import { mapState } from 'vuex';
import uni from '@/utils/uniHooks';
import { orderInfo } from '@/api/parking';
import ordersInfoMockData from '@/api/mockData/ordersInfo.json';
import { ORDER_STATUS } from '@/common/js/BaseDictionary'
import moment from 'moment'
export default {
  data() {
    return {
      orderNo: '',
      isInvoiceName: '',
      detail: {},
    };
  },

  mounted() {
    setTimeout(() => {
      uni.setNavigationBarTitle({
        title: '缴费详情',
      });
    }, 300);
    setTimeout(() => {
      window?.toWXSendMsg({
        type: 'uni_func',
        funcName: 'setNavigationBarColor',
        options: {
          frontColor: '#000000',
          backgroundColor: '#FBFCFF',
        },
      });
    }, 500)
    this.orderNo = this.$route.query.orderNo;
    this.getData();
  },
  computed: {

    ...mapState({
      // custTypeId: (state) => state.custTypeId,
      // paramsScene: (state) => state.paramsScene,
      // mallid: (state) => state.mallId,
      // openId: (state) => state.openid,
      // member: (state) => state.member,
      groupId: (state) => state.groupId,
      // mobile: (state) => state.mobile,
      // projectId: (state) => state.projectId,
    }),
  },
  methods: {
    async getData() {
      const params = {
        orderno: this.orderNo,
      };
      /*uni.showLoading({
       title: '加载中',
       });*/
      try {
        const res = await orderInfo(this.orderNo);
        console.log(59595959, res);
        // this.detail = ordersInfoMockData;
        this.detail = res;
        const isInvoice = this.detail.isInvoice;
        if (isInvoice == 0) {
          this.isInvoiceName = '未开票';
        } else if (isInvoice == 1) {
          this.isInvoiceName = '已申请开票';
        } else if (isInvoice == 2) {
          this.isInvoiceName = '开票中';
        } else if (isInvoice == 3) {
          this.isInvoiceName = '开票完成';
        } else if (isInvoice == 4) {
          this.isInvoiceName = '开票失败';
        }
      } catch (err) {
        console.log(err);
      }
      return;
      this.$md(params);
      uni.request({
        url: this.$baseURL + 'api/1.0/park/parkOrderDetail',
        data: params,
        method: 'POST',
        header: JSON.parse(uni.getStorageSync('handleUser')),
        success: (res) => {
          uni.hideLoading();
          if (res.data.code == 0) {
            this.detail = res.data.data;
            // this.detail = mockDetailSuccess.data;
            const isInvoice = this.detail.isInvoice;
            if (isInvoice == 0) {
              this.isInvoiceName = '未开票';
            } else if (isInvoice == 1) {
              this.isInvoiceName = '已申请开票';
            } else if (isInvoice == 2) {
              this.isInvoiceName = '开票中';
            } else if (isInvoice == 3) {
              this.isInvoiceName = '开票完成';
            } else if (isInvoice == 4) {
              this.isInvoiceName = '开票失败';
            }
          } else {
            uni.showToast({
              title: res.data.msg,
              duration: 2000,
              icon: 'none',
            });
          }
        },
        fail: (err) => {
          uni.hideLoading();
          uni.showToast({
            title: res.data.msg,
            duration: 2000,
            icon: 'none',
          });
        },
      });
    },
  },
  filters: {
    orderStatus(val) {
      return ORDER_STATUS[val]
    },
    parkingTime(val) {
      const time = val;
      const days = parseInt(time / 60 / 24);
      const hours = parseInt((time / 60) % 24);
      const minutes = parseInt(time % 60);
      if (days > 0) {
        return `${days}天 ${hours}小时 ${minutes}分钟`;
      }
      if (hours > 0) {
        return `${hours}小时 ${minutes}分钟`;
      }
      return `${minutes}分钟`;
    },
    momentFormat(val) {
      if(!val)return val
      return moment(val).format('YYYY-MM-DD hh:mm:ss')
    }
  }
};
