import { getDischargeSettlementDetails, getDischargeInstructions } from './service';
import { reportApi } from '../../utils/cloudMonitorHelper';
Component({
  data: {
    dischargeSettlementDetails: {},
    // 出院详情内容
    dischargeInstructions: '',
    // 出院须知内容
    inpatientId: '',
    // 住院记录id
    settlementType: 'supportMedicalPreSettlement' // 页面类型
    // supportMedicalPreSettlement - 支持医保，预结算,有退款 / notSupportMedicalRefund - 不支持医保， 有退款 / notSupportMedicalSupplementary - 不支持医保，需补缴

  },

  didMount() {
    // 获取参数住院IDhospitalDistrictId
    const optionsValue = JSON.parse(JSON.stringify(this.$page.data.query));
    const {
      inpatientId,
      settlementType
    } = optionsValue;
    this.setData({
      inpatientId,
      settlementType: settlementType || 'supportMedicalPreSettlement'
    }, () => {
      // 获取出院详情
      this.getDischargeSettlementDetails();
    }); // 获取出院须知

    this.getDischargeInstructionsInfo();
    /* 服务办结，出院结算成功 */

    reportApi('出院结算成功');
  },

  methods: {
    /**
    * 获取出院详情
    */
    async getDischargeSettlementDetails() {
      const {
        inpatientId
      } = this.data; // 调用方法 - 获取出院详情接口

      const params = {
        inpatientId
      };
      const dischargeSettlementDetails = await getDischargeSettlementDetails(params);
      this.setData({
        dischargeSettlementDetails
      });
    },

    /**
     * 获取出院须知
     */
    async getDischargeInstructionsInfo() {
      // 调用方法 - 获取出院须知接口
      const res = await getDischargeInstructions();
      this.setData({
        dischargeInstructions: res.dischargeNotice || ''
      });
    },

    /**
     * 返回首页
     */
    onReturnHome() {
      const len = getCurrentPages().length;
      my.navigateBack({
        delta: len + 1
      }); // my.redirectTo({
      //   url: '/pages/inpatient-service-index/index'
      // });
    }

  }
});