import { payHistory } from '../utils/service';
import { reportCmPV_YL } from '../utils/cloudMonitorHelper';
import { history, mapToArray } from '../utils';
Component({
  props: {
    componentData: {}
  },

  didMount() {
    const {
      status,
      serviceCode
    } = this.$page.options;
    const query = {
      serviceCode,
      status
    };

    if (status === '0') {
      my.setNavigationBar({
        title: '诊间缴费'
      });
      reportCmPV_YL({
        title: '诊间缴费',
        query
      });
    } else if (status === '1,9') {
      my.setNavigationBar({
        title: '缴费查询'
      });
      reportCmPV_YL({
        title: '缴费查询',
        query
      });
    } else {
      reportCmPV_YL({
        title: '未知查询',
        query
      });
    }

    my.hideShareMenu(); // 隐藏分享按钮
  },

  methods: {
    async payHistory(params) {
      const {
        status
      } = this.$page.options;
      const [err, result] = await payHistory({ ...params,
        type: 3,
        status
      });

      if (result && result.list) {
        result.list.forEach(item => {
          item.customInfo = mapToArray(item.customInfo);
        });
      }

      return [err, { ...result
      }];
    },

    onItemClick(value) {
      const outTradeNo = value.target.dataset.detail.outTradeNo || '';
      history.openPage({
        pageType: 'payment-details',
        data: {
          outTradeNo
        }
      });
    }

  }
});