import { getReportDetail } from './service';
import history from '../../utils/history';
import { reportApi } from '../../utils/cloudMonitorHelper';
Component({
  props: {},
  data: {
    details: null,
    reportDetailsInfo: {},
    recordId: ''
  },

  onInit() {},

  didMount() {
    console.log('didMount');
    const {
      recordId = 1
    } = this.$page.data.query || {};
    getReportDetail({
      recordId
    }).then(res => {
      const {
        cardNum,
        userName,
        userSex,
        userAge,
        sampleType,
        applyDate,
        departmentName,
        ...rest
      } = res;
      const essentialInformationList = [{
        title: '就诊人',
        value: `${userName}，${userSex}，${userAge}岁`
      }, {
        title: '就诊卡号',
        value: cardNum
      }, {
        title: '标本种类',
        value: sampleType
      }, {
        title: '就诊科室',
        value: departmentName
      }, {
        title: '采样时间',
        value: applyDate
      }];
      this.setData({
        details: res,
        reportDetailsInfo: { ...rest,
          essentialInformationList
        }
      });
    });
    /* 服务办结，报告查询 */

    reportApi('报告查询');
  },

  methods: {
    /**
     * 图片放大
     */
    previewImage(e) {
      const {
        currentTarget: {
          dataset: {
            item
          }
        }
      } = e;
      my.previewImage({
        current: 0,
        urls: [item]
      });
    },

    /**
     * 纸质打印报告
     */
    paperPrintingBtn() {
      history.toH5(this.data.reportDetailsInfo.navigationUrl);
    },

    /**
     * 复诊挂号
     */
    registrationBtn() {
      const {
        details
      } = this.data;
      const {
        districtId,
        departmentId,
        districtName,
        departmentName
      } = details;
      history.push({
        query: {
          departmentId
        },
        pageType: 'hospital-num-source',
        title: `${departmentName}（${districtName}）`,
        componentData: {
          /* 区域 */
          area: {
            name: districtName,
            hospitalDistrictId: districtId
          },

          /* 科室 */
          department: {
            departmentId,
            name: departmentName
          }
        }
      });
    }

  }
});