| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- 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) {
- // 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)
- // })
- const value = e.detail.value
- if (value.name === '' || this.data.currentTab !== 2 && 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)
- }
- 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),
- })
- }
- })
|