174 lines
3.3 KiB
JavaScript
174 lines
3.3 KiB
JavaScript
import request from '~/api/request';
|
|
|
|
Page({
|
|
data: {
|
|
personInfo: {
|
|
username: '',
|
|
sex: 0,
|
|
age: '',
|
|
id_number: '',
|
|
birthday: '',
|
|
operative_date: '',
|
|
|
|
|
|
birth: '',
|
|
address: [],
|
|
introduction: '',
|
|
yearType: 0
|
|
// photos: [],
|
|
},
|
|
genderOptions: [
|
|
{
|
|
label: '男',
|
|
value: 0,
|
|
},
|
|
{
|
|
label: '女',
|
|
value: 1,
|
|
}
|
|
|
|
],
|
|
yearOptions: [
|
|
{
|
|
label: '月',
|
|
value: 0,
|
|
},
|
|
{
|
|
label: '年',
|
|
value: 1,
|
|
}
|
|
|
|
],
|
|
birthVisible: false,
|
|
birthStart: '1970-01-01',
|
|
birthEnd: '2025-03-01',
|
|
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,
|
|
},
|
|
},
|
|
|
|
onLoad() {
|
|
// this.initAreaData();
|
|
|
|
},
|
|
|
|
|
|
|
|
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) {
|
|
const { mode } = e.currentTarget.dataset;
|
|
this.setData({
|
|
[`${mode}Visible`]: true,
|
|
});
|
|
|
|
},
|
|
|
|
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,
|
|
// });
|
|
},
|
|
|
|
onSaveInfo() {
|
|
// console.log(this.data.personInfo);
|
|
},
|
|
});
|