|
|
@@ -1,129 +1,176 @@
|
|
|
+const util = require('../../utils/util.js')
|
|
|
+
|
|
|
Page({
|
|
|
|
|
|
/**
|
|
|
* 页面的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
- currentTab:0,
|
|
|
- winWidth:0,
|
|
|
- winHeight:0,
|
|
|
- inviteCode:"",
|
|
|
- publisherName:"",
|
|
|
- publisherContact:"",
|
|
|
- publisherIntro:"",
|
|
|
- publisherType:"",
|
|
|
- publisherAvatar:[],
|
|
|
- types:["校级", "园级", "院级"],
|
|
|
- stars:["一星级", "二星级", "三星级", "四星级", "五星级"],
|
|
|
+ currentTab: 0,
|
|
|
+ winWidth: 0,
|
|
|
+ winHeight: 0,
|
|
|
+ inviteCode: '',
|
|
|
+ publisherName: '',
|
|
|
+ publisherContact: '',
|
|
|
+ publisherIntro: '',
|
|
|
+ publisherType: '',
|
|
|
+ publisherAvatar: [],
|
|
|
+ types: ['园级', '院级', '校级'],
|
|
|
+ stars: ['一星级', '二星级', '三星级', '四星级', '五星级'],
|
|
|
},
|
|
|
|
|
|
- stopTouchMove:function(){
|
|
|
- return false;
|
|
|
+ stopTouchMove: function () {
|
|
|
+ return false
|
|
|
},
|
|
|
|
|
|
- updateRadio:function(e){
|
|
|
- this.setData({publisherType: e.detail.value})
|
|
|
+ bindLevelChange: function (e) {
|
|
|
+ this.setData({
|
|
|
+ publisherType: e.detail.value
|
|
|
+ })
|
|
|
},
|
|
|
|
|
|
- updatePublishAvatar:function(e){
|
|
|
- this.setData({publisherAvatar: e.detail.images})
|
|
|
+ bindAvatarChange: function (e) {
|
|
|
+ this.setData({
|
|
|
+ publisherAvatar: e.detail.images
|
|
|
+ })
|
|
|
},
|
|
|
|
|
|
- switch1:function(e){
|
|
|
- this.setData({currentTab:1})
|
|
|
+ switch1: function (e) {
|
|
|
+ this.setData({
|
|
|
+ currentTab: 1
|
|
|
+ })
|
|
|
},
|
|
|
|
|
|
- switch2:function(e){
|
|
|
- this.setData({currentTab:2})
|
|
|
+ switch2: function (e) {
|
|
|
+ this.setData({
|
|
|
+ currentTab: 2
|
|
|
+ })
|
|
|
},
|
|
|
|
|
|
- switch3:function(e){
|
|
|
- this.setData({currentTab:3})
|
|
|
+ switch3: function (e) {
|
|
|
+ this.setData({
|
|
|
+ currentTab: 3
|
|
|
+ })
|
|
|
},
|
|
|
|
|
|
- switch4:function(e){
|
|
|
- if (this.data.inviteCode == "" || this.data.publisherName == "" || this.data.publisherContact == "" ||
|
|
|
- this.data.publisherIntro == "" || this.data.publisherType == "" || this.data.publisherAvatar.length == 0) {
|
|
|
+ switch4: function (e) {
|
|
|
+ if (this.data.inviteCode == '' || this.data.publisherName == '' || this.data.publisherContact == '' ||
|
|
|
+ this.data.publisherIntro == '' || this.data.publisherType == '' || this.data.publisherAvatar.length == 0) {
|
|
|
wx.showToast({
|
|
|
- title: "请确认信息填写完整",
|
|
|
- icon: "none"
|
|
|
+ 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
|
|
|
+
|
|
|
+ // 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: this.data.publisherAvatar[0]
|
|
|
+ }).then(res => {
|
|
|
+ return wx.cloud.callFunction({
|
|
|
+ name: 'createPublisher',
|
|
|
+ data: {
|
|
|
+ code: this.data.inviteCode,
|
|
|
+ name: this.data.publisherName,
|
|
|
+ type: this.data.currentTab == 2 ? '组织' : '社团',
|
|
|
+ level: this.data.publisherType,
|
|
|
+ intro: this.data.publisherIntro,
|
|
|
+ avatar: res.fileID
|
|
|
}
|
|
|
- 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)
|
|
|
+ })
|
|
|
+ }).then(res => {
|
|
|
+ wx.hideLoading()
|
|
|
+ if (res.result.data !== undefined) {
|
|
|
+ this.setData({
|
|
|
+ currentTab: 4
|
|
|
})
|
|
|
- }.bind(this)
|
|
|
+ } else {
|
|
|
+ wx.showToast({
|
|
|
+ title: res.result.errMsg,
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ }
|
|
|
})
|
|
|
},
|
|
|
|
|
|
- returnToUser:function(e){
|
|
|
+ returnToUser: function (e) {
|
|
|
wx.navigateBack()
|
|
|
},
|
|
|
|
|
|
@@ -133,13 +180,17 @@ Page({
|
|
|
onLoad: function (e) {
|
|
|
wx.getSystemInfo({
|
|
|
success: function (res) {
|
|
|
- this.setData({winWidth:res.windowWidth})
|
|
|
- this.setData({winHeight:res.windowHeight})
|
|
|
+ this.setData({
|
|
|
+ winWidth: res.windowWidth
|
|
|
+ })
|
|
|
+ this.setData({
|
|
|
+ winHeight: res.windowHeight
|
|
|
+ })
|
|
|
}.bind(this),
|
|
|
})
|
|
|
},
|
|
|
-
|
|
|
- updatePage: function(e) {
|
|
|
+
|
|
|
+ updatePage: function (e) {
|
|
|
this.setData({
|
|
|
currentTab: e.detail.current
|
|
|
})
|