index.js 12 KB

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