|
@@ -7,7 +7,9 @@ Page({
|
|
form: { icon: [] },
|
|
form: { icon: [] },
|
|
// 性别
|
|
// 性别
|
|
genderList: gender,
|
|
genderList: gender,
|
|
- id: ''
|
|
|
|
|
|
+ id: '',
|
|
|
|
+ //用户id
|
|
|
|
+ user_id: ''
|
|
},
|
|
},
|
|
initValidate() {
|
|
initValidate() {
|
|
const rules = { icon: { required: true }, name: { required: true }, card: { required: true, idcard: true }, age: { required: true }, gender: { required: true }, phone: { required: true, tel: true } }
|
|
const rules = { icon: { required: true }, name: { required: true }, card: { required: true, idcard: true }, age: { required: true }, gender: { required: true }, phone: { required: true, tel: true } }
|
|
@@ -38,7 +40,7 @@ Page({
|
|
const that = this;
|
|
const that = this;
|
|
let card = e.detail.value;
|
|
let card = e.detail.value;
|
|
if (!/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(card)) {
|
|
if (!/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(card)) {
|
|
- wx.showToast({ title: `请输入18位的有效身份证`, icon: 'error', duration: 2000 })
|
|
|
|
|
|
+ wx.showToast({ title: `请输入有效身份证号码`, icon: 'none', duration: 2000 })
|
|
} else {
|
|
} else {
|
|
//获取出生日期
|
|
//获取出生日期
|
|
let birth = card.substring(6, 10) + "-" + card.substring(10, 12) + "-" + card.substring(12, 14);
|
|
let birth = card.substring(6, 10) + "-" + card.substring(10, 12) + "-" + card.substring(12, 14);
|
|
@@ -51,7 +53,7 @@ Page({
|
|
var day = myDate.getDate();
|
|
var day = myDate.getDate();
|
|
var age = myDate.getFullYear() - card.substring(6, 10) - 1;
|
|
var age = myDate.getFullYear() - card.substring(6, 10) - 1;
|
|
if (card.substring(10, 12) < month || card.substring(10, 12) == month && card.substring(12, 14) <= day) age++;
|
|
if (card.substring(10, 12) < month || card.substring(10, 12) == month && card.substring(12, 14) <= day) age++;
|
|
- that.setData({ 'form.age': age });
|
|
|
|
|
|
+ that.setData({ 'form.age': parseFloat(age) });
|
|
}
|
|
}
|
|
},
|
|
},
|
|
// 选择性别
|
|
// 选择性别
|
|
@@ -66,16 +68,17 @@ Page({
|
|
const form = that.data.form;
|
|
const form = that.data.form;
|
|
const params = e.detail.value;
|
|
const params = e.detail.value;
|
|
params.icon = form.icon;
|
|
params.icon = form.icon;
|
|
|
|
+ params.user_id = that.data.user_id;
|
|
if (!this.WxValidate.checkForm(params)) {
|
|
if (!this.WxValidate.checkForm(params)) {
|
|
const error = this.WxValidate.errorList[0];
|
|
const error = this.WxValidate.errorList[0];
|
|
wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
|
|
wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
|
|
return false
|
|
return false
|
|
} else {
|
|
} else {
|
|
- console.log(params);
|
|
|
|
- // if (form._id) arr = await app.$post(`/newCourt/api/student/${form._id}`, params);
|
|
|
|
- // else arr = await app.$post(`/newCourt/api/student`, params);
|
|
|
|
- // if (arr.errcode == '0') { wx.showToast({ title: `维护信息完成`, icon: 'success', duration: 2000 }); that.back(); }
|
|
|
|
- // else wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
|
|
|
|
|
|
+ let arr;
|
|
|
|
+ if (form._id) arr = await app.$post(`/student/${form._id}`, params);
|
|
|
|
+ else arr = await app.$post(`/student`, params)
|
|
|
|
+ if (arr.errcode == '0') { wx.showToast({ title: `维护信息完成`, icon: 'success', duration: 2000 }); that.back(); }
|
|
|
|
+ else wx.showToast({ title: `${errmsg}`, icon: 'error', duration: 2000 })
|
|
}
|
|
}
|
|
},
|
|
},
|
|
/**
|
|
/**
|
|
@@ -95,13 +98,12 @@ Page({
|
|
wx.getStorage({
|
|
wx.getStorage({
|
|
key: 'user',
|
|
key: 'user',
|
|
success: async res => {
|
|
success: async res => {
|
|
|
|
+ that.setData({ user_id: res.data._id });
|
|
if (that.data.id) {
|
|
if (that.data.id) {
|
|
- const form = { _id: '1', icon: [{ url: '/image/beijing.jpeg' }], name: "测试姓名", card: '220581200003302462', phone: '12345678901', age: '18', gender: '0' };
|
|
|
|
- that.setData({ form: form });
|
|
|
|
- // const arr = await app.$get(`/newCourt/api/student/${that.data.id}`);
|
|
|
|
- // if (arr.errcode == '0') {
|
|
|
|
- // that.setData({ form: arr.data });
|
|
|
|
- // }
|
|
|
|
|
|
+ const arr = await app.$get(`/student/${that.data.id}`);
|
|
|
|
+ if (arr.errcode == '0') {
|
|
|
|
+ that.setData({ form: arr.data });
|
|
|
|
+ }
|
|
}
|
|
}
|
|
},
|
|
},
|
|
fail: async res => {
|
|
fail: async res => {
|