import { payDetail } from '../../utils/service';
import { history, mapToArray } from '../../utils/index';
Component({
  props: {
    data: {}
  },
  data: {
    orderDetail: {},
    sourceType: null // 0医保 1自费

  },

  didMount() {
    my.setNavigationBar({
      title: '诊间缴费'
    });
    this.getDetail();
  },

  methods: {
    async getDetail() {
      const {
        outTradeNo
      } = this.props.data;
      const appIdRes = my.getAppIdSync();
      const [, res] = await payDetail({
        appId: appIdRes.appId,
        type: '3',
        outTradeNo
      });

      if (res) {
        res.customInfo = mapToArray(res.customInfo);
        this.setData({
          orderDetail: res
        });
      }
    },

    // 支付订单详情
    async toPay(e) {
      const sourceType = e.target.dataset.type;
      const {
        orderDetail
      } = this.data;
      history.openPage({
        pageType: 'settlement-details',
        data: {
          sourceType,
          orderDetail
        }
      });
    }

  }
});