publisherLogin.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. if (value.name === '' || value.level === '' || value.intro === '' || value.avatar.length === 0) {
  46. wx.showToast({
  47. title: '请确认信息填写完整',
  48. icon: 'none'
  49. })
  50. return
  51. }
  52. wx.showLoading({
  53. title: '上传图片'
  54. })
  55. wx.cloud.uploadFile({
  56. cloudPath: `publisherAvater/${util.randomString(16)}.jpg`,
  57. filePath: value.avatar[0]
  58. }).then(res => {
  59. wx.hideLoading()
  60. wx.showLoading({
  61. title: '正在入驻'
  62. })
  63. value.type = this.data.currentTab === 2 ? '组织' : this.data.currentTab === 3 ? '社团' : '学校部门'
  64. value.avatar = res.fileID
  65. return wx.cloud.callFunction({
  66. name: 'createPublisher',
  67. data: value
  68. })
  69. }).then(res => {
  70. wx.hideLoading()
  71. if (res.result.status !== 'OK') {
  72. wx.showToast({
  73. title: res.result.errMsg,
  74. icon: 'none'
  75. })
  76. return
  77. }
  78. this.setData({
  79. currentTab: 5
  80. })
  81. })
  82. },
  83. returnToUser: function (e) {
  84. wx.navigateBack()
  85. },
  86. /**
  87. * 生命周期函数--监听页面加载
  88. */
  89. onLoad: function (e) {
  90. wx.getSystemInfo({
  91. success: function (res) {
  92. this.setData({
  93. winWidth: res.windowWidth
  94. })
  95. this.setData({
  96. winHeight: res.windowHeight
  97. })
  98. }.bind(this),
  99. })
  100. }
  101. })