import history from '../../../utils/history';
Component({
  props: {
    show: true,
    defaultList: [],
    balance: false,
    onChange: () => null,
    onClose: () => null,
    personIndex: undefined
  },
  data: {
    activeIndex: undefined
  },

  deriveDataFromProps({
    personIndex
  }) {
    if (personIndex !== undefined) {
      this.setData({
        activeIndex: personIndex
      });
    }
  },

  methods: {
    onClosePopup() {
      this.props.onClose();
    },

    onConfirm(e) {
      const {
        item,
        index
      } = e.target.dataset;
      this.setData({
        activeIndex: index
      });
      this.props.onChange(item, index);
      this.onClosePopup();
    },

    handleToAdd() {
      history.push({
        title: '添加就诊人',
        pageType: 'edit-patient'
      });
    }

  }
});