publisherLogin.js 2.1 KB

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