publisherLogin.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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.value
  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. const value = e.detail.value
  49. if (value.code === '' || value.name === '' || value.level === '' || value.intro === '' || value.avatar.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: value.avatar[0]
  135. }).then(res => {
  136. value.avatar = res.fileID
  137. return wx.cloud.callFunction({
  138. name: 'createPublisher',
  139. data: value
  140. })
  141. }).then(res => {
  142. wx.hideLoading()
  143. if (res.result._id !== undefined) {
  144. this.setData({
  145. currentTab: 4
  146. })
  147. } else {
  148. wx.showToast({
  149. title: res.result.errMsg,
  150. icon: 'none'
  151. })
  152. }
  153. })
  154. },
  155. returnToUser: function (e) {
  156. wx.navigateBack()
  157. },
  158. /**
  159. * 生命周期函数--监听页面加载
  160. */
  161. onLoad: function (e) {
  162. wx.getSystemInfo({
  163. success: function (res) {
  164. this.setData({
  165. winWidth: res.windowWidth
  166. })
  167. this.setData({
  168. winHeight: res.windowHeight
  169. })
  170. }.bind(this),
  171. })
  172. },
  173. updatePage: function (e) {
  174. this.setData({
  175. currentTab: e.detail.current
  176. })
  177. }
  178. })