publisherLogin.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. Page({
  2. /**
  3. * 页面的初始数据
  4. */
  5. data: {
  6. currentTab:0,
  7. winWidth:0,
  8. winHeight:0,
  9. inviteCode:"",
  10. publisherName:"",
  11. publisherContact:"",
  12. publisherIntro:"",
  13. publisherType:"",
  14. publisherAvatar:[],
  15. types:["校级", "园级", "院级"],
  16. stars:["一星级", "二星级", "三星级", "四星级", "五星级"],
  17. },
  18. stopTouchMove:function(){
  19. return false;
  20. },
  21. updateRadio:function(e){
  22. this.setData({publisherType: e.detail.value})
  23. },
  24. updatePublishAvatar:function(e){
  25. this.setData({publisherAvatar: e.detail.images})
  26. },
  27. switch1:function(e){
  28. this.setData({currentTab:1})
  29. },
  30. switch2:function(e){
  31. this.setData({currentTab:2})
  32. },
  33. switch3:function(e){
  34. this.setData({currentTab:3})
  35. },
  36. switch4:function(e){
  37. if (this.data.inviteCode == "" || this.data.publisherName == "" || this.data.publisherContact == "" ||
  38. this.data.publisherIntro == "" || this.data.publisherType == "" || this.data.publisherAvatar.length == 0) {
  39. wx.showToast({
  40. title: "请确认信息填写完整",
  41. icon: "none"
  42. })
  43. return
  44. }
  45. const db = wx.cloud.database()
  46. const _ = db.command
  47. db.collection("inviteCodeData").where({
  48. code: this.data.inviteCode,
  49. used: false
  50. }).get({
  51. success: function (code) {
  52. if (code.data.length == 0) {
  53. wx.showToast({
  54. title: "邀请码不存在",
  55. icon: "none"
  56. })
  57. return
  58. }
  59. db.collection("publisherInfoData").where({
  60. publisherName: this.data.publisherName
  61. }).get({
  62. success: function (res) {
  63. if (res.data.length != 0) {
  64. wx.showToast({
  65. title: "名称已使用",
  66. icon: "none"
  67. })
  68. return
  69. }
  70. wx.showLoading({
  71. title: "入驻中"
  72. })
  73. wx.cloud.uploadFile({
  74. cloudPath: "publisherAvater/" + this.data.publisherName + '.jpg',
  75. filePath: this.data.publisherAvatar[0],
  76. success: function (res) {
  77. db.collection("publisherInfoData").add({
  78. data: {
  79. publisherAttribute: [this.data.currentTab == 2 ? "组织" : "社团"],
  80. publisherAvatar: res.fileID,
  81. publisherContact: this.data.publisherContact,
  82. publisherIntro: this.data.publisherIntro,
  83. publisherName: this.data.publisherName,
  84. publisherType: this.data.publisherType
  85. },
  86. success: function (res) {
  87. db.collection("inviteCodeData").doc(code.data[0]._id).update({
  88. data: {
  89. used: true,
  90. publisherId: res._id
  91. },
  92. success: function () {
  93. db.collection("userInfoData").get({
  94. success: function (user) {
  95. db.collection("userInfoData").doc(user.data[0]._id).update({
  96. data: {
  97. publisherId: _.push(res._id)
  98. },
  99. success: function () {
  100. this.setData({currentTab:4})
  101. wx.hideLoading()
  102. }.bind(this)
  103. })
  104. }.bind(this)
  105. })
  106. }.bind(this)
  107. })
  108. }.bind(this)
  109. })
  110. }.bind(this)
  111. })
  112. }.bind(this)
  113. })
  114. }.bind(this)
  115. })
  116. },
  117. returnToUser:function(e){
  118. wx.navigateBack()
  119. },
  120. /**
  121. * 生命周期函数--监听页面加载
  122. */
  123. onLoad: function (e) {
  124. wx.getSystemInfo({
  125. success: function (res) {
  126. this.setData({winWidth:res.windowWidth})
  127. this.setData({winHeight:res.windowHeight})
  128. }.bind(this),
  129. })
  130. },
  131. updatePage: function(e) {
  132. this.setData({
  133. currentTab: e.detail.current
  134. })
  135. }
  136. })