import { getInpatientNotice, getHospitalizationInfo } from './service';
import history from '../../utils/history';
import { reportApi } from '../../utils/cloudMonitorHelper';
Component({
  data: {
    hospitalizationInfo: {},
    inpatientNotice: '',
    inpatientId: '',
    showOtherButton: false
  },

  didMount() {
    const {
      inpatientId,
      showOtherButton
    } = JSON.parse(JSON.stringify(this.$page.data.query));
    console.log(showOtherButton);
    this.setData({
      inpatientId,
      showOtherButton: showOtherButton === 'true'
    }, () => {
      // 获取住院详情信息
      this.getHospitalizationInfo();
    }); // 获取入院须知内容

    this.getInpatientNoticeInfo();
    /* 服务办结，入院登记成功 */

    reportApi('入院登记成功');
  },

  methods: {
    /**
    * 获取入院须知内容
    */
    async getInpatientNoticeInfo() {
      const inpatientNoticeResult = await getInpatientNotice();
      this.setData({
        inpatientNotice: inpatientNoticeResult.inpatientNotice || ''
      });
    },

    /**
    * 获取住院详情信息
    */
    async getHospitalizationInfo() {
      const {
        inpatientId
      } = this.data;
      const hospitalizationInfo = await getHospitalizationInfo({
        inpatientId
      });
      this.setData({
        hospitalizationInfo
      });
    },

    /**
    * 完成,跳转至入院登记页面
    */
    onFinish() {
      history.push({
        title: '入院登记',
        pageType: 'admission-record'
      });
    },

    /**
    * 缴纳金额
    */
    onPremiumReceived() {
      history.push({
        query: {
          inpatientId: this.data.inpatientId
        },
        title: '押金缴纳',
        pageType: 'deposit'
      });
    }

  }
});