publisherLogin.js 2.2 KB

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