import { querySingle, patientUpdate } from '../patient-detail/service';
import history from '../../utils/history';
Component({
  props: {},
  data: {
    patient: {
      balance: 0,
      id: '',
      name: '',
      age: '',
      sex: '',
      phoneNumber: '',
      birthDay: '',
      idCardNo: '',
      relationShip: '',
      bindCardNum: '',
      medicCards: []
    }
  },

  didMount() {
    this.querySingle();
  },

  methods: {
    querySingle() {
      const {
        query = {
          id: ''
        }
      } = this.$page.data;
      my.showLoading();
      querySingle({
        id: query.id
      }).then(data => {
        this.setData({
          patient: data
        });
        my.hideLoading();
      });
    },

    // 修改关系
    onChange(e) {
      this.setData({
        'patient.relationShip': e.name
      });
    },

    onChangePhone() {
      history.push({
        query: {
          id: this.data.patient.id
        },
        title: '修改手机号',
        pageType: 'patient-detail-phone'
      });
    },

    onSubmit() {
      patientUpdate({
        id: this.data.patient.id,
        name: this.data.patient.name,
        relationShip: this.data.patient.relationShip
      }).then(my.navigateBack);
    }

  }
});