activityPublish.js 6.8 KB

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