activityPublish.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. const util = require('../../utils/util.js')
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. winWidth: 0,
  8. winHeight: 0,
  9. types1: [{
  10. value: '志愿活动',
  11. checked: false
  12. }, {
  13. value: '文艺活动',
  14. checked: false
  15. }, {
  16. value: '体育活动',
  17. checked: false
  18. }, {
  19. value: '学术活动',
  20. checked: false
  21. }, {
  22. value: '素质拓展',
  23. checked: false
  24. }, {
  25. value: '精品课程',
  26. checked: false
  27. }, {
  28. value: '其他活动',
  29. checked: false
  30. }],
  31. types2: [{
  32. value: '二课分',
  33. checked: false
  34. }, {
  35. value: '三课分',
  36. checked: false
  37. }, {
  38. value: '四课分',
  39. checked: false
  40. }, {
  41. value: '勤工助学',
  42. checked: false
  43. }, {
  44. value: '志愿者小时数',
  45. checked: false
  46. }, {
  47. value: '综素',
  48. checked: false
  49. }],
  50. types3: [{
  51. value: '水电通知',
  52. checked: false
  53. }, {
  54. value: '缴费通知',
  55. checked: false
  56. }, {
  57. value: '假期通知',
  58. checked: false
  59. }, {
  60. value: '后勤通知',
  61. checked: false
  62. }, {
  63. value: '图书馆通知',
  64. checked: false
  65. }, {
  66. value: '选课通知',
  67. checked: false
  68. }, {
  69. value: '竞赛通知',
  70. checked: false
  71. }, {
  72. value: '考试通知',
  73. checked: false
  74. }, {
  75. value: '其他通知',
  76. checked: false
  77. }],
  78. publisherId: '',
  79. messageId: '',
  80. currentTab: 0,
  81. activityInfo: {}
  82. },
  83. switch1: function (e) {
  84. this.setData({
  85. currentTab: 1
  86. })
  87. },
  88. switch2: function (e) {
  89. this.setData({
  90. currentTab: 2
  91. })
  92. },
  93. switch3: function (e) {
  94. this.setData({
  95. currentTab: 3
  96. })
  97. },
  98. switch4: function (e) {
  99. const value = e.detail.value
  100. if (this.data.currentTab === 2) {
  101. value.type = ['纳新']
  102. }
  103. if (value.name === '' || value.type.length === 0 || this.data.detail === '') {
  104. wx.showToast({
  105. title: '请确认信息填写完整',
  106. icon: 'none'
  107. })
  108. return
  109. }
  110. wx.showLoading({
  111. title: '上传图片'
  112. })
  113. const arr = []
  114. if (value.poster.length !== 0) {
  115. arr.push(wx.cloud.uploadFile({
  116. cloudPath: `messagePoster/${util.randomString(16)}.jpg`,
  117. filePath: value.poster[0]
  118. }))
  119. }
  120. for (let i = 0; i < value.photo.length; i++) {
  121. arr.push(wx.cloud.uploadFile({
  122. cloudPath: `messagePhoto/${util.randomString(16)}.jpg`,
  123. filePath: value.photo[i]
  124. }))
  125. }
  126. Promise.all(arr).then(res => {
  127. wx.hideLoading()
  128. wx.showLoading({
  129. title: '正在发布'
  130. })
  131. value.pub_id = this.data.publisherId
  132. if (value.poster.length !== 0) {
  133. value.poster[0] = res[0].fileID
  134. res.splice(0, 1)
  135. }
  136. for (let i = 0; i < value.photo.length; i++) {
  137. value.photo[i] = res[i].fileID
  138. }
  139. value = util.msgToDb(value)
  140. return wx.cloud.callFunction({
  141. name: 'createMessage',
  142. data: value
  143. })
  144. }).then(res => {
  145. wx.hideLoading()
  146. if (res.result._id !== undefined) {
  147. this.setData({
  148. currentTab: 4
  149. })
  150. } else {
  151. wx.showToast({
  152. title: res.result.errMsg,
  153. icon: 'none'
  154. })
  155. }
  156. })
  157. },
  158. returnToPublisher: function (e) {
  159. wx.navigateBack()
  160. },
  161. /**
  162. * 生命周期函数--监听页面加载
  163. */
  164. onLoad: function (options) {
  165. this.setData({
  166. publisherId: options.id
  167. })
  168. if (options.msg_id) {
  169. this.setData({
  170. messageId: options.msg_id,
  171. currentTab: -1
  172. })
  173. wx.showLoading({
  174. title: '加载中'
  175. })
  176. wx.cloud.callFunction({
  177. name: 'getMessage',
  178. data: {
  179. msg_id: options.msg_id
  180. }
  181. }).then(res => {
  182. wx.hideLoading()
  183. res.result.list[0] = util.dbToMsg(res.result.list[0])
  184. const type = res.result.list[0].type[0].substr(res.result.list[0].type[0].length - 2)
  185. for (let i = 0; i < this.data.types1.length; i++) {
  186. this.data.types1[i].checked = res.result.list[0].type.indexOf(this.data.types1[i].value) !== -1
  187. }
  188. for (let i = 0; i < this.data.types2.length; i++) {
  189. this.data.types2[i].checked = res.result.list[0].tag.indexOf(this.data.types2[i].value) !== -1
  190. }
  191. for (let i = 0; i < this.data.types3.length; i++) {
  192. this.data.types3[i].checked = res.result.list[0].type.indexOf(this.data.types3[i].value) !== -1
  193. }
  194. this.setData({
  195. types1: this.data.types1,
  196. types2: this.data.types2,
  197. types3: this.data.types3,
  198. currentTab: type === '通知' ? 3 : type === '纳新' ? 2 : 1,
  199. activityInfo: res.result.list[0]
  200. })
  201. })
  202. }
  203. wx.getSystemInfo({
  204. success: function (res) {
  205. this.setData({
  206. winWidth: res.windowWidth
  207. })
  208. this.setData({
  209. winHeight: res.windowHeight
  210. })
  211. }.bind(this),
  212. })
  213. }
  214. })