import request from '~/api/request'; Page({ data: { personInfo: { username: '', sex: 0, id_number: '', birthday: '', operative_date: '', }, genderOptions: [ { label: '男', value: 0, }, { label: '女', value: 1, } ], yearOptions: [ { label: '月', value: 0, }, { label: '年', value: 1, } ], birthVisible: false, birthStart: '1970-01-01', birthEnd: new Date().toISOString().split('T')[0], birthTime: 0, birthFilter: (type, options) => (type === 'year' ? options.sort((a, b) => b.value - a.value) : options), addressText: '', addressVisible: false, provinces: [], cities: [], gridConfig: { column: 3, width: 160, height: 160, }, defaultTime: '', newTime: '', }, onLoad() { // this.initAreaData(); this.getPersonalInfo() }, async getPersonalInfo() { const info = await request('patient/basic/0') this.setData({ personInfo: { username: info.username, sex: info.sex, id_number: info.id_number, birthday: info.birthday, operative_date: info.operative_date, } }) }, getAreaOptions(data, filter) { const res = Object.keys(data).map((key) => ({ value: key, label: data[key] })); return typeof filter === 'function' ? res.filter(filter) : res; }, getCities(provinceValue) { return this.getAreaOptions( areaList.cities, (city) => `${city.value}`.slice(0, 2) === `${provinceValue}`.slice(0, 2), ); }, initAreaData() { const provinces = this.getAreaOptions(areaList.provinces); const cities = this.getCities(provinces[0].value); this.setData({ provinces, cities }); }, onAreaPick(e) { const { column, index } = e.detail; const { provinces } = this.data; // 更改省份则更新城市列表 if (column === 0) { const cities = this.getCities(provinces[index].value); this.setData({ cities }); } }, showPicker(e) { console.log(e) const { mode } = e.currentTarget.dataset; this.setData({ birthVisible: true, defaultTime: e.detail.value, newTime: e.detail.value, }); }, hidePicker(e) { const { mode } = e.currentTarget.dataset; this.setData({ [`${mode}Visible`]: false, }); }, onPickerChange(e) { const { value, label } = e.detail; const { mode } = e.currentTarget.dataset; this.setData({ [`personInfo.${mode}`]: value, }); if (mode === 'address') { this.setData({ addressText: label.join(' '), }); } }, personInfoFieldChange(field, e) { const { value } = e.detail; this.setData({ [`personInfo.${field}`]: value, }); }, onNameChange(e) { this.personInfoFieldChange('name', e); }, onGenderChange(e) { this.personInfoFieldChange('gender', e); }, onYearChange(e) { this.personInfoFieldChange('yearType', e); }, onIntroductionChange(e) { this.personInfoFieldChange('introduction', e); }, onPhotosRemove(e) { const { index } = e.detail; // const { photos } = this.data.personInfo; // photos.splice(index, 1); // this.setData({ // 'personInfo.photos': photos, // }); }, onPhotosSuccess(e) { const { files } = e.detail; // this.setData({ // 'personInfo.photos': files, // }); }, onPhotosDrop(e) { const { files } = e.detail; // this.setData({ // 'personInfo.photos': files, // }); }, async onSaveInfo() { // console.log(this.data.personInfo); const res = await request('patient/set_personal_information', 'get', { data: this.data.personInfo }) wx.navigateBack() }, });