123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- const app = getApp()
- import WxValidate from '../../utils/wxValidate'
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- id: "",
- form: {},
- // 用户
- userList: [],
- // 上传图片
- imgList: [],
- },
- // 上传图片
- 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 member = e.detail.value
- that.setData({ "form.member": member })
- that.setData({ "form.number": member.length })
- },
- //成立日期选择器
- bindDateChange: function (e) {
- const that = this;
- that.setData({ "form.create_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.logo = that.data.imgList
- parmas.member = form.member
- parmas.number = form.number
- 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;
- that.setData({ id: options.id });
- 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 })
- },
- search() {
- const that = this;
- wx.getStorage({
- key: 'user',
- async success(res) {
- if (that.data.id) {
- let res = await app.$api(`team/${that.data.id}`, 'GET', {})
- if (res.errcode == '0') {
- let arr = res.data.create_time.split(/\s+/);
- if (arr) { res.data.date = arr[0]; res.data.time = arr[1] }
- // 成员
- const member = await app.$api('user/person', 'GET', { team: that.data.id })
- if (member.errcode == '0') {
- for (const val of res.data.member) {
- for (const as of member.data) {
- if (!as.name) as.name = '暂无';
- if (as._id == val) as.checked = true
- }
- }
- that.setData({ userList: member.data })
- }
- that.setData({ imgList: res.data.logo, form: res.data })
- } else {
- wx.showToast({ title: `${res.errmsg}`, icon: 'none' });
- }
- } else {
- // 成员
- const member = await app.$api('user/person', 'GET', {})
- if (member.errcode == '0') {
- const userList = member.data.filter(i => i.name)
- that.setData({ userList })
- }
- }
- that.setData({ "form.administrator": res.data._id })
- },
- fail(err) {
- // console.log(err);
- }
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- }
- })
|