index.js 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. //index.js
  2. //获取应用实例
  3. import fetch from '../../utils/http'
  4. const app = getApp()
  5. const $api = require('../../config/api.js').$api
  6. Page({
  7. onShow() {
  8. this.PageReset()
  9. if (this.data.Type === 1) {
  10. this.GetProjectDetail()
  11. } else {
  12. this.GetActivityDetail()
  13. this.GetCommentList()
  14. this.GetSignUpList()
  15. }
  16. },
  17. onLoad(e) {
  18. console.log(e)
  19. this.setData({
  20. Id: e.id,
  21. Type: e.type - 0,
  22. FormData: {
  23. ...this.data.FormData,
  24. activityId: e.id
  25. }
  26. })
  27. if (e.type - 0 === 1) {
  28. wx.setNavigationBarTitle({
  29. title: '项目详情'
  30. })
  31. } else {
  32. wx.setNavigationBarTitle({
  33. title: '活动详情'
  34. })
  35. }
  36. },
  37. data: {
  38. ShowMaxSwiper: false,
  39. HasSignUp: false,
  40. UserInfo: app.globalData.UserInfo,
  41. Id: null,
  42. Type: null,
  43. ShowPopup: false,
  44. FormData: {
  45. customerName: '',
  46. phone: '',
  47. idNum: '',
  48. activityId: ''
  49. },
  50. SubmitOff: true,
  51. ActivityDetail: {
  52. Title: '',
  53. Publisher: '',
  54. CreateDate: '',
  55. Content: '',
  56. BeginDate: '',
  57. EndDate: '',
  58. ActivityId: '',
  59. },
  60. CommentList: [],
  61. CurrentImgList: []
  62. },
  63. onReady() {
  64. },
  65. CloseMaxSwiper() { // 关闭大图
  66. this.setData({
  67. ShowMaxSwiper: false,
  68. CurrentIndex: 0
  69. })
  70. },
  71. PageReset() { // 页面数据重置
  72. this.setData({
  73. ActivityDetail: {
  74. Title: '',
  75. Publisher: '',
  76. CreateDate: '',
  77. Content: '',
  78. BeginDate: '',
  79. EndDate: ''
  80. },
  81. CommentList: [],
  82. SubmitOff: true,
  83. ShowPopup: false,
  84. CurrentIndex: 0
  85. })
  86. },
  87. GetSignUpList() { // 获取报名情况
  88. fetch({
  89. url: $api.user.signUpList.url.replace(':openid', app.globalData.UserInfo.openid) + '?pageNum=1&pageSize=10000',
  90. method: $api.user.signUpList.method
  91. }).then((res) => {
  92. if (res.code === 200) {
  93. res.data.records.map((item) => {
  94. if (item.activityId === this.data.FormData.activityId) {
  95. this.setData({
  96. HasSignUp: true
  97. })
  98. return
  99. }
  100. })
  101. }
  102. })
  103. },
  104. AddComment() { // 添加评论
  105. if (app.globalData.UserInfo.hasReg - 0 !== 1) {
  106. wx.navigateTo({
  107. url: '/pages/index/index?index=3'
  108. })
  109. } else {
  110. wx.navigateTo({
  111. url: '/pages/ActivityDetail/comment?id=' + this.data.Id
  112. })
  113. }
  114. },
  115. ShowSignUpPopup() { // 打开报名弹窗
  116. if (app.globalData.UserInfo.hasReg - 0 !== 1) {
  117. wx.navigateTo({
  118. url: '/pages/index/index?index=3'
  119. })
  120. } else {
  121. if (!this.data.HasSignUp) {
  122. this.setData({
  123. ShowPopup: true
  124. })
  125. }
  126. }
  127. },
  128. ClosePopup() { // 关闭报名弹窗
  129. this.setData({
  130. ShowPopup: false,
  131. FormData: {
  132. customerName: '',
  133. phone: '',
  134. idNum: '',
  135. activityId: this.data.FormData.activityId
  136. }
  137. })
  138. },
  139. FormInput(e) { // 输入form数据
  140. this.setData({
  141. FormData: {
  142. ...this.data.FormData,
  143. [e.target.dataset.name]: e.detail.value
  144. }
  145. })
  146. },
  147. Submit() { // 提交报名信息
  148. if (new Date(this.data.ActivityDetail.BeginDate).getTime() < Date.now() && new Date(this.data.ActivityDetail.EndDate).getTime() > Date.now()) {
  149. if (this.data.FormData.customerName === '') {
  150. wx.showToast({
  151. title: '姓名不能为空!',
  152. icon: 'none'
  153. })
  154. return false
  155. }
  156. if (this.data.FormData.phone === '') {
  157. wx.showToast({
  158. title: '手机号不能为空!',
  159. icon: 'none'
  160. })
  161. return false
  162. }
  163. if (this.data.FormData.idNum === '') {
  164. wx.showToast({
  165. title: '身份证号不能为空!',
  166. icon: 'none'
  167. })
  168. return false
  169. }
  170. if (this.data.SubmitOff) {
  171. this.setData({
  172. SubmitOff: false
  173. })
  174. fetch({
  175. url: $api.activity.signUp.url.replace(':openid', app.globalData.UserInfo.openid),
  176. method: $api.activity.signUp.method,
  177. data: {
  178. ...this.data.FormData
  179. }
  180. }).then((res) => {
  181. // console.log(res)
  182. if (res.code === 200) {
  183. wx.showToast({
  184. title: '报名成功!',
  185. icon: 'success'
  186. })
  187. this.setData({
  188. ShowPopup: false
  189. })
  190. } else {
  191. wx.showToast({
  192. title: res.message,
  193. icon: 'none'
  194. })
  195. this.setData({
  196. SubmitOff: true
  197. })
  198. }
  199. })
  200. }
  201. } else {
  202. if (new Date(this.data.ActivityDetail.BeginDate).getTime() > Date.now()) {
  203. wx.showToast({
  204. title: '报名时间未开始!',
  205. icon: 'none'
  206. })
  207. } else if (new Date(this.data.ActivityDetail.EndDate).getTime() < Date.now()) {
  208. wx.showToast({
  209. title: '报名已结束!',
  210. icon: 'none'
  211. })
  212. }
  213. }
  214. },
  215. GetCommentList() { // 获取评论列表
  216. fetch({
  217. url: $api.comment.list.url + '?pageNum=1&pageSize=10000&commentType=activity&mainId=' + this.data.Id,
  218. method: $api.comment.list.method
  219. }).then((res) => {
  220. if (res.code === 200) {
  221. // console.log(res.data.records)
  222. let CommentList = []
  223. res.data.records.map((item, index) => {
  224. CommentList.push({
  225. FloorUserIcon: item.avatar,
  226. FloorUserName: item.customerName,
  227. CreateDate: item.createDate,
  228. Content: item.commentContent,
  229. ImgList: item.commentImgList || [],
  230. LikeNum: '0',
  231. ParentId: item.parentId,
  232. Childs: []
  233. })
  234. let aChild = []
  235. item.childComment.map((subItem) => {
  236. aChild.push({
  237. Name: subItem.customerName,
  238. CreateDate: subItem.createDate,
  239. Content: subItem.commentContent,
  240. LikeNum: '0',
  241. ImgList: subItem.commentImgList || []
  242. })
  243. })
  244. CommentList[index].Childs = aChild
  245. })
  246. let aArr = []
  247. CommentList.map((item, index) => {
  248. if (item.ParentId !== '') {
  249. aArr.unshift(index)
  250. }
  251. })
  252. aArr.map((item) => {
  253. CommentList.splice(item - 0, 1)
  254. })
  255. this.setData({
  256. CommentList: CommentList
  257. })
  258. console.log(this.data.CommentList)
  259. }
  260. })
  261. },
  262. CheckBigImg(e) { // 查看大图
  263. // console.log(e.target.dataset)
  264. if (e.target.dataset.type - 0 === 1) { // 评论大图
  265. // console.log(this.data.CommentList[e.target.dataset.mainindex].ImgList)
  266. this.setData({
  267. CurrentImgList: this.data.CommentList[e.target.dataset.mainindex].ImgList,
  268. CurrentIndex: e.target.dataset.index,
  269. ShowMaxSwiper: true
  270. })
  271. } else { // 回复大图
  272. this.setData({
  273. CurrentImgList: this.data.CommentList[e.target.dataset.mainindex].Childs[e.target.dataset.subindex].ImgList,
  274. CurrentIndex: e.target.dataset.index,
  275. ShowMaxSwiper: true
  276. })
  277. }
  278. },
  279. GetActivityDetail() { // 获取活动详情
  280. fetch({
  281. url: $api.activity.detail.url.replace(':id', this.data.Id),
  282. method: $api.activity.detail.method
  283. }).then((res) => {
  284. if (res.code === 200) {
  285. this.setData({
  286. ActivityDetail: {
  287. Title: res.data.title,
  288. Publisher: '江北公司',
  289. CreateDate: res.data.publicDate,
  290. Content: res.data.context,
  291. BeginDate: res.data.beginDate,
  292. EndDate: res.data.endDate,
  293. ActivityId: res.data.activityId
  294. }
  295. })
  296. }
  297. })
  298. },
  299. GetProjectDetail() { // 获取项目详情
  300. fetch({
  301. url: $api.dynamic.detail.url.replace(':id', this.data.Id),
  302. method: $api.dynamic.detail.method
  303. }).then((res) => {
  304. if (res.code === 200) {
  305. this.setData({
  306. ActivityDetail: {
  307. Title: res.data.title,
  308. Publisher: '江北公司',
  309. CreateDate: res.data.publishDate,
  310. Content: res.data.url,
  311. BeginDate: '',
  312. EndDate: ''
  313. }
  314. })
  315. }
  316. })
  317. },
  318. onShareAppMessage: function () {
  319. var shareImg = app.globalData.ActivityImg
  320. if (this.data.Type == 1) {
  321. shareImg = app.globalData.DongtaiImg
  322. }
  323. return {
  324. title: this.data.ActivityDetail.Title,
  325. path: '/pages/ActivityDetail/index?id=' + this.data.Id + '&type='+this.data.Type,
  326. imageUrl: shareImg
  327. }
  328. }
  329. })