const util = require('../../utils/util.js') Page({ /** * 页面的初始数据 */ data: { currentTab: 0, winWidth: 0, winHeight: 0, inviteCode: '', publisherName: '', publisherContact: '', publisherIntro: '', publisherType: '', publisherAvatar: [], types: ['园级', '院级', '校级'], stars: ['一星级', '二星级', '三星级', '四星级', '五星级'], }, stopTouchMove: function () { return false }, bindLevelChange: function (e) { this.setData({ publisherType: e.detail.value }) }, bindAvatarChange: function (e) { this.setData({ publisherAvatar: e.detail.value }) }, 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 (value.code === '' || value.name === '' || value.level === '' || value.intro === '' || value.avatar.length === 0) { wx.showToast({ title: '请确认信息填写完整', icon: 'none' }) return } // const db = wx.cloud.database() // const _ = db.command // db.collection('inviteCodeData').where({ // code: this.data.inviteCode, // used: false // }).get({ // success: function (code) { // if (code.data.length == 0) { // wx.showToast({ // title: '邀请码不存在', // icon: 'none' // }) // return // } // db.collection('publisherInfoData').where({ // publisherName: this.data.publisherName // }).get({ // success: function (res) { // if (res.data.length != 0) { // wx.showToast({ // title: '名称已使用', // icon: 'none' // }) // return // } // wx.showLoading({ // title: '入驻中' // }) // wx.cloud.uploadFile({ // cloudPath: 'publisherAvater/' + this.data.publisherName + '.jpg', // filePath: this.data.publisherAvatar[0], // success: function (res) { // db.collection('publisherInfoData').add({ // data: { // publisherAttribute: [this.data.currentTab == 2 ? '组织' : '社团'], // publisherAvatar: res.fileID, // publisherContact: this.data.publisherContact, // publisherIntro: this.data.publisherIntro, // publisherName: this.data.publisherName, // publisherType: this.data.publisherType // }, // success: function (res) { // db.collection('inviteCodeData').doc(code.data[0]._id).update({ // data: { // used: true, // publisherId: res._id // }, // success: function () { // db.collection('userInfoData').get({ // success: function (user) { // db.collection('userInfoData').doc(user.data[0]._id).update({ // data: { // publisherId: _.push(res._id) // }, // success: function () { // this.setData({ // currentTab: 4 // }) // wx.hideLoading() // }.bind(this) // }) // }.bind(this) // }) // }.bind(this) // }) // }.bind(this) // }) // }.bind(this) // }) // }.bind(this) // }) // }.bind(this) // }) wx.showLoading({ title: '入驻中' }) wx.cloud.uploadFile({ cloudPath: `publisherAvater/${util.randomString(16)}.jpg`, filePath: value.avatar[0] }).then(res => { value.avatar = res.fileID return wx.cloud.callFunction({ name: 'createPublisher', data: value }) }).then(res => { wx.hideLoading() if (res.result._id !== undefined) { this.setData({ currentTab: 4 }) } 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), }) }, updatePage: function (e) { this.setData({ currentTab: e.detail.current }) } })