|
@@ -0,0 +1,178 @@
|
|
|
+const app = getApp()
|
|
|
+import WxValidate from '../../utils/wxValidate'
|
|
|
+Page({
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 页面的初始数据
|
|
|
+ */
|
|
|
+ data: {
|
|
|
+ form: {},
|
|
|
+ // 用户
|
|
|
+ userList: [],
|
|
|
+ // 上传图片
|
|
|
+ imgList: [],
|
|
|
+ // 成员
|
|
|
+ member: '',
|
|
|
+ memberList: []
|
|
|
+ },
|
|
|
+ // 上传图片
|
|
|
+ imgUpl: function (e) {
|
|
|
+ const that = this;
|
|
|
+ let data = that.data.imgList;
|
|
|
+ data.push(e.detail)
|
|
|
+ that.setData({ imgList: data })
|
|
|
+ },
|
|
|
+ // 删除图片
|
|
|
+ imgDel: function (e) {
|
|
|
+ const that = this;
|
|
|
+ let list = that.data.imgList;
|
|
|
+ let arr = list.filter((i, index) => index != e.detail.index)
|
|
|
+ that.setData({ imgList: arr })
|
|
|
+ },
|
|
|
+ // 选择成员
|
|
|
+ userChange(e) {
|
|
|
+ const that = this;
|
|
|
+ const memberList = that.data.memberList
|
|
|
+ const index = e.detail.value;
|
|
|
+ let data = that.data.userList[index];
|
|
|
+ if (data) {
|
|
|
+ const res = memberList.find(i => i._id == data._id)
|
|
|
+ if (!res) {
|
|
|
+ memberList.push(data)
|
|
|
+ that.setData({ memberList })
|
|
|
+ const list = memberList.map(i => { return i.name })
|
|
|
+ that.setData({ member: list.join(',') })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ //日期选择器
|
|
|
+ bindDateChange: function (e) {
|
|
|
+ const that = this;
|
|
|
+ that.setData({ "form.date": e.detail.value })
|
|
|
+ },
|
|
|
+ //时间选择器
|
|
|
+ bindTimeChange: function (e) {
|
|
|
+ const that = this;
|
|
|
+ that.setData({ "form.time": e.detail.value })
|
|
|
+ },
|
|
|
+ // 提交保存
|
|
|
+ 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;
|
|
|
+ parmas.member = that.data.memberList
|
|
|
+ parmas.number = that.data.memberList.length.toString()
|
|
|
+ parmas.logo = that.data.imgList
|
|
|
+ parmas.create_time = parmas.date + ' ' + parmas.time
|
|
|
+ delete parmas.date
|
|
|
+ delete parmas.time
|
|
|
+ if (form._id) res = await app.$api(`team/${form._id}`, 'POST', parmas);
|
|
|
+ else res = await app.$api('team', 'POST', parmas);
|
|
|
+ if (res.errcode == '0') {
|
|
|
+ wx.showToast({ title: `信息提交成功`, icon: 'success' });
|
|
|
+ wx.navigateBack({ delta: 1 });
|
|
|
+ } else {
|
|
|
+ wx.showToast({ title: `${res.errmsg}`, icon: 'none' });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面加载
|
|
|
+ */
|
|
|
+ async onLoad(options) {
|
|
|
+ const that = this;
|
|
|
+ wx.showLoading({ title: '加载中', mask: true })
|
|
|
+ //验证规则函数
|
|
|
+ that.initValidate();
|
|
|
+ await that.searchOther()
|
|
|
+ await that.search()
|
|
|
+ wx.hideLoading()
|
|
|
+ },
|
|
|
+ initValidate() {
|
|
|
+ const rules = { name: { required: true }, phone: { required: true, tel: true }, address: { required: true } }
|
|
|
+ const messages = { name: { required: '请输入团队名称' }, phone: { required: '请输入手机号' }, address: { required: '请输入单位地址' } };
|
|
|
+ this.WxValidate = new WxValidate(rules, messages)
|
|
|
+ },
|
|
|
+ // 查询其他信息
|
|
|
+ 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 })
|
|
|
+ // 成员
|
|
|
+ res = await app.$api('user', 'GET', { status: '1', type: '0' })
|
|
|
+ if (res.errcode == '0') that.setData({ userList: res.data })
|
|
|
+ },
|
|
|
+ search() {
|
|
|
+ const that = this;
|
|
|
+ wx.getStorage({
|
|
|
+ key: 'token',
|
|
|
+ async success(res) {
|
|
|
+ that.setData({ "form.administrator": res.data._id })
|
|
|
+ },
|
|
|
+ fail(err) {
|
|
|
+ console.log(err);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面初次渲染完成
|
|
|
+ */
|
|
|
+ onReady() {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面显示
|
|
|
+ */
|
|
|
+ onShow() {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面隐藏
|
|
|
+ */
|
|
|
+ onHide() {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面卸载
|
|
|
+ */
|
|
|
+ onUnload() {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 页面相关事件处理函数--监听用户下拉动作
|
|
|
+ */
|
|
|
+ onPullDownRefresh() {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 页面上拉触底事件的处理函数
|
|
|
+ */
|
|
|
+ onReachBottom() {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户点击右上角分享
|
|
|
+ */
|
|
|
+ onShareAppMessage() {
|
|
|
+
|
|
|
+ }
|
|
|
+})
|