activityPublish.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. types4: ["选课通知", "水电通知", "缴费通知", "其他通知"],
  44. publisherId: ""
  45. },
  46. activityAttrUpdate: function (e) {
  47. this.setData({
  48. activityAttr: e.detail.value
  49. })
  50. },
  51. activitySupplyUpdate: function (e) {
  52. this.setData({
  53. activitySupply: e.detail.value
  54. })
  55. },
  56. recruitAttrUpdate: function (e) {
  57. this.setData({
  58. recruitAttr: e.detail.value
  59. })
  60. },
  61. notiAttrUpdate: function (e) {
  62. this.setData({
  63. notiAttr: e.detail.value
  64. })
  65. },
  66. updateActivityPoster: function (e) {
  67. this.setData({
  68. activityPoster: e.detail.images
  69. })
  70. },
  71. updateActivityPicture: function (e) {
  72. this.setData({
  73. activityPicture: e.detail.images
  74. })
  75. },
  76. updateRecruitPoster: function (e) {
  77. this.setData({
  78. recruitPoster: e.detail.images
  79. })
  80. },
  81. updateRecruitPicture: function (e) {
  82. this.setData({
  83. recruitPicture: e.detail.images
  84. })
  85. },
  86. updateNotiPoster: function (e) {
  87. this.setData({
  88. notiPoster: e.detail.images
  89. })
  90. },
  91. updateNotiPicture: function (e) {
  92. this.setData({
  93. notiPicture: e.detail.images
  94. })
  95. },
  96. switch1: function (e) {
  97. this.setData({
  98. currentTab: 1
  99. })
  100. },
  101. switch2: function (e) {
  102. this.setData({
  103. currentTab: 2
  104. })
  105. },
  106. switch3: function (e) {
  107. this.setData({
  108. currentTab: 3
  109. })
  110. },
  111. randomString: function () {
  112. var char = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
  113. var str = ""
  114. for (var i = 0; i < 16; i++) {
  115. str += char[Math.floor(Math.random() * char.length)]
  116. }
  117. return str
  118. },
  119. switch4: function (e) {
  120. var obj = {}
  121. if (this.data.currentTab == 1) {
  122. if (this.data.activityName == "" || this.data.activityTime == "" || this.data.activityPlace == "" ||
  123. this.data.activityAttr.length == 0 || this.data.activityContact == "" || this.data.activityDetail == "") {
  124. wx.showToast({
  125. title: "请确认信息填写完整",
  126. icon: "none"
  127. })
  128. return
  129. }
  130. obj = {
  131. title: this.data.activityName,
  132. subTitle: this.data.activitySubTitle,
  133. activityTime: this.data.activityTime,
  134. place: this.data.activityPlace,
  135. attribute: this.data.activityAttr,
  136. supply: this.data.activitySupply,
  137. contactDetails: this.data.activityContact,
  138. objectOriented: this.data.activityAim,
  139. details: this.data.activityDetail,
  140. poster: this.data.activityPoster.length == 0 ? "" : this.data.activityPoster[0],
  141. photo: this.data.activityPicture,
  142. publicity: this.data.activityProInfo,
  143. registrationLink: this.data.activitySrc
  144. }
  145. } else if (this.data.currentTab == 2) {
  146. if (this.data.recruitName == "" || this.data.recruitTime == "" || this.data.recruitAttr == "" ||
  147. this.data.recruitContact == "" || this.data.recruitDetail == "") {
  148. wx.showToast({
  149. title: "请确认信息填写完整",
  150. icon: "none"
  151. })
  152. return
  153. }
  154. obj = {
  155. title: this.data.recruitName,
  156. subTitle: this.data.recruitSubTitle,
  157. activityTime: this.data.recruitTime,
  158. attribute: this.data.recruitAttr,
  159. contactDetails: this.data.recruitContact,
  160. objectOriented: this.data.recruitAim,
  161. details: this.data.recruitDetail,
  162. poster: this.data.recruitPoster.length == 0 ? "" : this.data.recruitPoster[0],
  163. photo: this.data.recruitPicture,
  164. publicity: this.data.recruitProInfo,
  165. registrationLink: this.data.recruitSrc
  166. }
  167. } else {
  168. if (this.data.notiName == "" || this.data.notiAttr.length == 0 || this.data.notiDetail == "") {
  169. wx.showToast({
  170. title: "请确认信息填写完整",
  171. icon: "none"
  172. })
  173. return
  174. }
  175. obj = {
  176. title: this.data.notiName,
  177. subTitle: this.data.notiSubTitle,
  178. attribute: this.data.notiAttr,
  179. objectOriented: this.data.notiAim,
  180. details: this.data.notiDetail,
  181. poster: this.data.notiPoster.length == 0 ? "" : this.data.notiPoster[0],
  182. photo: this.data.notiPicture
  183. }
  184. }
  185. obj.time = new Date()
  186. obj.publisherId = this.data.publisherId
  187. wx.showLoading({
  188. title: "发布中"
  189. })
  190. const db = wx.cloud.database()
  191. db.collection("publisherInfoData").doc(this.data.publisherId).get({
  192. success: async function (res) {
  193. obj.publisherAvatar = res.data.publisherAvatar
  194. obj.publisherName = res.data.publisherName
  195. if (obj.poster != "") {
  196. obj.poster = (await wx.cloud.uploadFile({
  197. cloudPath: "activityPoster/" + this.randomString() + ".jpg",
  198. filePath: obj.poster
  199. })).fileID
  200. }
  201. var arr = []
  202. for (let i = 0; i < obj.photo.length; i++) {
  203. arr.push(wx.cloud.uploadFile({
  204. cloudPath: "informPhoto/" + this.randomString() + ".jpg",
  205. filePath: obj.photo[i]
  206. }))
  207. }
  208. arr = await Promise.all(arr)
  209. for (let i = 0; i < obj.photo.length; i++) {
  210. obj.photo[i] = arr[i].fileID
  211. }
  212. db.collection("mainData").add({
  213. data: obj,
  214. success: function () {
  215. this.setData({
  216. currentTab: 4
  217. })
  218. wx.hideLoading()
  219. }.bind(this)
  220. })
  221. }.bind(this)
  222. })
  223. },
  224. returnToUser: 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. updatePage: function (e) {
  246. this.setData({
  247. currentTab: e.detail.current
  248. })
  249. }
  250. })