const util = require('../../utils/util.js') Page({ /** * 页面的初始数据 */ data: { currentTab: 0, winWidth: 0, winHeight: 0, inviteCode: '', publisherName: '', publisherContact: '', publisherIntro: '', publisherType: '', publisherAvatar: [], types: ['园级', '院级', '校级'], stars: ['一星级', '二星级', '三星级', '四星级', '五星级'], }, switch1: function (e) { this.setData({ currentTab: 1 }) }, switch2: function (e) { this.setData({ currentTab: 2 }) }, switch3: function (e) { this.setData({ currentTab: 3 }) }, switch4: function (e) { this.setData({ currentTab: 4 }) }, switch5: function (e) { const value = e.detail.value if (this.data.currentTab === 4) { value.level = '校级' } if (value.code === '' || value.name === '' || value.level === '' || value.intro === '' || value.avatar.length === 0) { wx.showToast({ title: '请确认信息填写完整', icon: 'none' }) return } wx.showLoading({ title: '上传图片' }) wx.cloud.uploadFile({ cloudPath: `publisherAvater/${util.randomString(16)}.jpg`, filePath: value.avatar[0] }).then(res => { wx.hideLoading() wx.showLoading({ title: '正在入驻' }) value.type = this.data.currentTab === 2 ? '组织' : this.data.currentTab === 3 ? '社团' : '学校部门' value.avatar = res.fileID return wx.cloud.callFunction({ name: 'createPublisher', data: value }) }).then(res => { wx.hideLoading() if (res.result._id !== undefined) { this.setData({ currentTab: 5 }) } else { wx.showToast({ title: res.result.errMsg, icon: 'none' }) } }) }, returnToUser: function (e) { wx.navigateBack() }, /** * 生命周期函数--监听页面加载 */ onLoad: function (e) { wx.getSystemInfo({ success: function (res) { this.setData({ winWidth: res.windowWidth }) this.setData({ winHeight: res.windowHeight }) }.bind(this), }) } })