| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- 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: ""
- },
- 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
- })
- }
- })
|