Component({
  props: {
    /*
    * 数据结构为 [{ value: 'normal', label:'普通号' }]
    * */
    options: [],

    /* 挂号类型 */
    type: '',
    status: '',

    /* 时间 */
    otherOption: '',
    medicCards: [],
    onChange: () => {},
    statusList: [],
    defaultName: '',
    defaultLabel: ''
  },
  data: {},

  didMount() {},

  methods: {
    onShowMask() {
      this.setData({
        showOptions: true
      });
    },

    onShowStatusMask() {
      this.setData({
        showStatus: true
      });
    },

    onCloseMask() {
      this.setData({
        showOptions: false
      });
    },

    onCloseStatusMask() {
      this.setData({
        showStatus: false
      });
    },

    onTypeChange(value) {
      this.props.onChange({
        type: value
      });
    },

    onStatusChange(value) {
      this.props.onChange({
        status: value
      });
    },

    onShowTime() {
      this.setData({
        showTime: true
      }, () => {
        console.log(my.createSelectorQuery().select('.range-item'));
      });
    },

    onResetTime() {
      this.props.onChange({
        startTime: '',
        endTime: ''
      });
      this.setData({
        showTime: false
      });
    },

    onCancelTime() {
      this.setData({
        showTime: false
      });
    },

    onConfirmTime(date) {
      const [start = '', end = ''] = this.judgeDate(date);
      this.props.onChange({
        startTime: start,
        endTime: end
      });
      this.setData({
        showTime: false
      });
    },

    judgeDate(date) {
      const [start = '', end = ''] = date;
      const toDateStart = start ? new Date(start) : '';
      const toDateEnd = end ? new Date(end) : '';

      if (toDateStart && toDateEnd) {
        if (toDateStart > toDateEnd) {
          return [end, start];
        }

        return [start, end];
      }

      return ['', ''];
    },

    onCardTap() {
      this.setData({
        showCard: true
      });
    },

    onClosePopup() {
      this.setData({
        showCard: false
      });
    },

    onCardChange(item) {
      this.setData({
        showCard: false
      });
      this.props.onChange({
        cardNum: item.cardNum
      });
    }

  }
});