<template>
  <div id="myInvoice">
    <my-invoice-list ref="invoiceList" @gotoDetail="gotoDetail"/>
    <!-- <high-search v-model="moreSearchShow" @onsearch="moreSearchConfirm" @onclean="moreSearchClean"/> -->
    <high-search :more-search-info="moreSearchInfo" v-model="moreSearchShow" @onsearch="moreSearchConfirm" @onclean="moreSearchClean"/>
  </div>
</template>

<script>
// import HighSearch from './components/HighSearch.vue'
import HighSearch from '@/views/myOrder/components/HighSearchNewDelete.vue'
import {getFormateDate} from '@/utils/common'
import myInvoiceList from './myInvoiceList.vue'
import invoiecDetail from './invoiecDetail.vue'
import { bridge } from "@/utils";
export default {
  name: 'MyInvoice',
  components: {
    HighSearch,
    myInvoiceList                          
  },
  data() {
    return {
      tabsTitle: [],
      moreSearchShow: false,
      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"),
        },
      },
      invoiceList: []
    }
  },
  computed: {
    linkInfo () {
      return this.$store.state.linkInfo
    },
    routKey() {
      return this.$route.path
    },
    searchTime() {
      let time = this.time.start + '/' + this.time.end
      return time
    }
  },
  activated() {
    // 设置标题栏关闭返回按钮
    this.$store.commit('setNavBar', {
      show: true,
      leftArrow: true,
      rightIcon: true,
      title: '发票',
      leftText: '',
      leftClick: this.closeAppPage,
      rightClick: this.onMoreSearch
    })
    // 给window添加一个popstate事件，拦截返回键，执行this.onBrowserBack事件，addEventListener需要指向一个方法
    window.addEventListener('popstate', this.onBrowserBack, false)
  },
  mounted() {
    // 设置标题栏关闭返回按钮
    // this.$store.commit('setNavBar', {
    //   show: true,
    //   leftArrow: true,
    //   rightIcon: true,
    //   title: '发票',
    //   leftText: '',
    //   leftClick: this.closeAppPage,
    //   rightClick: this.onMoreSearch
    // })
    // // 给window添加一个popstate事件，拦截返回键，执行this.onBrowserBack事件，addEventListener需要指向一个方法
    // window.addEventListener('popstate', this.onBrowserBack, false)
  },
  destroyed() {
    // 当页面销毁必须要移除这个事件，vue不刷新页面，不移除会重复执行这个事件
    window.removeEventListener('popstate', this.onBrowserBack, false)
  },
  methods: {
    // 跳转发票详情
    gotoDetail(model) {
      console.log(model)
      this.$router.push({
        path: '/invoiecDetail',
        query: model
       });
    },
    onBrowserBack() {
      if (this.moreSearchShow) {
        this.moreSearchShow = false
        return
      }
      this.$router.go(-1)
    },
    onSearch() {

    },
    onMoreSearch() {
      this.moreSearchShow = !this.moreSearchShow
      if (this.moreSearchShow) {
        window.history.pushState(null, null, document.URL)
      }
    },
    // 高级搜索查询
    moreSearchConfirm(data) {
      console.log(data)
      this.$refs.invoiceList[0].httpAction(this.moreSearchInfo)
    },
    // 高级搜索取消
    moreSearchClean(data) {
      this.moreSearchInfo = data;
      this.$refs.invoiceList[0].httpAction(this.moreSearchInfo)
    },
    closeAppPage() {
      console.log('关闭页面')
      bridge.closeWindow_c()
    }
  }
}
</script>

<style lang="scss" scoped>
  #myInvoice {
    height: 100%;
  }
</style>
