import { getDoctorInfo } from './service';
import history from '../../utils/history';
import { reportCmPV_YL } from '../../utils/cloudMonitorHelper';
Component({
  props: {
    registerBtn: () => null,
    onclose: () => null
  },
  data: {
    doctorInfo: null,
    className: '',
    txt: '去挂号',
    isShowModal: false,
    // 挂号模态框
    position: 'bottom',
    // 模态框出现方向
    title: '请选择科室',
    departmentList: [{
      name: '呼吸123内科',
      id: '1'
    }, {
      name: '新生儿呼吸科',
      id: '2'
    }]
  },

  didMount() {
    const {
      doctorId = 3
    } = this.$page.data.query || {};
    getDoctorInfo({
      doctorId
    }).then(res => {
      const {
        name,
        picUrl,
        description,
        level,
        specialty,
        departments
      } = res;
      const doctorTemp = {
        avator: picUrl,
        name,
        duty: level,
        type: departments[0].name,
        sectionList: [{
          title: '擅长',
          desc: specialty
        }, {
          title: '医生简介',
          desc: description
        }],
        doctorId
      };
      this.setData({
        departmentList: departments,
        doctorInfo: doctorTemp,
        docId: doctorId
      });
    });
    /* 服务预警，专家介绍 */

    reportCmPV_YL({
      title: '专家介绍'
    });
  },

  methods: {
    /**
     * 去挂号
     */
    registerBtn() {
      /* 多个科室 */
      if (this.data.departmentList && this.data.departmentList.length > 1) {
        this.setData({
          isShowModal: true,
          // 挂号模态框
          position: 'bottom' // 模态框出现方向

        });
      } else {
        /* 只有一个科室 直接跳转 */
        history.push({
          query: {
            depId: this.data.departmentList[0].departmentId,
            // 科室id
            doctorId: this.data.docId // 医生唯一识别号

          },
          title: '医生主页',
          pageType: 'doctor-page'
        });
      }
    },

    /**
     * 关闭模态框
     */
    onClose() {
      this.setData({
        isShowModal: false
      });
    }

  }
});