import { patientUpdate } from '../patient-detail/service';
import getEncryptStr from '../../utils/getEncryptStr';
Component({
  props: {},
  data: {
    phone: ''
  },

  didMount() {},

  methods: {
    onInput(e) {
      this.setData({
        phone: e.detail.value
      });
    },

    async onSave() {
      const {
        query = {
          id: ''
        }
      } = this.$page.data;
      const phoneNumber = this.data.phone;

      if (/^[1]([3-9])[0-9]{9}$/.test(phoneNumber)) {
        patientUpdate({
          id: query.id,
          phoneNumber: await getEncryptStr(this.data.phone)
        }).then(() => {
          my.navigateBack();
        });
      } else {
        my.showToast({
          type: 'fail',
          content: '手机号错误',
          duration: 3000,
          success: () => {
            this.setData({
              phone: ''
            });
          }
        });
      }
    }

  }
});