|
@@ -1,20 +1,126 @@
|
|
|
const app = getApp()
|
|
|
+import WxValidate from '../../utils/wxValidate'
|
|
|
+const moment = require("../../utils/moment.min");
|
|
|
Page({
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 页面的初始数据
|
|
|
+ */
|
|
|
data: {
|
|
|
- info: {}
|
|
|
+ form: {},
|
|
|
+ // 性别
|
|
|
+ genderList: [],
|
|
|
+ // 类别
|
|
|
+ typeList: [],
|
|
|
+ },
|
|
|
+ initValidate() {
|
|
|
+ const rules = { name: { required: true } }
|
|
|
+ const messages = { name: { required: '请输入姓名' } };
|
|
|
+ this.WxValidate = new WxValidate(rules, messages)
|
|
|
},
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
- onLoad(options) {
|
|
|
+ async onLoad(options) {
|
|
|
const that = this;
|
|
|
wx.showLoading({ title: '加载中', mask: true })
|
|
|
- that.search()
|
|
|
+ //验证规则函数
|
|
|
+ that.initValidate();
|
|
|
+ await that.searchOther()
|
|
|
+ await that.search()
|
|
|
wx.hideLoading()
|
|
|
},
|
|
|
- // 查询通知
|
|
|
- async search() {
|
|
|
+ search() {
|
|
|
+ const that = this;
|
|
|
+ wx.getStorage({
|
|
|
+ key: 'token',
|
|
|
+ async success(res) {
|
|
|
+ let form = {}
|
|
|
+ let aee = await app.$api(`user/${res.data._id}`, 'GET', {})
|
|
|
+ if (aee.errcode == '0') {
|
|
|
+ form = aee.data;
|
|
|
+ if (form && form._id) {
|
|
|
+ // 性别
|
|
|
+ if (form.gender) form.gender_name = that.getDict(form.gender, 'gender')
|
|
|
+ // 工作状态
|
|
|
+ if (form.type) form.type_name = that.getDict(form.type, 'type')
|
|
|
+ } else {
|
|
|
+ form.status = '0';
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ wx.showToast({ title: `${aee.errmsg}`, icon: 'error' });
|
|
|
+ }
|
|
|
+ that.setData({ form })
|
|
|
+ },
|
|
|
+ fail(err) {
|
|
|
+ console.log(err);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 过滤字典表
|
|
|
+ getDict(value, model) {
|
|
|
+ const that = this;
|
|
|
+ if (value) {
|
|
|
+ let list = that.data[model + 'List']
|
|
|
+ let data = list.find(i => i.value == value);
|
|
|
+ if (data) return data.label
|
|
|
+ else return '暂无'
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 选择性别
|
|
|
+ genderChange(e) {
|
|
|
+ const that = this;
|
|
|
+ const index = e.detail.value;
|
|
|
+ let data = that.data.genderList[index];
|
|
|
+ if (data) {
|
|
|
+ that.setData({ 'form.gender': data.value })
|
|
|
+ that.setData({ 'form.gender_name': data.label })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 选择类别
|
|
|
+ typeChange(e) {
|
|
|
+ const that = this;
|
|
|
+ // 所取数据
|
|
|
+ const index = e.detail.value;
|
|
|
+ // 选择项
|
|
|
+ let data = that.data.typeList[index];
|
|
|
+ if (data) {
|
|
|
+ that.setData({ 'form.type': data.value })
|
|
|
+ that.setData({ 'form.type_name': data.label })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 提交保存
|
|
|
+ async toSave(e) {
|
|
|
+ const that = this;
|
|
|
+ const parmas = e.detail.value;
|
|
|
+ if (!this.WxValidate.checkForm(parmas)) {
|
|
|
+ const error = that.WxValidate.errorList[0];
|
|
|
+ wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
|
|
|
+ return false
|
|
|
+ } else {
|
|
|
+ // 判断id使用
|
|
|
+ let form = that.data.form;
|
|
|
+ let res;
|
|
|
+ if (form._id) res = await app.$api(`user/${form._id}`, 'POST', parmas);
|
|
|
+ else res = await app.$api('user', 'POST', parmas);
|
|
|
+ if (res.errcode == '0') {
|
|
|
+ wx.showToast({ title: `信息提交成功`, icon: 'success' });
|
|
|
+ that.search()
|
|
|
+ } else {
|
|
|
+ wx.showToast({ title: `${res.errmsg}`, icon: 'none' });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 查询其他信息
|
|
|
+ async searchOther() {
|
|
|
const that = this;
|
|
|
+ let res;
|
|
|
+ // 性别
|
|
|
+ res = await app.$api('dictData', 'GET', { type: 'gender', is_use: '0' })
|
|
|
+ if (res.errcode == '0') that.setData({ genderList: res.data })
|
|
|
+ // 类别
|
|
|
+ res = await app.$api('dictData', 'GET', { type: 'type', is_use: '0' })
|
|
|
+ if (res.errcode == '0') that.setData({ typeList: res.data })
|
|
|
},
|
|
|
|
|
|
/**
|