activityPublish.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. // var obj = {}
  63. // if (this.data.currentTab == 1) {
  64. // if (this.data.activityName == '' || this.data.activityTime == '' || this.data.activityPlace == '' ||
  65. // this.data.activityAttr.length == 0 || this.data.activityContact == '' || this.data.activityDetail == '') {
  66. // wx.showToast({
  67. // title: '请确认信息填写完整',
  68. // icon: 'none'
  69. // })
  70. // return
  71. // }
  72. // obj = {
  73. // title: this.data.activityName,
  74. // subTitle: this.data.activitySubTitle,
  75. // activityTime: this.data.activityTime,
  76. // place: this.data.activityPlace,
  77. // attribute: this.data.activityAttr,
  78. // supply: this.data.activitySupply,
  79. // contactDetails: this.data.activityContact,
  80. // objectOriented: this.data.activityAim,
  81. // details: this.data.activityDetail,
  82. // poster: this.data.activityPoster.length == 0 ? '' : this.data.activityPoster[0],
  83. // photo: this.data.activityPicture,
  84. // publicity: this.data.activityProInfo,
  85. // registrationLink: this.data.activitySrc
  86. // }
  87. // } else if (this.data.currentTab == 2) {
  88. // if (this.data.recruitName == '' || this.data.recruitTime == '' || this.data.recruitAttr == '' ||
  89. // this.data.recruitContact == '' || this.data.recruitDetail == '') {
  90. // wx.showToast({
  91. // title: '请确认信息填写完整',
  92. // icon: 'none'
  93. // })
  94. // return
  95. // }
  96. // obj = {
  97. // title: this.data.recruitName,
  98. // subTitle: this.data.recruitSubTitle,
  99. // activityTime: this.data.recruitTime,
  100. // attribute: this.data.recruitAttr,
  101. // contactDetails: this.data.recruitContact,
  102. // objectOriented: this.data.recruitAim,
  103. // details: this.data.recruitDetail,
  104. // poster: this.data.recruitPoster.length == 0 ? '' : this.data.recruitPoster[0],
  105. // photo: this.data.recruitPicture,
  106. // publicity: this.data.recruitProInfo,
  107. // registrationLink: this.data.recruitSrc
  108. // }
  109. // } else {
  110. // if (this.data.notiName == '' || this.data.notiAttr.length == 0 || this.data.notiDetail == '') {
  111. // wx.showToast({
  112. // title: '请确认信息填写完整',
  113. // icon: 'none'
  114. // })
  115. // return
  116. // }
  117. // obj = {
  118. // title: this.data.notiName,
  119. // subTitle: this.data.notiSubTitle,
  120. // attribute: this.data.notiAttr,
  121. // objectOriented: this.data.notiAim,
  122. // details: this.data.notiDetail,
  123. // poster: this.data.notiPoster.length == 0 ? '' : this.data.notiPoster[0],
  124. // photo: this.data.notiPicture
  125. // }
  126. // }
  127. // obj.time = new Date()
  128. // obj.publisherId = this.data.publisherId
  129. // wx.showLoading({
  130. // title: '发布中'
  131. // })
  132. // const db = wx.cloud.database()
  133. // db.collection('publisherInfoData').doc(this.data.publisherId).get({
  134. // success: async function (res) {
  135. // obj.publisherAvatar = res.data.publisherAvatar
  136. // obj.publisherName = res.data.publisherName
  137. // if (obj.poster != '') {
  138. // obj.poster = (await wx.cloud.uploadFile({
  139. // cloudPath: 'activityPoster/' + this.randomString() + '.jpg',
  140. // filePath: obj.poster
  141. // })).fileID
  142. // }
  143. // var arr = []
  144. // for (let i = 0; i < obj.photo.length; i++) {
  145. // arr.push(wx.cloud.uploadFile({
  146. // cloudPath: 'informPhoto/' + this.randomString() + '.jpg',
  147. // filePath: obj.photo[i]
  148. // }))
  149. // }
  150. // arr = await Promise.all(arr)
  151. // for (let i = 0; i < obj.photo.length; i++) {
  152. // obj.photo[i] = arr[i].fileID
  153. // }
  154. // db.collection('mainData').add({
  155. // data: obj,
  156. // success: function () {
  157. // this.setData({
  158. // currentTab: 4
  159. // })
  160. // wx.hideLoading()
  161. // }.bind(this)
  162. // })
  163. // }.bind(this)
  164. // })
  165. const value = e.detail.value
  166. if (value.name === '' || this.data.currentTab !== 2 && value.type === '' || this.data.detail === '') {
  167. wx.showToast({
  168. title: '请确认信息填写完整',
  169. icon: 'none'
  170. })
  171. return
  172. }
  173. wx.showLoading({
  174. title: '上传图片'
  175. })
  176. const arr = []
  177. if (value.poster.length !== 0) {
  178. arr.push(wx.cloud.uploadFile({
  179. cloudPath: `messagePoster/${util.randomString(16)}.jpg`,
  180. filePath: value.poster[0]
  181. }))
  182. }
  183. for (let i = 0; i < value.photo.length; i++) {
  184. arr.push(wx.cloud.uploadFile({
  185. cloudPath: `messagePhoto/${util.randomString(16)}.jpg`,
  186. filePath: value.photo[i]
  187. }))
  188. }
  189. Promise.all(arr).then(res => {
  190. wx.hideLoading()
  191. wx.showLoading({
  192. title: '正在发布',
  193. })
  194. value.pub_id = this.data.publisherId
  195. if (value.poster.length !== 0) {
  196. value.poster = res[0].fileID
  197. res.splice(0, 1)
  198. }
  199. for (let i = 0; i < value.photo.length; i++) {
  200. value.photo[i] = res[i].fileID
  201. }
  202. value.photo = value.photo.join()
  203. if (value.tag) {
  204. value.tag = value.tag.join()
  205. }
  206. return wx.cloud.callFunction({
  207. name: 'createMessage',
  208. data: value
  209. })
  210. }).then(res => {
  211. wx.hideLoading()
  212. if (res.result._id !== undefined) {
  213. this.setData({
  214. currentTab: 4
  215. })
  216. } else {
  217. wx.showToast({
  218. title: res.result.errMsg,
  219. icon: 'none'
  220. })
  221. }
  222. })
  223. },
  224. returnToPublisher: function (e) {
  225. wx.navigateBack()
  226. },
  227. /**
  228. * 生命周期函数--监听页面加载
  229. */
  230. onLoad: function (options) {
  231. this.setData({
  232. publisherId: options.id
  233. })
  234. wx.getSystemInfo({
  235. success: function (res) {
  236. this.setData({
  237. winWidth: res.windowWidth
  238. })
  239. this.setData({
  240. winHeight: res.windowHeight
  241. })
  242. }.bind(this),
  243. })
  244. }
  245. })