index.js 11 KB

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