<template>
  <div id="orderInvoiecDetail">
    <div class="content">
      <order-invoiec-head :invoiceItem="invoiceItem"/>
    </div>
    <div class="list">
      <order-invoiec-detail-list :invoiceItem="invoiceItem"/>
    </div>
    <!-- <high-search v-model="moreSearchShow" @onsearch="moreSearchConfirm" @onclean="moreSearchClean"/> -->
  </div>
</template>

<script>
import {getFormateDate} from '@/utils/common'
import { getOrderInvoiceList } from '@/api/myOrder'
import orderInvoiecHead from './invoiecDetail/orderInvoiecHead.vue'
import orderInvoiecDetailList from './invoiecDetail/orderInvoiecDetailList.vue'
export default {
  name: 'OrderInvoiecDetail',
  components: {
    orderInvoiecHead,
    orderInvoiecDetailList              
  },
  data() {
    return {
      tabsTitle: [],
      moreSearchShow: false,
      currentPage: 1,
      pageSize: 10,
      activeTab: 'home',
      moreSearchInfo: {
        //接收搜索更多回传的数据
        supplier: { comPartyId: "" }, //供应商ID
        goods: { comGoodsId: "" }, //商品ID
        orderNo: "", //订单编号
        time: {
          //起始时间
          start: getFormateDate(new Date(), "yyyy-MM-dd"),
          end: getFormateDate(new Date(), "yyyy-MM-dd"),
        },
      },
      invoiceItem: {}
    }
  },
  computed: {
    linkInfo () {
      return this.$store.state.linkInfo
    },
    routKey() {
      return this.$route.path
    },
    searchTime() {
      let time = this.time.start + '/' + this.time.end
      return time
    }
  },
  mounted() {
    // 设置标题栏关闭返回按钮
    this.$store.commit('setNavBar', {
      show: true,
      leftArrow: true,
      rightIcon: false,
      title: '',
      leftText: '发票明细',
      leftClick: this.onBrowserBack,
      rightClick: this.onMoreSearch
    })
    // 给window添加一个popstate事件，拦截返回键，执行this.onBrowserBack事件，addEventListener需要指向一个方法
    window.addEventListener('popstate', this.onBrowserBack, false)
    this.getPostData()
  },
  destroyed() {
    // 当页面销毁必须要移除这个事件，vue不刷新页面，不移除会重复执行这个事件
    window.removeEventListener('popstate', this.onBrowserBack, false)
  },
  methods: {
    onBrowserBack() {
      this.$router.go(-1)
    },
    onSearch() {

    },
    onMoreSearch() {
      this.moreSearchShow = !this.moreSearchShow
      if (this.moreSearchShow) {
        window.history.pushState(null, null, document.URL)
      }
    },
    // 高级搜索查询
    moreSearchConfirm(data) {
      console.log('000000000')
    },
    // 高级搜索取消
    moreSearchClean(data) {
      this.moreSearchInfo = data;
    },
    closeAppPage() {
      console.log('关闭页面')
      bridge.closeWindow_c()
    },
    getPostData() {
      let _this = this
      let data = {
        'clientID': [
        ],
        'endDate': '',
        'goodsCode': '',
        'goodsDesc': '',
        'goodsId': '',
        'goodsName': '',
        'goodsSpec': '',
        'invoiceCode': '',
        'invoiceDate': '',
        'invoiceFullNo': '',
        'invoiceNo': this.$route.query.invoiceNo,
        'isTwoTicket': '',
        'manufacturer': '',
        'mdmClientCode': '',
        'mdmGoodsCode': '',
        'order': '',
        'orderId': '',
        'orderNo': this.$route.query.orderNo,
        'pageNum': this.currentPage,
        'pageSize': this.pageSize,
        'sort': '',
        'sourceDb': this.$route.query.sourceDb,
        'startDate': '',
        'supplierId': [
        ]
      }
      getOrderInvoiceList(data).then(rt => {
        if (rt.data.code === '00000') {
          if (rt.data.entity && rt.data.entity.invoiceList.length > 0) {
            _this.invoiceItem = rt.data.entity.invoiceList[0]
          }
        } else {
          _this.$toast(rt.message)
        }
        // 加载状态结束
        _this.isLoading = false
      }).catch(e => {
        this.$toast('获取信息失败！')
        _this.isRefreshing = false
        _this.isLoading = false
        _this.error = true
        _this.finished = true
      })
    }
  }
}
</script>

<style lang="scss" scoped>
  #orderInvoiecDetail {
    height: 100%;
    width: 100%;
    .list{
      height: calc(100vh - 245PX);
      margin-top: -40PX;
    }
  }
</style>
