publisherLogin.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. switch1: function (e) {
  20. this.setData({
  21. currentTab: 1
  22. })
  23. },
  24. switch2: function (e) {
  25. this.setData({
  26. currentTab: 2
  27. })
  28. },
  29. switch3: function (e) {
  30. this.setData({
  31. currentTab: 3
  32. })
  33. },
  34. switch4: function (e) {
  35. this.setData({
  36. currentTab: 4
  37. })
  38. },
  39. switch5: function (e) {
  40. const value = e.detail.value
  41. if (this.data.currentTab === 4) {
  42. value.level = '校级'
  43. }
  44. if (value.code === '' || value.name === '' || value.level === '' || value.intro === '' || value.avatar.length === 0) {
  45. wx.showToast({
  46. title: '请确认信息填写完整',
  47. icon: 'none'
  48. })
  49. return
  50. }
  51. wx.showLoading({
  52. title: '上传图片'
  53. })
  54. wx.cloud.uploadFile({
  55. cloudPath: `publisherAvater/${util.randomString(16)}.jpg`,
  56. filePath: value.avatar[0]
  57. }).then(res => {
  58. wx.hideLoading()
  59. wx.showLoading({
  60. title: '正在入驻',
  61. })
  62. value.type = this.data.currentTab === 2 ? '组织' : this.data.currentTab === 3 ? '社团' : '学校部门'
  63. value.avatar = res.fileID
  64. return wx.cloud.callFunction({
  65. name: 'createPublisher',
  66. data: value
  67. })
  68. }).then(res => {
  69. wx.hideLoading()
  70. if (res.result._id !== undefined) {
  71. this.setData({
  72. currentTab: 5
  73. })
  74. } else {
  75. wx.showToast({
  76. title: res.result.errMsg,
  77. icon: 'none'
  78. })
  79. }
  80. })
  81. },
  82. returnToUser: function (e) {
  83. wx.navigateBack()
  84. },
  85. /**
  86. * 生命周期函数--监听页面加载
  87. */
  88. onLoad: function (e) {
  89. wx.getSystemInfo({
  90. success: function (res) {
  91. this.setData({
  92. winWidth: res.windowWidth
  93. })
  94. this.setData({
  95. winHeight: res.windowHeight
  96. })
  97. }.bind(this),
  98. })
  99. }
  100. })