opinion.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. this.setData({currentTab:4})
  38. },
  39. switchend:function(e){
  40. if (this.data.inviteCode == "" || this.data.publisherName == "" || this.data.publisherContact == "" ||
  41. this.data.publisherIntro == "" || this.data.publisherType == "" || this.data.publisherAvatar.length == 0) {
  42. wx.showToast({
  43. title: "请确认信息填写完整",
  44. icon: "none"
  45. })
  46. return
  47. }
  48. const db = wx.cloud.database()
  49. const _ = db.command
  50. db.collection("inviteCodeData").where({
  51. code: this.data.inviteCode,
  52. used: false
  53. }).get({
  54. success: function (code) {
  55. if (code.data.length == 0) {
  56. wx.showToast({
  57. title: "邀请码不存在",
  58. icon: "none"
  59. })
  60. return
  61. }
  62. db.collection("publisherInfoData").where({
  63. publisherName: this.data.publisherName
  64. }).get({
  65. success: function (res) {
  66. if (res.data.length != 0) {
  67. wx.showToast({
  68. title: "名称已使用",
  69. icon: "none"
  70. })
  71. return
  72. }
  73. wx.showLoading({
  74. title: "入驻中"
  75. })
  76. wx.cloud.uploadFile({
  77. cloudPath: "publisherAvater/" + this.data.publisherName + '.jpg',
  78. filePath: this.data.publisherAvatar[0],
  79. success: function (res) {
  80. db.collection("publisherInfoData").add({
  81. data: {
  82. publisherAttribute: [this.data.currentTab == 2 ? "组织" : "社团"],
  83. publisherAvatar: res.fileID,
  84. publisherContact: this.data.publisherContact,
  85. publisherIntro: this.data.publisherIntro,
  86. publisherName: this.data.publisherName,
  87. publisherType: this.data.publisherType
  88. },
  89. success: function (res) {
  90. db.collection("inviteCodeData").doc(code.data[0]._id).update({
  91. data: {
  92. used: true,
  93. publisherId: res._id
  94. },
  95. success: function () {
  96. db.collection("userInfoData").get({
  97. success: function (user) {
  98. db.collection("userInfoData").doc(user.data[0]._id).update({
  99. data: {
  100. publisherId: _.push(res._id)
  101. },
  102. success: function () {
  103. this.setData({currentTab:end})
  104. wx.hideLoading()
  105. }.bind(this)
  106. })
  107. }.bind(this)
  108. })
  109. }.bind(this)
  110. })
  111. }.bind(this)
  112. })
  113. }.bind(this)
  114. })
  115. }.bind(this)
  116. })
  117. }.bind(this)
  118. })
  119. },
  120. returnToUser:function(e){
  121. wx.navigateBack()
  122. },
  123. /**
  124. * 生命周期函数--监听页面加载
  125. */
  126. onLoad: function (e) {
  127. wx.getSystemInfo({
  128. success: function (res) {
  129. this.setData({winWidth:res.windowWidth})
  130. this.setData({winHeight:res.windowHeight})
  131. }.bind(this),
  132. })
  133. },
  134. updatePage: function(e) {
  135. this.setData({
  136. currentTab: e.detail.current
  137. })
  138. }
  139. })