// const app = getApp()
const app = {};
import downloadBtnIcon from '../../static/images/download.png';
import arrowIcon from '../../static/images/arrows.png';
import { mapState } from 'vuex';
import uni from '@/utils/uniHooks';
import { invoicesDeatil, invoicesOrders } from '@/api/parking';
export default {
  data() {
    return {
      picUrl: this.$picUrl,
      arrowIcon: arrowIcon,
      downloadBtnIcon: downloadBtnIcon,
      order: {
        id: 0 ,
        invoiceOrderNo: "",
        pdfUrl: "",
        invoiceType: "",
        invoiceNumber: "",
        invoiceCode: "",
        invoiceTotalAmount: 0,
        email: "",
        remark: "",
        invoiceTitleId: 0,
        invoiceTime: "",
        invoiceTitle: {
            id: 0,
            titleName: "",
            companyAddress: ""
        },
        invoiceItem: [
        ]
    },
      webviewStyles: {
        progress: {
          color: '#FF3333',
        },
      },
      id: '',
    };
  },
  created() {
    console.log('查看发票详情的id', this.$route.query);
    this.id = this.$route.query.id;
    this.getInvoicesOrders(this.id)
  },
  mounted() {
    setTimeout(() => {
      uni.setNavigationBarTitle({
        title: '发票详情',
      });
    }, 300);
    setTimeout(() => {
      window?.toWXSendMsg({
        type: 'uni_func',
        funcName: 'setNavigationBarColor',
        options: {
          frontColor: '#000000',
          backgroundColor: '#FBFCFF',
        },
      });
    }, 500)
      // const res = await invoicesDeatil(id)
    this.getInvoicedDetail(this.id);
  },
  computed: {
    ...mapState({
      custTypeId: (state) => state.custTypeId,
    }),
  },
  methods: {
    getInvoicesOrders: async function (id) {
      try {
        const res = await invoicesOrders(id)
        this.invoiceAmount = res.invoiceTotalAmount
        this.orderQuantity = res.invoicedOrders.length
        this.parkingOrder = res.invoicedOrders
        console.log('1.28 查看发票关联的订单支付详情：：：：', res)
      } catch {
        uni.showToast({
          title: '服务器开小差了呢，请您稍后再试',
          icon: 'none',
        });
      }
    },
    // 根据发票id获取发票详情信息(含发票抬头信息),
    getInvoicedDetail: async function (id) {
      //
      // console.log('根据发票id获取发票详情信息(含发票抬头信息),', id);
      const self = this;
      // self.$md(data);
      try {
        const res = await invoicesDeatil(id)
        console.log('支付订单详情', res)
          self.order = res;
      } catch {
        uni.showToast({
          title: '服务器开小差了呢，请您稍后再试',
          icon: 'none',
        });
      }
      // uni.request({
      //   url: self.$baseURL + 'api/1.0/invoice/getInvoicedDetail?id=' + id,
      //   method: 'POST',
      //   data: data,
      //   header: JSON.parse(uni.getStorageSync('handleUser')),
      //   success: (res) => {
      //     console.log('获取发票详情信息', res.data);
      //     if (res.data.code === 0) {
      //       self.order = res.data.data;
      //     } else {
      //       uni.showToast({
      //         title: res.data.msg,
      //         duration: 2000,
      //         icon: 'none',
      //       });
      //     }
      //   },
      //   fail: () => {
      //     uni.showToast({
      //       title: '服务器开小差了呢，请您稍后再试',
      //       icon: 'none',
      //     });
      //   },
      // });
    },
    showHeader() {
      this.$router.push({
        path: 'parkingHeaderDetail?header=' + JSON.stringify(this.order),
      });
    },
    gotoRecordDetail() {
      this.$router.push({
        path: 'parkingOrderDetail',
        query: {
          id: this.order.id,
        }
      });
    },
    showInvoiceDetail() {
      this.$router.push({
        path: 'parkingInvoiceImage?order=' + JSON.stringify(this.order),
      });
    },
  },
};
