index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. // pages/activity/index/index.js
  2. import httpRequestApi from '../../../utils/APIClient';
  3. import {
  4. formatDate
  5. } from '../../../utils/util';
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. activityReadData: [],
  12. selectInd: 0,
  13. selectBg: ['../../../static/activity/right.png', '../../../static/activity/left.png'],
  14. activityMyReadData: [],
  15. nextMargin: '400rpx', // 视频下边距
  16. isSwiper: false,
  17. noMoreWork: false,
  18. hotAmountTopData: [],
  19. sortImg: ['../../../static/activity/1.png', '../../../static/activity/2.png', '../../../static/activity/3.png'],
  20. grades: '',
  21. gradeObj: {
  22. "PRIMARY_FIRST_GRADE": "一年级",
  23. "PRIMARY_SECOND_GRADE": "二年级",
  24. "PRIMARY_THREE_GRADE": "三年级",
  25. "PRIMARY_SENIOR_GRADE": "四年级"
  26. },
  27. myHotAmountData: {},
  28. commentShow: false,
  29. commentList: [],
  30. commentNum: 0,
  31. },
  32. /**
  33. * 生命周期函数--监听页面加载
  34. */
  35. onLoad: function (options) {
  36. // 接口调用
  37. const grade = wx.getStorageSync('grade')
  38. this.setData({
  39. grades: this.data.gradeObj[grade]
  40. })
  41. httpRequestApi.getActivityRead(grade).success(res => {
  42. if (res.data.code === 200) {
  43. const activityReadData = [...res.data.data]
  44. this.setData({
  45. activityReadData
  46. })
  47. }
  48. })
  49. },
  50. /**
  51. * 生命周期函数--监听页面初次渲染完成
  52. */
  53. onReady: function () {
  54. },
  55. /**
  56. * 生命周期函数--监听页面显示
  57. */
  58. onShow: function () {
  59. /**
  60. * 获取排名信息
  61. */
  62. httpRequestApi.getHotAmountTop().success(res => {
  63. if (res.data.code === 200) {
  64. const hotAmountTopData = [...res.data.data]
  65. this.setData({
  66. hotAmountTopData
  67. })
  68. }
  69. })
  70. /**
  71. * 获取我的排名信息
  72. */
  73. httpRequestApi.getMyHotAmount().success(res => {
  74. if (res.data.code === 200) {
  75. // console.log(res)
  76. const myHotAmountData = res.data.data
  77. this.setData({
  78. myHotAmountData
  79. })
  80. }
  81. })
  82. },
  83. /**
  84. * 生命周期函数--监听页面隐藏
  85. */
  86. onHide: function () {
  87. },
  88. /**
  89. * 生命周期函数--监听页面卸载
  90. */
  91. onUnload: function () {
  92. },
  93. /**
  94. * 下拉
  95. */
  96. onPullDownRefresh: function () {
  97. wx.showNavigationBarLoading() //在标题栏中显示加载
  98. /**
  99. * 获取排名信息
  100. */
  101. httpRequestApi.getHotAmountTop().success(res => {
  102. if (res.data.code === 200) {
  103. const hotAmountTopData = [...res.data.data]
  104. this.setData({
  105. hotAmountTopData
  106. })
  107. wx.hideNavigationBarLoading() //完成停止加载
  108. wx.stopPullDownRefresh() //停止下拉刷新
  109. }
  110. })
  111. /**
  112. * 获取我的排名信息
  113. */
  114. httpRequestApi.getMyHotAmount().success(res => {
  115. if (res.data.code === 200) {
  116. // console.log(res)
  117. const myHotAmountData = res.data.data
  118. this.setData({
  119. myHotAmountData
  120. })
  121. }
  122. })
  123. },
  124. /**
  125. *
  126. * @param {*} res
  127. * 分享
  128. */
  129. onShareAppMessage: function (res) {
  130. console.log('onShareAppMessage>>>>>>>>>>>>')
  131. if (res.from === 'button') {
  132. return {
  133. title: '请欣赏我的课文朗读作品,点赞+评论。',
  134. path: `/pages/index/index?readId=${this.data.shareId}&activity=true`,
  135. imageUrl: this.data.shareImg
  136. }
  137. } else {
  138. return {
  139. title: '课文朗读,从未如此有趣。',
  140. path: '/pages/index/index',
  141. }
  142. }
  143. },
  144. /**
  145. * 活动页点击切换
  146. */
  147. tabSelect({
  148. currentTarget
  149. }) {
  150. const selectInd = currentTarget.dataset.index * 1
  151. if (selectInd === this.data.selectInd) return;
  152. this.setData({
  153. selectInd
  154. });
  155. if (selectInd === 1) {
  156. this.getMyRead();
  157. }
  158. },
  159. /**
  160. * 去比赛
  161. */
  162. goToReading({
  163. currentTarget
  164. }) {
  165. const id = currentTarget.dataset.id
  166. wx.navigateTo({
  167. url: `../../reading/reading?id=${id}`
  168. });
  169. },
  170. /**
  171. * 修改list列表
  172. * @param {*} 列表
  173. */
  174. formatWorksList(list) {
  175. this.data.activityMyReadData = [];
  176. list.forEach((item) => {
  177. const temp = {};
  178. temp.title = item.userRead.title;
  179. temp.summary = item.userRead.summary;
  180. temp.img = item.userRead.iconImg;
  181. temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
  182. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  183. temp.commentAmount = item.userRead.commentAmount ? item.userRead.commentAmount : 0;
  184. temp.shareAmount = item.userRead.shareAmount;
  185. temp.favoritesAmount = item.userRead.favoritesAmount;
  186. temp.classId = item.userRead.exampleId ? item.userRead.exampleId : 1605097720036046;
  187. temp.time = formatDate(item.userRead.gmtCreated, 3);
  188. temp.avatar = item.user.avatar;
  189. temp.profession = item.user.profession;
  190. temp.uid = item.user.uid;
  191. temp.markPath = item.userRead.markPath ? item.userRead.markPath : item.userRead.videoPath;
  192. temp.url = item.userRead.videoPath ? item.userRead.videoPath : item.userRead.originVideo;
  193. temp.id = item.userRead.id;
  194. temp.type = item.userRead.type;
  195. temp.nickName = item.user.wechatName;
  196. temp.isLike = item.isLike;
  197. temp.isFavorite = item.isFavorites;
  198. temp.showMyBtn = true;
  199. temp.nickName = item.user.wechatName;
  200. temp.status = item.userRead.status;
  201. temp.ifCheck = item.userRead.status === 'CHECK' ? true : false;
  202. temp.coverImg = item.userRead.coverImg;
  203. temp.grade = item.userRead.grade
  204. temp.isFans = true;
  205. temp.videoShow = false;
  206. temp.shareImg = item.userRead.shareImg;
  207. temp.activity = true;
  208. temp.noReading = true;
  209. this.data.activityMyReadData.push(temp);
  210. // tempList.push(temp);
  211. });
  212. // if (!notSet) {
  213. this.setData({
  214. activityMyReadData: this.data.activityMyReadData
  215. })
  216. // }
  217. },
  218. /**
  219. * 获取我的朗读
  220. */
  221. getMyRead() {
  222. httpRequestApi.getActivityMyRead().success(res => {
  223. if (res.data.code === 200) {
  224. const recommendRes = res.data.data;
  225. this.formatWorksList(recommendRes);
  226. }
  227. })
  228. },
  229. /**
  230. * 点击删除按钮
  231. */
  232. delHideMyWork() {
  233. this.getMyRead()
  234. },
  235. /**
  236. * 点击收藏按钮
  237. */
  238. collectTap(e) {
  239. const index = e.detail.index;
  240. let str = `activityMyReadData[${index}].isFavorite`;
  241. let str2 = `activityMyReadData[${index}].favoritesAmount`;
  242. let favoritesAmount = e.detail.isCollect ? this.data.activityMyReadData[index].favoritesAmount + 1 : this.data.activityMyReadData[index].favoritesAmount - 1
  243. this.setData({
  244. [str]: e.detail.isCollect,
  245. [str2]: favoritesAmount
  246. })
  247. },
  248. /**
  249. * 点赞执行事件
  250. */
  251. likeTap(e) {
  252. const index = e.detail.index;
  253. let likeStr = `activityMyReadData[${index}].isLike`;
  254. let likeNumStr = `activityMyReadData[${index}].likes`;
  255. this.setData({
  256. [likeStr]: true,
  257. [likeNumStr]: this.data.activityMyReadData[index].likes + 1
  258. })
  259. // this.flowerAnimationHandler()
  260. },
  261. /**
  262. * 打开评论
  263. */
  264. openComment: function (e) {
  265. //
  266. this.setData({
  267. commentShow: !this.data.commentShow,
  268. commentId: e.detail.activeId,
  269. commentIndex: e.detail.activeIndex
  270. });
  271. },
  272. /**
  273. * 评论区点击
  274. */
  275. commentTap: function (e) {
  276. console.log('点击评论区', e)
  277. if (e.target.dataset.type === 'blank') {
  278. if (this.data.commentShow && this.data.commentId) {
  279. httpRequestApi.getClassDetail(this.data.commentId).success(res => {
  280. console.log('评论回显', res.data.data.userRead.commentAmount)
  281. let str = `activityMyReadData[${this.data.commentIndex}].commentAmount`;
  282. this.setData({
  283. [str]: res.data.data.userRead.commentAmount
  284. })
  285. })
  286. }
  287. this.setData({
  288. commentShow: false
  289. })
  290. }
  291. },
  292. /**
  293. * 获取评论信息
  294. */
  295. getReply: function (columnId) {
  296. // let columnId = this.data.id;
  297. console.log(123123123, columnId)
  298. // let pageNo = this.data.pageNo;
  299. // let pageSize = this.data.pageSize;
  300. httpRequestApi.getReply(this.uid, columnId, 1, 10).success((res) => {
  301. console.log('reply', res)
  302. const commentList = res.data.data.list;
  303. const commentNum = res.data.data.totalSize;
  304. console.log('评论数量', commentNum)
  305. commentList.forEach((item) => {
  306. const temp = {};
  307. temp.nickName = item.user.wechatName;
  308. temp.avatar = item.user.avatar;
  309. temp.uid = item.user.uid;
  310. temp.text = item.detailDesc;
  311. temp.id = item.id;
  312. temp.replyCount = item.replyCount;
  313. temp.time = formatDate(item.gmtCreated, 3);
  314. temp.likes = item.postsAttributeInfo.favors || 0;
  315. temp.isLike = item.isLike;
  316. temp.replyList = item.replyVOList;
  317. this.data.commentList.push(temp);
  318. });
  319. this.setData({
  320. commentList: this.data.commentList,
  321. commentNum: commentNum
  322. })
  323. });
  324. },
  325. /**
  326. * 发布回复
  327. */
  328. sendReply: function (e) {
  329. console.log('triger', e.detail.content);
  330. let data = {
  331. columnId: this.data.commentId,
  332. colunmNames: 'what',
  333. detailDesc: e.detail.content,
  334. // productId: this.data.productId
  335. }
  336. httpRequestApi.postReply(this.uid, data).success(res => {
  337. console.log(res)
  338. this.setData({
  339. pageNo: 1,
  340. commentList: []
  341. }, () => {
  342. this.getReply(this.data.commentId);
  343. })
  344. });
  345. },
  346. /**
  347. * 点击分享
  348. */
  349. openShare(e) {
  350. this.setData({
  351. shareTitle: e.detail.currentTarget.dataset.title,
  352. shareId: e.detail.currentTarget.dataset.id,
  353. shareImg: e.detail.currentTarget.dataset.shareimg,
  354. goToShare: true
  355. })
  356. },
  357. /**
  358. * 点击活动
  359. */
  360. rule() {
  361. wx.navigateTo({
  362. url: `../rule/rule`
  363. });
  364. },
  365. /**
  366. * 点击攻略
  367. */
  368. strategy() {
  369. wx.navigateTo({
  370. url: `../strategy/strategy`
  371. });
  372. },
  373. /**
  374. * 点击头像
  375. */
  376. headTap(e) {
  377. if (!wx.getStorageSync('user').wechatName) {
  378. wx.navigateTo({
  379. url: `../../pages/login/login`
  380. });
  381. return;
  382. }
  383. let uid = e.target.dataset.uid ? e.target.dataset.uid : e.currentTarget.dataset.uid;
  384. // this.trigger(e, 'headTap')
  385. console.log('点击头像', e)
  386. wx.navigateTo({
  387. url: `../../pages/myworks/myworks?uid=${uid}`,
  388. fail: (err) => {
  389. console.log('跳转错误', err)
  390. wx.navigateTo({
  391. url: `../../../pages/myworks/myworks?uid=${uid}`
  392. });
  393. }
  394. });
  395. },
  396. /**
  397. * 点击关注
  398. */
  399. follow(e) {
  400. const followUid = e.target.dataset.uid ? e.target.dataset.uid : e.currentTarget.dataset.uid;
  401. const uid = wx.getStorageSync('uid');
  402. httpRequestApi.followUser(uid, followUid).success((res) => {
  403. // this.setData({
  404. // isFans: true
  405. // })
  406. wx.showToast({
  407. title: '关注啦',
  408. icon: 'success',
  409. duration: 1000
  410. })
  411. });
  412. httpRequestApi.getHotAmountTop().success(res => {
  413. if (res.data.code === 200) {
  414. const hotAmountTopData = [...res.data.data]
  415. this.setData({
  416. hotAmountTopData
  417. })
  418. }
  419. })
  420. }
  421. })