import { getDoctorOrderSource } from '../../utils/service';
import { history } from '../../utils';
Component({
  props: {
    data: {
      timeRange: [],
      bookInfo: {},
      doctor: {}
    }
  },
  data: {
    date: undefined,
    sourceList: []
  },

  didMount() {
    my.setNavigationBar({
      title: '选择号源'
    });
  },

  methods: {
    getCurSelectTime(date) {
      this.getDoctorOrderSourceList(date.id);
    },

    toSelectCard(e) {
      const {
        source
      } = e.target.dataset;

      if (!source.remain) {
        my.showToast({
          content: '暂无号源',
          duration: 3000
        });
        return;
      }

      const bookInfo = { ...this.props.data.bookInfo,
        ...source
      };
      history.openPage({
        pageType: 'select-card',
        data: {
          bookInfo
        }
      });
    },

    // 医生号源
    async getDoctorOrderSourceList(date) {
      const {
        bookInfo
      } = this.props.data;
      this.setData({
        sourceList: [],
        noData: false
      });
      const [, res] = await getDoctorOrderSource({
        startTime: date,
        endTime: date,
        doctorId: bookInfo.doctorId,
        depId: bookInfo.depId
      });
      this.setData({
        sourceList: res,
        noData: !(res && res.length),
        showLoading: false
      });
    }

  }
});