const util = require('../../utils/util.js') Page({ /** * 页面的初始数据 */ data: { currentTab: 0, winWidth: 0, winHeight: 0, activityName: '', activitySubTitle: '', activityTime: '', activityPlace: '', activityContact: '', activityAim: '', activityDetail: '', activityPoster: [], activityPicture: [], activityProInfo: '', activitySrc: '', activityAttr: [], activitySupply: [], recruitName: '', recruitSubTitle: '', recruitTime: '', recruitAttr: '', recruitContact: '', recruitAim: '', recruitDetail: '', recruitPoster: [], recruitPicture: [], recruitProInfo: '', recruitSrc: '', notiName: '', notiSubTitle: '', notiAttr: [], notiAim: '', notiDetail: '', notiPoster: [], notiPicture: [], types1: ['志愿活动', '文艺活动', '体育活动', '学术活动', '素质拓展', '精品课程', '其他活动'], types2: ['二课分', '三课分', '四课分', '勤工助学', '志愿者小时数', '综素/活动纪实'], types3: ['水电通知', '缴费通知', '假期通知', '后勤通知', '图书馆通知', '选课通知', '竞赛通知', '考试通知', '其他通知'], publisherId: '' }, 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 === '' || 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 = res[0].fileID res.splice(0, 1) } else { value.poster = '' } for (let i = 0; i < value.photo.length; i++) { value.photo[i] = res[i].fileID } value.photo = value.photo.join() if (value.tag) { value.tag = value.tag.join() } return wx.cloud.callFunction({ name: 'createMessage', data: value }) }).then(res => { wx.hideLoading() if (res.result._id !== undefined) { this.setData({ currentTab: 4 }) } else { wx.showToast({ title: res.result.errMsg, icon: 'none' }) } }) }, returnToPublisher: function (e) { wx.navigateBack() }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ publisherId: options.id }) wx.getSystemInfo({ success: function (res) { this.setData({ winWidth: res.windowWidth }) this.setData({ winHeight: res.windowHeight }) }.bind(this), }) } })