|
@@ -3,14 +3,12 @@ import WxValidate from '../../utils/wxValidate';
|
|
|
Page({
|
|
|
data: {
|
|
|
frameStyle: { useTop: true, name: '学员信息管理', leftArrow: true, useBar: false },
|
|
|
+ id: '',
|
|
|
form: { icon: [] },
|
|
|
// 性别
|
|
|
genderList: [],
|
|
|
//运动等级
|
|
|
levelList: [],
|
|
|
- id: '',
|
|
|
- //用户id
|
|
|
- user_id: ''
|
|
|
},
|
|
|
initValidate() {
|
|
|
const rules = { icon: { required: true }, name: { required: true }, age: { required: true }, gender: { required: true }, phone: { required: true, tel: true } }
|
|
@@ -40,13 +38,20 @@ Page({
|
|
|
genderChange: function (e) {
|
|
|
const that = this;
|
|
|
let data = that.data.genderList[e.detail.value];
|
|
|
- if (data) that.setData({ 'form.gender': data.value });
|
|
|
+ if (data) {
|
|
|
+ that.setData({ 'form.gender': data.value });
|
|
|
+ that.setData({ 'form.zhGender': data.label });
|
|
|
+ }
|
|
|
},
|
|
|
// 选择等级
|
|
|
levelChange: function (e) {
|
|
|
const that = this;
|
|
|
let data = that.data.levelList[e.detail.value];
|
|
|
- if (data) that.setData({ 'form.level': data.value });
|
|
|
+ if (data) {
|
|
|
+ that.setData({ 'form.level': data.value });
|
|
|
+ that.setData({ 'form.zhLevel': data.label });
|
|
|
+
|
|
|
+ }
|
|
|
},
|
|
|
//提交
|
|
|
onSubmit: async function (e) {
|
|
@@ -54,7 +59,6 @@ Page({
|
|
|
const form = that.data.form;
|
|
|
const params = e.detail.value;
|
|
|
params.icon = form.icon;
|
|
|
- params.user_id = that.data.user_id;
|
|
|
if (!this.WxValidate.checkForm(params)) {
|
|
|
const error = this.WxValidate.errorList[0];
|
|
|
wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
|
|
@@ -70,28 +74,47 @@ Page({
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
- onLoad: function (options) {
|
|
|
+ onLoad: async function (options) {
|
|
|
const that = this;
|
|
|
that.setData({ id: options.id || '' })
|
|
|
//验证规则函数
|
|
|
that.initValidate();
|
|
|
+ // 查询其他信息
|
|
|
+ await that.searchOther();
|
|
|
// 监听用户是否登录
|
|
|
- that.watchLogin();
|
|
|
+ await that.watchLogin();
|
|
|
+ },
|
|
|
+ searchOther: async function () {
|
|
|
+ const that = this;
|
|
|
+ let arr;
|
|
|
+ // 性别
|
|
|
+ arr = await app.$get(`/dict`, { code: 'gender' });
|
|
|
+ if (arr.errcode == '0' && arr.total > 0) {
|
|
|
+ let list = arr.data[0].list;
|
|
|
+ that.setData({ genderList: list })
|
|
|
+ }
|
|
|
+ // 运动等级
|
|
|
+ arr = await app.$get(`/dict`, { code: 'student_grade' });
|
|
|
+ if (arr.errcode == '0' && arr.total > 0) {
|
|
|
+ let list = arr.data[0].list;
|
|
|
+ that.setData({ levelList: list })
|
|
|
+ }
|
|
|
},
|
|
|
// 监听用户是否登录
|
|
|
watchLogin: async function () {
|
|
|
const that = this;
|
|
|
+ let genderList = that.data.genderList;
|
|
|
+ let levelList = that.data.levelList;
|
|
|
wx.getStorage({
|
|
|
key: 'user',
|
|
|
success: async res => {
|
|
|
- that.setData({ user_id: res.data._id });
|
|
|
- let gender = await app.$get(`/dict`, { code: "gender" });
|
|
|
- if (gender.errcode == '0') that.setData({ genderList: gender.data[0].list });
|
|
|
- let student = await app.$get(`/dict`, { code: "student_grade" });
|
|
|
- if (student.errcode == '0') that.setData({ levelList: student.data[0].list });
|
|
|
if (that.data.id) {
|
|
|
const arr = await app.$get(`/student/${that.data.id}`);
|
|
|
if (arr.errcode == '0') {
|
|
|
+ let gender = genderList.find(i => i.value == arr.data.gender)
|
|
|
+ if (gender) arr.data.zhGender = gender.label;
|
|
|
+ let level = levelList.find(i => i.value == arr.data.level)
|
|
|
+ if (level) arr.data.zhLevel = level.label;
|
|
|
that.setData({ form: arr.data });
|
|
|
}
|
|
|
}
|