const util = require('../../utils/util.js') Page({ /** * 页面的初始数据 */ data: { publisherId: '', messageId: '', activityInfo: {}, currentTab: 0, winWidth: 0, winHeight: 0, types1: [{ value: '志愿活动', checked: false }, { value: '文艺活动', checked: false }, { value: '体育活动', checked: false }, { value: '学术活动', checked: false }, { value: '素质拓展', checked: false }, { value: '精品课程', checked: false }, { value: '其他活动', checked: false }], types2: [{ value: '二课分', checked: false }, { value: '三课分', checked: false }, { value: '四课分', checked: false }, { value: '勤工助学', checked: false }, { value: '志愿者小时数', checked: false }, { value: '综素', checked: false }], types3: [{ value: '水电通知', checked: false }, { value: '缴费通知', checked: false }, { value: '假期通知', checked: false }, { value: '后勤通知', checked: false }, { value: '图书馆通知', checked: false }, { value: '选课通知', checked: false }, { value: '竞赛通知', checked: false }, { value: '考试通知', checked: false }, { value: '其他通知', checked: false }] }, switch1: function (e) { this.setData({ currentTab: 1 }) }, switch2: function (e) { this.setData({ currentTab: 2 }) }, switch3: function (e) { this.setData({ currentTab: 3 }) }, switch4: function (e) { const value = e.detail.value if (this.data.currentTab === 2) { value.type = ['纳新'] } if (value.name === '' || value.type.length === 0 || this.data.detail === '') { wx.showToast({ title: '请确认信息填写完整', icon: 'none' }) return } wx.showLoading({ title: '上传图片' }) const arr = [] if (value.poster.length !== 0) { arr.push(wx.cloud.uploadFile({ cloudPath: `messagePoster/${util.randomString(16)}.jpg`, filePath: value.poster[0] })) } for (let i = 0; i < value.photo.length; i++) { arr.push(wx.cloud.uploadFile({ cloudPath: `messagePhoto/${util.randomString(16)}.jpg`, filePath: value.photo[i] })) } Promise.all(arr).then(res => { wx.hideLoading() wx.showLoading({ title: '正在发布' }) value.pub_id = this.data.publisherId if (value.poster.length !== 0) { value.poster[0] = res[0].fileID res.splice(0, 1) } for (let i = 0; i < value.photo.length; i++) { value.photo[i] = res[i].fileID } value = util.msgToDb(value) return wx.cloud.callFunction({ name: 'createMessage', data: value }) }).then(res => { wx.hideLoading() if (res.result.status !== 'OK') { wx.showToast({ title: res.result.errMsg, icon: 'none' }) return } this.setData({ currentTab: 4 }) }) }, returnToPublisher: function (e) { wx.navigateBack() }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ publisherId: options.id }) if (options.msg_id) { this.setData({ messageId: options.msg_id, currentTab: -1 }) wx.showLoading({ title: '加载中' }) wx.cloud.callFunction({ name: 'getMessage', data: { msg_id: this.data.messageId } }).then(res => { wx.hideLoading() if (res.result.status !== 'OK') { wx.showToast({ title: res.result.errMsg, icon: 'none' }) return } res.result.data = util.dbToMsg(res.result.data) const type = res.result.data.type[0].substr(res.result.data.type[0].length - 2) for (let i = 0; i < this.data.types1.length; i++) { this.data.types1[i].checked = res.result.data.type.indexOf(this.data.types1[i].value) !== -1 } for (let i = 0; i < this.data.types2.length; i++) { this.data.types2[i].checked = res.result.data.tag.indexOf(this.data.types2[i].value) !== -1 } for (let i = 0; i < this.data.types3.length; i++) { this.data.types3[i].checked = res.result.data.type.indexOf(this.data.types3[i].value) !== -1 } this.setData({ types1: this.data.types1, types2: this.data.types2, types3: this.data.types3, currentTab: type === '通知' ? 3 : type === '纳新' ? 2 : 1, activityInfo: res.result.data }) }) } wx.getSystemInfo({ success: function (res) { this.setData({ winWidth: res.windowWidth }) this.setData({ winHeight: res.windowHeight }) }.bind(this), }) } })