publisherLogin.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. const util = require('../../utils/util.js')
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. currentTab: 0,
  8. winWidth: 0,
  9. winHeight: 0,
  10. inviteCode: '',
  11. publisherName: '',
  12. publisherContact: '',
  13. publisherIntro: '',
  14. publisherType: '',
  15. publisherAvatar: [],
  16. types: ['园级', '院级', '校级'],
  17. stars: ['一星级', '二星级', '三星级', '四星级', '五星级'],
  18. },
  19. stopTouchMove: function () {
  20. return false
  21. },
  22. bindLevelChange: function (e) {
  23. this.setData({
  24. publisherType: e.detail.value
  25. })
  26. },
  27. bindAvatarChange: function (e) {
  28. this.setData({
  29. publisherAvatar: e.detail.images
  30. })
  31. },
  32. switch1: function (e) {
  33. this.setData({
  34. currentTab: 1
  35. })
  36. },
  37. switch2: function (e) {
  38. this.setData({
  39. currentTab: 2
  40. })
  41. },
  42. switch3: function (e) {
  43. this.setData({
  44. currentTab: 3
  45. })
  46. },
  47. switch4: function (e) {
  48. if (this.data.inviteCode == '' || this.data.publisherName == '' || this.data.publisherContact == '' ||
  49. this.data.publisherIntro == '' || this.data.publisherType == '' || this.data.publisherAvatar.length == 0) {
  50. wx.showToast({
  51. title: '请确认信息填写完整',
  52. icon: 'none'
  53. })
  54. return
  55. }
  56. // const db = wx.cloud.database()
  57. // const _ = db.command
  58. // db.collection('inviteCodeData').where({
  59. // code: this.data.inviteCode,
  60. // used: false
  61. // }).get({
  62. // success: function (code) {
  63. // if (code.data.length == 0) {
  64. // wx.showToast({
  65. // title: '邀请码不存在',
  66. // icon: 'none'
  67. // })
  68. // return
  69. // }
  70. // db.collection('publisherInfoData').where({
  71. // publisherName: this.data.publisherName
  72. // }).get({
  73. // success: function (res) {
  74. // if (res.data.length != 0) {
  75. // wx.showToast({
  76. // title: '名称已使用',
  77. // icon: 'none'
  78. // })
  79. // return
  80. // }
  81. // wx.showLoading({
  82. // title: '入驻中'
  83. // })
  84. // wx.cloud.uploadFile({
  85. // cloudPath: 'publisherAvater/' + this.data.publisherName + '.jpg',
  86. // filePath: this.data.publisherAvatar[0],
  87. // success: function (res) {
  88. // db.collection('publisherInfoData').add({
  89. // data: {
  90. // publisherAttribute: [this.data.currentTab == 2 ? '组织' : '社团'],
  91. // publisherAvatar: res.fileID,
  92. // publisherContact: this.data.publisherContact,
  93. // publisherIntro: this.data.publisherIntro,
  94. // publisherName: this.data.publisherName,
  95. // publisherType: this.data.publisherType
  96. // },
  97. // success: function (res) {
  98. // db.collection('inviteCodeData').doc(code.data[0]._id).update({
  99. // data: {
  100. // used: true,
  101. // publisherId: res._id
  102. // },
  103. // success: function () {
  104. // db.collection('userInfoData').get({
  105. // success: function (user) {
  106. // db.collection('userInfoData').doc(user.data[0]._id).update({
  107. // data: {
  108. // publisherId: _.push(res._id)
  109. // },
  110. // success: function () {
  111. // this.setData({
  112. // currentTab: 4
  113. // })
  114. // wx.hideLoading()
  115. // }.bind(this)
  116. // })
  117. // }.bind(this)
  118. // })
  119. // }.bind(this)
  120. // })
  121. // }.bind(this)
  122. // })
  123. // }.bind(this)
  124. // })
  125. // }.bind(this)
  126. // })
  127. // }.bind(this)
  128. // })
  129. wx.showLoading({
  130. title: '入驻中'
  131. })
  132. wx.cloud.uploadFile({
  133. cloudPath: `publisherAvater/${util.randomString(16)}.jpg`,
  134. filePath: this.data.publisherAvatar[0]
  135. }).then(res => {
  136. return wx.cloud.callFunction({
  137. name: 'createPublisher',
  138. data: {
  139. code: this.data.inviteCode,
  140. name: this.data.publisherName,
  141. type: this.data.currentTab == 2 ? '组织' : '社团',
  142. level: this.data.publisherType,
  143. intro: this.data.publisherIntro,
  144. avatar: res.fileID
  145. }
  146. })
  147. }).then(res => {
  148. wx.hideLoading()
  149. if (res.result._id !== undefined) {
  150. this.setData({
  151. currentTab: 4
  152. })
  153. } else {
  154. wx.showToast({
  155. title: res.result.errMsg,
  156. icon: 'none'
  157. })
  158. }
  159. })
  160. },
  161. returnToUser: function (e) {
  162. wx.navigateBack()
  163. },
  164. /**
  165. * 生命周期函数--监听页面加载
  166. */
  167. onLoad: function (e) {
  168. wx.getSystemInfo({
  169. success: function (res) {
  170. this.setData({
  171. winWidth: res.windowWidth
  172. })
  173. this.setData({
  174. winHeight: res.windowHeight
  175. })
  176. }.bind(this),
  177. })
  178. },
  179. updatePage: function (e) {
  180. this.setData({
  181. currentTab: e.detail.current
  182. })
  183. }
  184. })