activityPublish.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. Page({
  2. /**
  3. * 页面的初始数据
  4. */
  5. data: {
  6. currentTab: 0,
  7. winWidth: 0,
  8. winHeight: 0,
  9. activityName: "",
  10. activitySubTitle: "",
  11. activityTime: "",
  12. activityPlace: "",
  13. activityContact: "",
  14. activityAim: "",
  15. activityDetail: "",
  16. activityPoster: [],
  17. activityPicture: [],
  18. activityProInfo: "",
  19. activitySrc: "",
  20. activityAttr: [],
  21. activitySupply: [],
  22. recruitName: "",
  23. recruitSubTitle: "",
  24. recruitTime: "",
  25. recruitAttr: "",
  26. recruitContact: "",
  27. recruitAim: "",
  28. recruitDetail: "",
  29. recruitPoster: [],
  30. recruitPicture: [],
  31. recruitProInfo: "",
  32. recruitSrc: "",
  33. notiName: "",
  34. notiSubTitle: "",
  35. notiAttr: [],
  36. notiAim: "",
  37. notiDetail: "",
  38. notiPoster: [],
  39. notiPicture: [],
  40. types1: ["志愿活动", "文艺活动", "体育活动", "学术活动", "素质拓展", "精品课程", "其他活动"],
  41. types2: ["二课分", "三课分", "四课分", "勤工助学", "志愿者小时数", "综素/活动纪实"],
  42. types3: ["水电通知", "缴费通知", "假期通知", "后勤通知", "图书馆通知", "选课通知", "竞赛通知", "考试通知", "其他通知"],
  43. publisherId: ""
  44. },
  45. activityAttrUpdate: function (e) {
  46. this.setData({
  47. activityAttr: e.detail.value
  48. })
  49. },
  50. activitySupplyUpdate: function (e) {
  51. this.setData({
  52. activitySupply: e.detail.value
  53. })
  54. },
  55. recruitAttrUpdate: function (e) {
  56. this.setData({
  57. recruitAttr: e.detail.value
  58. })
  59. },
  60. notiAttrUpdate: function (e) {
  61. this.setData({
  62. notiAttr: e.detail.value
  63. })
  64. },
  65. updateActivityPoster: function (e) {
  66. this.setData({
  67. activityPoster: e.detail.images
  68. })
  69. },
  70. updateActivityPicture: function (e) {
  71. this.setData({
  72. activityPicture: e.detail.images
  73. })
  74. },
  75. updateRecruitPoster: function (e) {
  76. this.setData({
  77. recruitPoster: e.detail.images
  78. })
  79. },
  80. updateRecruitPicture: function (e) {
  81. this.setData({
  82. recruitPicture: e.detail.images
  83. })
  84. },
  85. updateNotiPoster: function (e) {
  86. this.setData({
  87. notiPoster: e.detail.images
  88. })
  89. },
  90. updateNotiPicture: function (e) {
  91. this.setData({
  92. notiPicture: e.detail.images
  93. })
  94. },
  95. switch1: function (e) {
  96. this.setData({
  97. currentTab: 1
  98. })
  99. },
  100. switch2: function (e) {
  101. this.setData({
  102. currentTab: 2
  103. })
  104. },
  105. switch3: function (e) {
  106. this.setData({
  107. currentTab: 3
  108. })
  109. },
  110. randomString: function () {
  111. var char = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
  112. var str = ""
  113. for (var i = 0; i < 16; i++) {
  114. str += char[Math.floor(Math.random() * char.length)]
  115. }
  116. return str
  117. },
  118. switch4: function (e) {
  119. var obj = {}
  120. if (this.data.currentTab == 1) {
  121. if (this.data.activityName == "" || this.data.activityTime == "" || this.data.activityPlace == "" ||
  122. this.data.activityAttr.length == 0 || this.data.activityContact == "" || this.data.activityDetail == "") {
  123. wx.showToast({
  124. title: "请确认信息填写完整",
  125. icon: "none"
  126. })
  127. return
  128. }
  129. obj = {
  130. title: this.data.activityName,
  131. subTitle: this.data.activitySubTitle,
  132. activityTime: this.data.activityTime,
  133. place: this.data.activityPlace,
  134. attribute: this.data.activityAttr,
  135. supply: this.data.activitySupply,
  136. contactDetails: this.data.activityContact,
  137. objectOriented: this.data.activityAim,
  138. details: this.data.activityDetail,
  139. poster: this.data.activityPoster.length == 0 ? "" : this.data.activityPoster[0],
  140. photo: this.data.activityPicture,
  141. publicity: this.data.activityProInfo,
  142. registrationLink: this.data.activitySrc
  143. }
  144. } else if (this.data.currentTab == 2) {
  145. if (this.data.recruitName == "" || this.data.recruitTime == "" || this.data.recruitAttr == "" ||
  146. this.data.recruitContact == "" || this.data.recruitDetail == "") {
  147. wx.showToast({
  148. title: "请确认信息填写完整",
  149. icon: "none"
  150. })
  151. return
  152. }
  153. obj = {
  154. title: this.data.recruitName,
  155. subTitle: this.data.recruitSubTitle,
  156. activityTime: this.data.recruitTime,
  157. attribute: this.data.recruitAttr,
  158. contactDetails: this.data.recruitContact,
  159. objectOriented: this.data.recruitAim,
  160. details: this.data.recruitDetail,
  161. poster: this.data.recruitPoster.length == 0 ? "" : this.data.recruitPoster[0],
  162. photo: this.data.recruitPicture,
  163. publicity: this.data.recruitProInfo,
  164. registrationLink: this.data.recruitSrc
  165. }
  166. } else {
  167. if (this.data.notiName == "" || this.data.notiAttr.length == 0 || this.data.notiDetail == "") {
  168. wx.showToast({
  169. title: "请确认信息填写完整",
  170. icon: "none"
  171. })
  172. return
  173. }
  174. obj = {
  175. title: this.data.notiName,
  176. subTitle: this.data.notiSubTitle,
  177. attribute: this.data.notiAttr,
  178. objectOriented: this.data.notiAim,
  179. details: this.data.notiDetail,
  180. poster: this.data.notiPoster.length == 0 ? "" : this.data.notiPoster[0],
  181. photo: this.data.notiPicture
  182. }
  183. }
  184. obj.time = new Date()
  185. obj.publisherId = this.data.publisherId
  186. wx.showLoading({
  187. title: "发布中"
  188. })
  189. const db = wx.cloud.database()
  190. db.collection("publisherInfoData").doc(this.data.publisherId).get({
  191. success: async function (res) {
  192. obj.publisherAvatar = res.data.publisherAvatar
  193. obj.publisherName = res.data.publisherName
  194. if (obj.poster != "") {
  195. obj.poster = (await wx.cloud.uploadFile({
  196. cloudPath: "activityPoster/" + this.randomString() + ".jpg",
  197. filePath: obj.poster
  198. })).fileID
  199. }
  200. var arr = []
  201. for (let i = 0; i < obj.photo.length; i++) {
  202. arr.push(wx.cloud.uploadFile({
  203. cloudPath: "informPhoto/" + this.randomString() + ".jpg",
  204. filePath: obj.photo[i]
  205. }))
  206. }
  207. arr = await Promise.all(arr)
  208. for (let i = 0; i < obj.photo.length; i++) {
  209. obj.photo[i] = arr[i].fileID
  210. }
  211. db.collection("mainData").add({
  212. data: obj,
  213. success: function () {
  214. this.setData({
  215. currentTab: 4
  216. })
  217. wx.hideLoading()
  218. }.bind(this)
  219. })
  220. }.bind(this)
  221. })
  222. },
  223. returnToUser: function (e) {
  224. wx.navigateBack()
  225. },
  226. /**
  227. * 生命周期函数--监听页面加载
  228. */
  229. onLoad: function (options) {
  230. this.setData({
  231. publisherId: options.id
  232. })
  233. wx.getSystemInfo({
  234. success: function (res) {
  235. this.setData({
  236. winWidth: res.windowWidth
  237. })
  238. this.setData({
  239. winHeight: res.windowHeight
  240. })
  241. }.bind(this),
  242. })
  243. },
  244. updatePage: function (e) {
  245. this.setData({
  246. currentTab: e.detail.current
  247. })
  248. }
  249. })