activityPublish.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. const util = require('../../utils/util.js')
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. currentTab: 0,
  8. winWidth: 0,
  9. winHeight: 0,
  10. activityName: '',
  11. activitySubTitle: '',
  12. activityTime: '',
  13. activityPlace: '',
  14. activityContact: '',
  15. activityAim: '',
  16. activityDetail: '',
  17. activityPoster: [],
  18. activityPicture: [],
  19. activityProInfo: '',
  20. activitySrc: '',
  21. activityAttr: [],
  22. activitySupply: [],
  23. recruitName: '',
  24. recruitSubTitle: '',
  25. recruitTime: '',
  26. recruitAttr: '',
  27. recruitContact: '',
  28. recruitAim: '',
  29. recruitDetail: '',
  30. recruitPoster: [],
  31. recruitPicture: [],
  32. recruitProInfo: '',
  33. recruitSrc: '',
  34. notiName: '',
  35. notiSubTitle: '',
  36. notiAttr: [],
  37. notiAim: '',
  38. notiDetail: '',
  39. notiPoster: [],
  40. notiPicture: [],
  41. types1: ['志愿活动', '文艺活动', '体育活动', '学术活动', '素质拓展', '精品课程', '其他活动'],
  42. types2: ['二课分', '三课分', '四课分', '勤工助学', '志愿者小时数', '综素/活动纪实'],
  43. types3: ['水电通知', '缴费通知', '假期通知', '后勤通知', '图书馆通知', '选课通知', '竞赛通知', '考试通知', '其他通知'],
  44. publisherId: ''
  45. },
  46. switch1: function (e) {
  47. this.setData({
  48. currentTab: 1
  49. })
  50. },
  51. switch2: function (e) {
  52. this.setData({
  53. currentTab: 2
  54. })
  55. },
  56. switch3: function (e) {
  57. this.setData({
  58. currentTab: 3
  59. })
  60. },
  61. switch4: function (e) {
  62. const value = e.detail.value
  63. if (this.data.currentTab === 2) {
  64. value.type = '纳新'
  65. }
  66. if (value.name === '' || value.type === '' || this.data.detail === '') {
  67. wx.showToast({
  68. title: '请确认信息填写完整',
  69. icon: 'none'
  70. })
  71. return
  72. }
  73. wx.showLoading({
  74. title: '上传图片'
  75. })
  76. const arr = []
  77. if (value.poster.length !== 0) {
  78. arr.push(wx.cloud.uploadFile({
  79. cloudPath: `messagePoster/${util.randomString(16)}.jpg`,
  80. filePath: value.poster[0]
  81. }))
  82. }
  83. for (let i = 0; i < value.photo.length; i++) {
  84. arr.push(wx.cloud.uploadFile({
  85. cloudPath: `messagePhoto/${util.randomString(16)}.jpg`,
  86. filePath: value.photo[i]
  87. }))
  88. }
  89. Promise.all(arr).then(res => {
  90. wx.hideLoading()
  91. wx.showLoading({
  92. title: '正在发布',
  93. })
  94. value.pub_id = this.data.publisherId
  95. if (value.poster.length !== 0) {
  96. value.poster = res[0].fileID
  97. res.splice(0, 1)
  98. }
  99. for (let i = 0; i < value.photo.length; i++) {
  100. value.photo[i] = res[i].fileID
  101. }
  102. value.photo = value.photo.join()
  103. if (value.tag) {
  104. value.tag = value.tag.join()
  105. }
  106. return wx.cloud.callFunction({
  107. name: 'createMessage',
  108. data: value
  109. })
  110. }).then(res => {
  111. wx.hideLoading()
  112. if (res.result._id !== undefined) {
  113. this.setData({
  114. currentTab: 4
  115. })
  116. } else {
  117. wx.showToast({
  118. title: res.result.errMsg,
  119. icon: 'none'
  120. })
  121. }
  122. })
  123. },
  124. returnToPublisher: function (e) {
  125. wx.navigateBack()
  126. },
  127. /**
  128. * 生命周期函数--监听页面加载
  129. */
  130. onLoad: function (options) {
  131. this.setData({
  132. publisherId: options.id
  133. })
  134. wx.getSystemInfo({
  135. success: function (res) {
  136. this.setData({
  137. winWidth: res.windowWidth
  138. })
  139. this.setData({
  140. winHeight: res.windowHeight
  141. })
  142. }.bind(this),
  143. })
  144. }
  145. })