| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- const util = require('../../utils/util.js')
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- publisherId: '',
- messageId: '',
- messageInfo: {},
- 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 && value.poster[0].substr(0, 8) !== 'cloud://') {
- arr.push(wx.cloud.uploadFile({
- cloudPath: `messagePoster/${util.randomString(16)}.jpg`,
- filePath: value.poster[0]
- }))
- }
- for (let i = 0; i < value.photo.length; i++) {
- if (value.photo[i].substr(0, 8) !== 'cloud://') {
- 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: '正在' + (this.data.messageId === '' ? '发布' : '修改')
- })
- if (this.data.messageId === '') {
- value.pub_id = this.data.publisherId
- } else {
- value.msg_id = this.data.messageId
- }
- if (value.poster.length !== 0 && value.poster[0].substr(0, 8) !== 'cloud://') {
- value.poster[0] = res[0].fileID
- res.splice(0, 1)
- }
- for (let i = 0; i < value.photo.length; i++) {
- if (value.photo[i].substr(0, 8) !== 'cloud://') {
- value.photo[i] = res[0].fileID
- res.splice(0, 1)
- }
- }
- if (this.data.messageId === '') {
- return wx.cloud.callFunction({
- name: 'createMessage',
- data: util.msgToDb(value)
- })
- } else {
- return wx.cloud.callFunction({
- name: 'updateMessage',
- data: util.msgToDb(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,
- messageInfo: res.result.data
- })
- })
- }
- wx.getSystemInfo({
- success: function (res) {
- this.setData({
- winWidth: res.windowWidth
- })
- this.setData({
- winHeight: res.windowHeight
- })
- }.bind(this),
- })
- }
- })
|