activityPublish.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. } else {
  99. value.poster = ''
  100. }
  101. for (let i = 0; i < value.photo.length; i++) {
  102. value.photo[i] = res[i].fileID
  103. }
  104. value.photo = value.photo.join()
  105. if (value.tag) {
  106. value.tag = value.tag.join()
  107. }
  108. return wx.cloud.callFunction({
  109. name: 'createMessage',
  110. data: value
  111. })
  112. }).then(res => {
  113. wx.hideLoading()
  114. if (res.result._id !== undefined) {
  115. this.setData({
  116. currentTab: 4
  117. })
  118. } else {
  119. wx.showToast({
  120. title: res.result.errMsg,
  121. icon: 'none'
  122. })
  123. }
  124. })
  125. },
  126. returnToPublisher: function (e) {
  127. wx.navigateBack()
  128. },
  129. /**
  130. * 生命周期函数--监听页面加载
  131. */
  132. onLoad: function (options) {
  133. this.setData({
  134. publisherId: options.id
  135. })
  136. wx.getSystemInfo({
  137. success: function (res) {
  138. this.setData({
  139. winWidth: res.windowWidth
  140. })
  141. this.setData({
  142. winHeight: res.windowHeight
  143. })
  144. }.bind(this),
  145. })
  146. }
  147. })