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:["组织纳新", "社团纳新"], types4:["选课通知", "水电通知", "缴费通知", "其他通知"], publisherId: "" }, activityAttrUpdate:function(e){ this.setData({activityAttr:e.detail.value}) }, activitySupplyUpdate:function(e){ this.setData({activitySupply:e.detail.value}) }, recruitAttrUpdate:function(e){ this.setData({recruitAttr:e.detail.value}) } , notiAttrUpdate:function(e){ this.setData({notiAttr:e.detail.value}) } , updateActivityPoster:function(e){ this.setData({activityPoster: e.detail.images}) }, updateActivityPicture:function(e){ this.setData({activityPicture: e.detail.images}) }, updateRecruitPoster:function(e){ this.setData({recruitPoster: e.detail.images}) }, updateRecruitPicture:function(e){ this.setData({recruitPicture: e.detail.images}) }, updateNotiPoster:function(e){ this.setData({notiPoster: e.detail.images}) }, updateNotiPicture:function(e){ this.setData({notiPicture: e.detail.images}) }, switch1:function(e){ this.setData({currentTab:1}) }, switch2:function(e){ this.setData({currentTab:2}) }, switch3:function(e){ this.setData({currentTab:3}) }, randomString:function(){ var char = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" var str = "" for (var i = 0; i < 16; i++) { str += char[Math.floor(Math.random() * char.length)] } return str }, switch4:function(e){ var obj = {} if (this.data.currentTab == 1) { if (this.data.activityName == "" || this.data.activityTime == "" || this.data.activityPlace == "" || this.data.activityAttr.length == 0 || this.data.activityContact == "" || this.data.activityDetail == "") { wx.showToast({ title: "请确认信息填写完整", icon: "none" }) return } obj = { title: this.data.activityName, subTitle: this.data.activitySubTitle, activityTime: this.data.activityTime, place: this.data.activityPlace, attribute: this.data.activityAttr, supply: this.data.activitySupply, contactDetails: this.data.activityContact, objectOriented: this.data.activityAim, details: this.data.activityDetail, poster: this.data.activityPoster.length == 0 ? "" : this.data.activityPoster[0], photo: this.data.activityPicture, publicity: this.data.activityProInfo, registrationLink: this.data.activitySrc } } else if (this.data.currentTab == 2) { if (this.data.recruitName == "" || this.data.recruitTime == "" || this.data.recruitAttr == "" || this.data.recruitContact == "" || this.data.recruitDetail == "") { wx.showToast({ title: "请确认信息填写完整", icon: "none" }) return } obj = { title: this.data.recruitName, subTitle: this.data.recruitSubTitle, activityTime: this.data.recruitTime, attribute: this.data.recruitAttr, contactDetails: this.data.recruitContact, objectOriented: this.data.recruitAim, details: this.data.recruitDetail, poster: this.data.recruitPoster.length == 0 ? "" : this.data.recruitPoster[0], photo: this.data.recruitPicture, publicity: this.data.recruitProInfo, registrationLink: this.data.recruitSrc } } else { if (this.data.notiName == "" || this.data.notiAttr.length == 0 || this.data.notiDetail == "") { wx.showToast({ title: "请确认信息填写完整", icon: "none" }) return } obj = { title: this.data.notiName, subTitle: this.data.notiSubTitle, attribute: this.data.notiAttr, objectOriented: this.data.notiAim, details: this.data.notiDetail, poster: this.data.notiPoster.length == 0 ? "" : this.data.notiPoster[0], photo: this.data.notiPicture } } obj.time = new Date() obj.publisherId = this.data.publisherId wx.showLoading({ title: "发布中" }) const db = wx.cloud.database() db.collection("publisherInfoData").doc(this.data.publisherId).get({ success: async function (res) { obj.publisherAvatar = res.data.publisherAvatar obj.publisherName = res.data.publisherName if (obj.poster != "") { obj.poster = (await wx.cloud.uploadFile({ cloudPath: "activityPoster/" + this.randomString() + ".jpg", filePath: obj.poster })).fileID } var arr = [] for (let i = 0; i < obj.photo.length; i++) { arr.push(wx.cloud.uploadFile({ cloudPath: "informPhoto/" + this.randomString() + ".jpg", filePath: obj.photo[i] })) } arr = await Promise.all(arr) for (let i = 0; i < obj.photo.length; i++) { obj.photo[i] = arr[i].fileID } db.collection("mainData").add({ data: obj, success: function () { this.setData({currentTab:4}) wx.hideLoading() }.bind(this) }) }.bind(this) }) }, returnToUser: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), }) }, updatePage: function(e) { this.setData({ currentTab: e.detail.current }) } })