index.js 14 KB

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