publisherLogin.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. const app = getApp()
  2. const util = require('../../utils/util.js')
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. currentTab: 0,
  9. winWidth: 0,
  10. winHeight: 0,
  11. inviteCode: '',
  12. publisherName: '',
  13. publisherContact: '',
  14. publisherIntro: '',
  15. publisherType: '',
  16. publisherAvatar: [],
  17. types: ['园级', '院级', '校级'],
  18. stars: ['一星级', '二星级', '三星级', '四星级', '五星级'],
  19. },
  20. switch1: function (e) {
  21. this.setData({
  22. currentTab: 1
  23. })
  24. },
  25. switch2: function (e) {
  26. this.setData({
  27. currentTab: 2
  28. })
  29. },
  30. switch3: function (e) {
  31. this.setData({
  32. currentTab: 3
  33. })
  34. },
  35. switch4: function (e) {
  36. this.setData({
  37. currentTab: 4
  38. })
  39. },
  40. switch5: function (e) {
  41. const value = e.detail.value
  42. if (this.data.currentTab === 4) {
  43. value.level = '校级'
  44. }
  45. // if (value.code === '' || value.name === '' || value.level === '' || value.intro === '' || value.avatar.length === 0) {
  46. if (value.name === '' || value.level === '' || value.intro === '' || value.avatar.length === 0) {
  47. wx.showToast({
  48. title: '请确认信息填写完整',
  49. icon: 'none'
  50. })
  51. return
  52. }
  53. wx.showLoading({
  54. title: '上传图片'
  55. })
  56. wx.cloud.uploadFile({
  57. cloudPath: `publisherAvater/${util.randomString(16)}.jpg`,
  58. filePath: value.avatar[0]
  59. }).then(res => {
  60. wx.hideLoading()
  61. wx.showLoading({
  62. title: '正在入驻'
  63. })
  64. value.type = this.data.currentTab === 2 ? '组织' : this.data.currentTab === 3 ? '社团' : '学校部门'
  65. value.avatar = res.fileID
  66. return wx.cloud.callFunction({
  67. name: 'createPublisher',
  68. data: value
  69. })
  70. }).then(res => {
  71. wx.hideLoading()
  72. if (res.result.status !== 'OK') {
  73. wx.showToast({
  74. title: res.result.errMsg,
  75. icon: 'none'
  76. })
  77. return
  78. }
  79. this.setData({
  80. currentTab: 5
  81. })
  82. return wx.cloud.callFunction({
  83. name: 'listPublishers',
  84. data: {
  85. manager: true,
  86. page_token: 0,
  87. page_size: 20
  88. }
  89. })
  90. }).then(res => {
  91. if (res.result.status !== 'OK') {
  92. wx.showToast({
  93. title: res.result.errMsg,
  94. icon: 'none'
  95. })
  96. return
  97. }
  98. app.globalData.pubInfo = res.result.list
  99. })
  100. },
  101. returnToUser: function (e) {
  102. wx.navigateBack()
  103. },
  104. /**
  105. * 生命周期函数--监听页面加载
  106. */
  107. onLoad: function (e) {
  108. wx.getSystemInfo({
  109. success: function (res) {
  110. this.setData({
  111. winWidth: res.windowWidth
  112. })
  113. this.setData({
  114. winHeight: res.windowHeight
  115. })
  116. }.bind(this),
  117. })
  118. }
  119. })