index.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053
  1. //index.js
  2. //获取应用实例
  3. // 获取授权登录
  4. import {
  5. getOpenidSessionKey
  6. } from '../../utils/httpUtil';
  7. // 不用获取授权登录
  8. import {
  9. getOpenidNoLogin
  10. } from '../../utils/httpUtilNoLogin';
  11. import {
  12. formatDate
  13. } from '../../utils/util';
  14. const app = getApp()
  15. import {
  16. hotInit
  17. } from '../../component/hot/hot';
  18. import {
  19. groupInit
  20. } from '../../component/group/group';
  21. import {
  22. myInit
  23. } from '../../component/my/my';
  24. import httpRequestApi from '../../utils/APIClient';
  25. import httputil from '../../utils/httpUtil';
  26. import {
  27. GetQueryString
  28. } from '../../utils/util';
  29. Page({
  30. data: {
  31. tab: [{
  32. name: '我的',
  33. templates: 'my',
  34. }, {
  35. name: '推荐',
  36. templates: 'recommend',
  37. },
  38. {
  39. name: '关注',
  40. templates: 'follow',
  41. },
  42. {
  43. name: '资源',
  44. templates: 'courses',
  45. }
  46. ],
  47. winH: 568,
  48. statusBarHeight: getApp().globalData.statusBarHeight,
  49. myIndex: 0,
  50. followData: [],
  51. recommendPageNo: 1,
  52. recommendPageSize: 3,
  53. recommendTotalNo: 1,
  54. myData: {},
  55. templates: '',
  56. title: 'index中的title',
  57. jurisdictionFlag: true,
  58. hotInput: '12345',
  59. mineSettingInfo: '528',
  60. hide: true,
  61. isIOS: app.globalData.isIOS,
  62. ifHaveMore: true,
  63. indexSignDialog: false,
  64. indexMissionDialog: false,
  65. unfinishedCount: 0,
  66. videoList: [],
  67. nextMargin: '400rpx', // 视频下边距
  68. commentShow: false,
  69. commentList: [],
  70. commentNum: 0,
  71. followPageNo: 1,
  72. followPageSize: 3,
  73. coursePageNo: 1,
  74. coursesData: [],
  75. updateId: 0, // 刷新id
  76. statusbarobj: {
  77. isshowbtn: true, //是否显示按钮
  78. title: "小学语文朗读配音", //标题
  79. },
  80. grade: wx.getStorageSync('grade'),
  81. noMoreWork: false, // 没有更多作品 已经到底了
  82. upgradeHide: false,
  83. gradeActivity: ''
  84. },
  85. jurisdiction: function () {
  86. //隐藏弹框
  87. this.setData({
  88. hide: !this.data.hide
  89. })
  90. //登录页信息
  91. this.updateData(0)
  92. },
  93. // 隐藏升级弹窗
  94. hideUpgrade() {
  95. this.setData({
  96. upgradeHide: true
  97. })
  98. },
  99. //tab点击
  100. switcher: function ({
  101. currentTarget
  102. }) {
  103. if (currentTarget.dataset.index === this.data.myIndex) return;
  104. this.updateData(currentTarget.dataset.index);
  105. },
  106. // 根据index 更新template
  107. updateData: function (index) {
  108. let myIndex = parseInt(index);
  109. this.setData({
  110. myIndex,
  111. noMoreWork: false
  112. });
  113. // 获取推荐列表
  114. if (myIndex == 0) {
  115. this.setData({
  116. recommendPageNo: 1,
  117. videoList: [],
  118. isSwiper: false
  119. }, () => {
  120. // 转为异步
  121. setTimeout(() => {
  122. this.getHotRecommend(this.uid);
  123. }, 0)
  124. })
  125. return;
  126. }
  127. /* 关注和我的需要登陆后查看 */
  128. if (!this.data.isLogin) {
  129. wx.navigateTo({
  130. url: `../../pages/login/login?index=${myIndex}`
  131. });
  132. return;
  133. }
  134. console.log('继续')
  135. // 刷新关注列表
  136. if (myIndex == 1) {
  137. this.setData({
  138. videoList: [],
  139. isSwiper: false,
  140. followPageNo: 1
  141. }, () => {
  142. this.getFollowData()
  143. })
  144. return;
  145. }
  146. // 刷新资源
  147. if (myIndex == 2) {
  148. this.setData({
  149. videoList: [],
  150. coursesData: [],
  151. templates: 'courses',
  152. coursePageNo: 1
  153. }, () => {
  154. this.getCoursesList();
  155. })
  156. return;
  157. }
  158. // 刷新我的
  159. if (myIndex == 3) {
  160. this.setData({
  161. videoList: [],
  162. templates: 'my',
  163. isSwiper: false
  164. }, () => {
  165. myInit(this);
  166. })
  167. return;
  168. }
  169. },
  170. showPage: function () {
  171. let options = this.data.options;
  172. console.log('this.data.workId', this.data.workId)
  173. if (this.data.workId) {
  174. // 需要在推荐第一个上插入一条分享或者刚朗读完数据
  175. let id = this.data.workId;
  176. this.setData({
  177. workId: null,
  178. myIndex: 0,
  179. videoList: [],
  180. isSwiper: false,
  181. recommendTotalNo: 1
  182. })
  183. httpRequestApi.getClassDetail(id).success(res => {
  184. console.log('有一条数据', res)
  185. let tempList = [];
  186. tempList.push(res.data.data);
  187. this.setData({
  188. videoList: [],
  189. isSwiper: false,
  190. recommendTotalNo: 1
  191. }, () => {
  192. this.formatWorksList(tempList, true);
  193. this.getHotRecommend(this.uid);
  194. })
  195. })
  196. } else {
  197. console.log('没有分享')
  198. if (options && options.index) {
  199. this.updateData(options.index)
  200. } else {
  201. console.log('又加载一边')
  202. this.updateData(0)
  203. }
  204. }
  205. setTimeout(() => {
  206. if (wx.getStorageSync('uid')) {
  207. httpRequestApi.userLoginRecord().success(res => {
  208. if (res.data.data && res.data.data.length !== 0) {
  209. // 有数据弹签到
  210. if (this.data.unfinishedCount > 0) {
  211. this.setData({
  212. indexSignDialog: true
  213. })
  214. }
  215. } else {
  216. // 没数据弹任务
  217. let oldDay = wx.getStorageSync('oldDay');
  218. let newDate = new Date();
  219. let day = newDate.getDate() < 10 ? '0' + newDate.getDate() : newDate.getDate()
  220. let timeStep = (newDate.getMonth() + 1).toString() + day
  221. if (oldDay) {
  222. let temp = parseInt(timeStep) - parseInt(oldDay)
  223. if (temp > 0) {
  224. wx.setStorageSync('oldDay', timeStep);
  225. this.setData({
  226. indexMissionDialog: true
  227. })
  228. }
  229. } else {
  230. wx.setStorageSync('oldDay', timeStep);
  231. this.setData({
  232. indexMissionDialog: true
  233. })
  234. }
  235. }
  236. })
  237. }
  238. }, 2800)
  239. },
  240. onLoad: function (options) {
  241. console.log('onload', options);
  242. if (options.scene) {
  243. // this.setData({
  244. // workId: options.scene
  245. // })
  246. let optionsStr = decodeURIComponent(options.scene);
  247. let optionsArr = optionsStr.split('&');
  248. options.readId = optionsArr[0];
  249. options.activity = optionsArr[1];
  250. console.log('整理后options', options)
  251. }
  252. if (options.readId) {
  253. this.setData({
  254. workId: options.readId
  255. })
  256. }
  257. /**
  258. * 活动统计
  259. */
  260. if (options.activity) {
  261. console.log('统计')
  262. httpRequestApi.shareAddHotAmount(options.readId).success(res => {
  263. console.log(res)
  264. })
  265. }
  266. getOpenidNoLogin((res) => {
  267. console.log('getOpenidNoLogin', res)
  268. if (!res.data.data.grade) {
  269. // 没有年级的老用户
  270. if (res.data.data.wechatName) {
  271. this.setData({
  272. isGradeShow: true,
  273. options,
  274. isLogin: true,
  275. oldUser: true
  276. })
  277. return;
  278. }
  279. this.setData({
  280. isGradeShow: true,
  281. options,
  282. isLogin: false,
  283. workId: options.scene ? options.scene : options.readId ? options.readId : undefined
  284. })
  285. return
  286. } else {
  287. if (res.data.data.wechatName) {
  288. this.setData({
  289. isLogin: true
  290. }, () => {
  291. this.showPage();
  292. })
  293. }
  294. }
  295. // 登录或注册完成 展示页面
  296. }, (error) => {
  297. console.log('获取失败', error)
  298. });
  299. this.uid = wx.getStorageSync('uid');
  300. // if (!this.uid || !grade) {
  301. // this.setData({
  302. // isGradeShow: true,
  303. // options
  304. // })
  305. // console.log('没有uid 也不是游客,需要去授权')
  306. // return;
  307. // }
  308. wx.getSystemInfo({
  309. success: (res) => {
  310. console.log('系统', res)
  311. console.log('nextMargin', res.pixelRatio)
  312. console.log('windowHeight', res.windowHeight)
  313. console.log('windowWidth', res.windowWidth)
  314. // let ratio = res.pixelRatio;
  315. let ratio = (res.screenHeight / res.screenWidth) * 1.1;
  316. console.log('比例系数', ratio)
  317. let winH = res.windowHeight * ratio;
  318. let x1 = 465 * ratio;
  319. let x2 = 603 * ratio;
  320. let minusNumber = (winH * x1) / x2;
  321. let nextMargin = parseInt(winH - minusNumber);
  322. app.globalData.nextMargin = nextMargin;
  323. this.setData({
  324. winH: winH,
  325. devicePixelRatio: res.pixelRatio,
  326. nextMargin: nextMargin + 'rpx'
  327. });
  328. }
  329. });
  330. },
  331. onShow: function () {
  332. let grade = wx.getStorageSync('grade');
  333. this.setData({
  334. gradeActivity: grade
  335. })
  336. if (this.data.myIndex === 3) {
  337. this.getUserWorksInfo(1)
  338. }
  339. wx.setNavigationBarTitle({
  340. title: '小学语文朗读配音'
  341. })
  342. if (this.data.fromLoginIndex) {
  343. console.log('页面返回页面返回', this.data.fromLoginIndex)
  344. let index = this.data.fromLoginIndex;
  345. let userInfo = wx.getStorageSync('user');
  346. this.setData({
  347. fromLoginIndex: null,
  348. isLogin: userInfo.wechatName ? true : false
  349. }, () => {
  350. this.updateData(0)
  351. })
  352. }
  353. if (this.data.fromReading) {
  354. this.setData({
  355. fromReading: false
  356. })
  357. this.updateData(3)
  358. }
  359. // 刷新课程资源的收藏数等
  360. if (this.data.myIndex === 2) {
  361. this.refreshCourseAmount()
  362. }
  363. this.setData({
  364. shareImg: '',
  365. shareId: ''
  366. })
  367. },
  368. onHide: function () {
  369. const str = 'hotData.inputFocus'
  370. this.setData({
  371. [str]: false
  372. });
  373. },
  374. /* 两个接口维护同一个数组,手动的结束后添加算法的 */
  375. // 推荐页信息 获取消息和手动推荐内容
  376. // 获取热门作品 算法出来的
  377. getHotRecommend: function () {
  378. let grade = wx.getStorageSync('grade')
  379. let pageNo = this.data.recommendPageNo;
  380. let pageSize = this.data.recommendPageSize;
  381. httpRequestApi.getHotRecommendSecond(grade, pageNo, pageSize).success(res => {
  382. console.log(res)
  383. const recommendRes = res.data.data.list;
  384. if (recommendRes.length <= 0) {
  385. this.setData({
  386. noMoreWork: true
  387. })
  388. return
  389. };
  390. // const recommendWorks = [];
  391. this.formatWorksList(recommendRes);
  392. })
  393. },
  394. // 组装list
  395. formatWorksList(list, notSet) {
  396. // const tempList = [];
  397. console.log('列表长度列表长度', list.length)
  398. if (list.length < 3 || list.length === 0) {
  399. this.setData({
  400. noMoreWork: true
  401. })
  402. }
  403. list.forEach((item, index) => {
  404. /* if (index === list.length - 2 && list.length > 2) {
  405. console.log('设置当前id', item.id)
  406. this.setData({
  407. updateId: item.userRead.id
  408. })
  409. } */
  410. const temp = {};
  411. temp.title = item.userRead.title;
  412. temp.summary = item.userRead.summary;
  413. temp.img = item.userRead.iconImg;
  414. temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
  415. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  416. temp.commentAmount = item.userRead.commentAmount ? item.userRead.commentAmount : 0;
  417. temp.shareAmount = item.userRead.shareAmount;
  418. temp.favoritesAmount = item.userRead.favoritesAmount;
  419. temp.classId = item.userRead.exampleId ? item.userRead.exampleId : 1605097720036046;
  420. temp.time = formatDate(item.userRead.gmtCreated, 3);
  421. temp.avatar = item.user.avatar;
  422. temp.profession = item.user.profession;
  423. temp.uid = item.user.uid;
  424. temp.markPath = item.userRead.markPath ? item.userRead.markPath : item.userRead.videoPath;
  425. temp.url = item.userRead.videoPath ? item.userRead.videoPath : item.userRead.originVideo;
  426. temp.id = item.userRead.id;
  427. temp.type = item.userRead.type;
  428. temp.nickName = item.user.wechatName;
  429. temp.isLike = item.isLike;
  430. temp.isFans = item.isFans ? true : item.user.uid === this.uid ? true : false;
  431. temp.isFavorite = item.isFavorites;
  432. temp.isEfun = item.user.profession === '官方' ? true : false;
  433. temp.hasTag = item.userRead.tag && item.userRead.tag !== 'EXAMPLE' ? true : false;
  434. temp.tagUrl = item.userRead.tag ? item.userRead.tag === 'HOT' ? '../../static/index/hot_tag.png' : '../../static/index/new_tag.png' : ''
  435. temp.status = item.userRead.status;
  436. temp.coverImg = item.userRead.coverImg;
  437. temp.shareImg = item.userRead.shareImg;
  438. temp.grade = item.userRead.grade;
  439. temp.videoShow = false;
  440. item.isActivity && (temp.activity = true);
  441. this.data.videoList.push(temp);
  442. // tempList.push(temp);
  443. });
  444. console.log('当前list', this.data.videoList)
  445. // if (!notSet) {
  446. this.setData({
  447. videoList: this.data.videoList
  448. })
  449. // }
  450. },
  451. // 获取用户信息
  452. getUserWorksInfo: function (flag) {
  453. if (flag) {
  454. httpRequestApi.getUserWorksInfo().success(res => {
  455. const userInfo = this.formatGrade(res.data.data.user);
  456. const str = 'myData.userInfo.wechatName';
  457. const avatarStr = 'myData.userInfo.avatar';
  458. const gradeTextStr = 'myData.userInfo.gradeText';
  459. this.setData({
  460. [str]: userInfo.wechatName,
  461. [avatarStr]: userInfo.avatar,
  462. [gradeTextStr]: userInfo.gradeText
  463. })
  464. })
  465. return;
  466. }
  467. httpRequestApi.getUserWorksInfo().success(res => {
  468. this.data.myData.user = res.data.data;
  469. httpRequestApi.userIntoPage('pages/index/index', '首页我的').success((res) => {})
  470. if (res.data.data.myRead) {
  471. res.data.data.myRead.gmtCreated = formatDate(this.data.myData.user.myRead.gmtCreated, 4)
  472. }
  473. res.data.data.user = this.formatGrade(res.data.data.user);
  474. this.setData({
  475. myData: res.data.data,
  476. ['myData.userInfo']: res.data.data.user
  477. }, () => {
  478. this.getMyRead()
  479. });
  480. }).fail(error => {
  481. console.log(error)
  482. })
  483. },
  484. formatGrade(userInfo) {
  485. switch (userInfo.grade) {
  486. case 'PRESCHOOL':
  487. userInfo.gradeText = '学前班'
  488. break;
  489. case 'PRIMARY_FIRST_GRADE':
  490. userInfo.gradeText = '一年级'
  491. break;
  492. case 'PRIMARY_SECOND_GRADE':
  493. userInfo.gradeText = '二年级'
  494. break;
  495. case 'PRIMARY_THREE_GRADE':
  496. userInfo.gradeText = '三年级'
  497. break;
  498. case 'PRIMARY_SENIOR_GRADE':
  499. userInfo.gradeText = '四年级';
  500. break;
  501. }
  502. return userInfo;
  503. },
  504. videoChange: function (e) {
  505. if (e.detail.activeId === this.data.updateId) {
  506. console.log('应该刷新')
  507. if (this.data.myIndex === 1) {
  508. this.setData({
  509. followPageNo: this.data.followPageNo + 1
  510. }, () => {
  511. this.getFollowData()
  512. })
  513. }
  514. if (this.data.myIndex === 0) {
  515. console.log('首页加载第二页')
  516. this.setData({
  517. recommendPageNo: this.data.recommendPageNo + 1
  518. }, () => {
  519. this.getHotRecommend()
  520. })
  521. }
  522. }
  523. },
  524. // 触底加载
  525. onReachBottom: function () {
  526. if (this.data.myIndex === 2) {
  527. this.setData({
  528. coursePageNo: this.data.coursePageNo + 1
  529. }, () => {
  530. this.getCoursesList()
  531. })
  532. }
  533. if (this.data.myIndex === 1) {
  534. this.setData({
  535. followPageNo: this.data.followPageNo + 1
  536. }, () => {
  537. this.getFollowData()
  538. })
  539. }
  540. if (this.data.myIndex === 0) {
  541. console.log('首页加载第二页')
  542. this.setData({
  543. recommendPageNo: this.data.recommendPageNo + 1
  544. }, () => {
  545. this.getHotRecommend()
  546. })
  547. }
  548. // // 当前在推荐页面 加载推荐
  549. // if (this.data.myIndex === 1) {
  550. // console.log(this.data.recommendPageNo)
  551. // console.log(this.data.recommendTotalNo)
  552. // this.setData({
  553. // recommendPageNo: this.data.recommendPageNo + 1
  554. // })
  555. // if (this.data.recommendPageNo <= this.data.recommendTotalNo) {
  556. // this.getHotRecommendSecond(this.uid, this.data.recommendPageNo, 3);
  557. // } else {
  558. // console.log('没有更多')
  559. // }
  560. // }
  561. },
  562. onPullDownRefresh: function () {
  563. //当前在团购页下拉加载
  564. this.updateData(this.data.myIndex)
  565. wx.showNavigationBarLoading() //在标题栏中显示加载
  566. //模拟加载
  567. setTimeout(function () {
  568. wx.hideNavigationBarLoading() //完成停止加载
  569. wx.stopPullDownRefresh() //停止下拉刷新
  570. }, 1000);
  571. },
  572. goToMessage: function () {
  573. wx.navigateTo({
  574. url: `../../pages/social/insideMessage/insideMessage`
  575. });
  576. const str = 'hotData.unReadMessageNum';
  577. this.setData({
  578. [str]: 0
  579. })
  580. },
  581. toMyCollage: function (e) {
  582. if (app.globalData.isIOS) {
  583. wx.navigateTo({
  584. url: `../../pages/groupPage/my-group/my-group?title=我的助力`
  585. });
  586. } else {
  587. wx.navigateTo({
  588. url: `../../pages/groupPage/my-group/my-group?title=我的拼团`
  589. });
  590. }
  591. },
  592. toMyCourse: function () {
  593. wx.navigateTo({
  594. url: `../../pages/user/mycourse/mycourse?title=我的课程`
  595. });
  596. },
  597. goToFlower: function () {
  598. wx.navigateTo({
  599. url: `../../pages/social/littleFlower/littleFlower`
  600. });
  601. },
  602. signInBtn: function (e) {
  603. this.setData({
  604. indexSignDialog: false
  605. })
  606. console.log(e.detail.formId)
  607. httpRequestApi.postFormId(e.detail.formId).success(res => {
  608. console.log(res)
  609. })
  610. this.goToFlower();
  611. },
  612. missionBtn: function () {
  613. this.setData({
  614. indexMissionDialog: false
  615. })
  616. this.goToFlower();
  617. },
  618. getUserAuth: function () {
  619. httpRequestApi.getUserAuth().success(res => {
  620. console.log(res)
  621. const str = 'myData.isVIP'
  622. if (res.data.data) {
  623. this.setData({
  624. [str]: true
  625. })
  626. } else {
  627. this.setData({
  628. [str]: false
  629. })
  630. }
  631. })
  632. },
  633. delHideMyWork: function () {
  634. this.getMyRead()
  635. },
  636. // 获取我的朗读
  637. getMyRead: function () {
  638. httpRequestApi.myRead().success(res => {
  639. console.log(123123, res)
  640. console.log('mydata', this.data.myData)
  641. const myList = res.data.data;
  642. if (myList.length === 0) {
  643. this.setData({
  644. videoList: []
  645. })
  646. return
  647. }
  648. // this.formatWorksList(myList)
  649. // const recommendWorks = [];
  650. const myWorks = [];
  651. myList.forEach(item => {
  652. const temp = {};
  653. temp.title = item.userRead.title;
  654. temp.summary = item.userRead.summary;
  655. temp.img = item.userRead.iconImg;
  656. temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
  657. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  658. temp.commentAmount = item.userRead.commentAmount ? item.userRead.commentAmount : 0;
  659. temp.shareAmount = item.userRead.shareAmount;
  660. temp.favoritesAmount = item.userRead.favoritesAmount;
  661. temp.classId = item.userRead.exampleId ? item.userRead.exampleId : 1605097720036046;
  662. temp.time = formatDate(item.userRead.gmtCreated, 3);
  663. temp.avatar = item.user.avatar;
  664. temp.profession = item.user.profession;
  665. temp.uid = item.user.uid;
  666. temp.markPath = item.userRead.markPath ? item.userRead.markPath : item.userRead.videoPath;
  667. temp.url = item.userRead.videoPath ? item.userRead.videoPath : item.userRead.originVideo;
  668. temp.id = item.userRead.id;
  669. temp.type = item.userRead.type;
  670. temp.nickName = item.user.wechatName;
  671. temp.isLike = item.isLike;
  672. temp.isFavorite = item.isFavorites;
  673. temp.showMyBtn = true;
  674. temp.nickName = this.data.myData.userInfo.wechatName;
  675. temp.status = item.userRead.status;
  676. temp.ifCheck = item.userRead.status === 'CHECK' ? true : false;
  677. temp.coverImg = item.userRead.coverImg;
  678. temp.grade = item.userRead.grade
  679. temp.isFans = true;
  680. temp.videoShow = false;
  681. temp.shareImg = item.userRead.shareImg;
  682. item.isActivity && (temp.activity = true);
  683. myWorks.push(temp);
  684. });
  685. console.log('myWorks', myWorks)
  686. if (this.data.myIndex === 3) {
  687. this.setData({
  688. videoList: myWorks,
  689. noMoreWork: true
  690. })
  691. }
  692. })
  693. },
  694. // 评论区点击
  695. commentTap: function (e) {
  696. console.log('点击评论区', e)
  697. if (e.target.dataset.type === 'blank') {
  698. if (this.data.commentShow && this.data.commentId) {
  699. httpRequestApi.getClassDetail(this.data.commentId).success(res => {
  700. console.log('评论回显', res.data.data.userRead.commentAmount)
  701. let str = `videoList[${this.data.commentIndex}].commentAmount`;
  702. this.setData({
  703. [str]: res.data.data.userRead.commentAmount
  704. })
  705. })
  706. }
  707. this.setData({
  708. commentShow: false
  709. })
  710. }
  711. },
  712. touchMove: function (e) {
  713. return
  714. },
  715. // 打开评论
  716. openComment: function (e) {
  717. //
  718. console.log('id', e.detail.activeId)
  719. console.log('id', e)
  720. this.setData({
  721. commentShow: !this.data.commentShow,
  722. commentId: e.detail.activeId,
  723. commentIndex: e.detail.activeIndex
  724. // commentList: []
  725. });
  726. // this.getReply(e.detail.activeId);
  727. },
  728. // 获取评论信息
  729. getReply: function (columnId) {
  730. debugger
  731. // let columnId = this.data.id;
  732. console.log(123123123, columnId)
  733. // let pageNo = this.data.pageNo;
  734. // let pageSize = this.data.pageSize;
  735. httpRequestApi.getReply(this.uid, columnId, 1, 10).success((res) => {
  736. console.log('reply', res)
  737. const commentList = res.data.data.list;
  738. const commentNum = res.data.data.totalSize;
  739. console.log('评论数量', commentNum)
  740. commentList.forEach((item) => {
  741. const temp = {};
  742. temp.nickName = item.user.wechatName;
  743. temp.avatar = item.user.avatar;
  744. temp.uid = item.user.uid;
  745. temp.text = item.detailDesc;
  746. temp.id = item.id;
  747. temp.replyCount = item.replyCount;
  748. temp.time = formatDate(item.gmtCreated, 3);
  749. temp.likes = item.postsAttributeInfo.favors || 0;
  750. temp.isLike = item.isLike;
  751. temp.replyList = item.replyVOList;
  752. this.data.commentList.push(temp);
  753. });
  754. this.setData({
  755. commentList: this.data.commentList,
  756. commentNum: commentNum
  757. })
  758. });
  759. },
  760. // 发布回复
  761. sendReply: function (e) {
  762. console.log('triger', e.detail.content);
  763. let data = {
  764. columnId: this.data.commentId,
  765. colunmNames: 'what',
  766. detailDesc: e.detail.content,
  767. // productId: this.data.productId
  768. }
  769. httpRequestApi.postReply(this.uid, data).success(res => {
  770. console.log(res)
  771. this.setData({
  772. pageNo: 1,
  773. commentList: []
  774. }, () => {
  775. this.getReply(this.data.commentId);
  776. })
  777. });
  778. },
  779. gradeTap: function () {
  780. // console.log("组件回调,返回上一页");
  781. this.setData({
  782. isGradeShow: true
  783. })
  784. },
  785. onShareAppMessage: function (res) {
  786. console.log('onShareAppMessage>>>>>>>>>>>>')
  787. console.log('this.data', this.data)
  788. if (res.from === 'button') {
  789. return {
  790. title: '请欣赏我的课文朗读作品,点赞+评论。',
  791. path: `/pages/index/index?readId=${this.data.shareId}&activity=${this.data.ifTapActivity}`,
  792. imageUrl: this.data.shareImg
  793. }
  794. } else {
  795. return {
  796. title: '课文朗读,从未如此有趣。',
  797. path: '/pages/index/index',
  798. }
  799. }
  800. },
  801. openShare: function (e) {
  802. console.log('点击分享', e)
  803. this.setData({
  804. shareTitle: e.detail.currentTarget.dataset.title,
  805. shareId: e.detail.currentTarget.dataset.id,
  806. shareImg: e.detail.currentTarget.dataset.shareimg,
  807. goToShare: true,
  808. ifTapActivity: e.detail.currentTarget.dataset.activity
  809. })
  810. },
  811. // 修改年级
  812. changeGrade: function (e) {
  813. const grade = e.target.dataset.code;
  814. wx.setStorageSync('grade', grade)
  815. this.setData({
  816. isGradeShow: false,
  817. grade
  818. })
  819. if (this.data.oldUser) {
  820. let data = {
  821. grade: e.target.dataset.code
  822. };
  823. httpRequestApi.settingUserInfo(data).success(res => {
  824. })
  825. return;
  826. };
  827. getOpenidNoLogin((res) => {
  828. console.log('getOpenidNoLogin', res)
  829. // 登录或注册完成 展示页面
  830. if (res.data.data.wechatName) {
  831. this.setData({
  832. isLogin: true
  833. })
  834. } else {
  835. this.setData({
  836. isLogin: false
  837. })
  838. }
  839. this.showPage()
  840. }, (error) => {
  841. console.log('获取失败')
  842. wx.setStorageSync('userSourseType', 'normal')
  843. this.setData({
  844. hide: !this.data.hide
  845. })
  846. }, grade);
  847. },
  848. getFollowData: function () {
  849. httpRequestApi.getFollowWorks(this.data.followPageNo, this.data.followPageSize).success(res => {
  850. if (res.data.data.totalSize === 0) {
  851. this.setData({
  852. videoList: [],
  853. noFollow: true
  854. })
  855. console.log('没有关注人或关注的人没有发过作品')
  856. return
  857. } else {
  858. this.setData({
  859. noFollow: false
  860. })
  861. }
  862. console.log('关注列表', res)
  863. const followData = res.data.data.list;
  864. // const videoList = [];
  865. this.formatWorksList(followData);
  866. });
  867. },
  868. // 点击用户头像区域
  869. headTapHandler: function (e) {
  870. console.log('点击头像', e)
  871. let tapId = e.detail.activeId;
  872. // 点击头像既关注 测试
  873. httpRequestApi.followUser(this.uid, tapId).success(res => {
  874. console.log(res)
  875. })
  876. },
  877. getCoursesList: function () {
  878. const grade = wx.getStorageSync('grade');
  879. const data = {
  880. pageNo: this.data.coursePageNo,
  881. pageSize: 6,
  882. grade,
  883. type: 'EXAMPLE'
  884. };
  885. console.log('资源', data)
  886. httpRequestApi.getClassRead(data).success(res => {
  887. console.log('资源', this.data.coursesData)
  888. this.setData({
  889. coursesData: this.data.coursesData.concat(res.data.data.list),
  890. noMoreWork: res.data.data.list.length <= 0 ? true : false
  891. }, () => {
  892. console.log(this.data.coursesData)
  893. })
  894. })
  895. },
  896. goToReading: function (e) {
  897. console.log('去朗读', e)
  898. const id = e.detail.activeId ? e.detail.activeId : e.currentTarget.dataset.id;
  899. const index = e.currentTarget.dataset.index;
  900. this.setData({
  901. goToCoursesId: id,
  902. goToCoursesIndex: index
  903. })
  904. wx.navigateTo({
  905. url: `../../pages/reading/reading?id=${id}`
  906. });
  907. },
  908. refreshCourseAmount() {
  909. console.log(this.data.goToCoursesId)
  910. console.log(this.data.goToCoursesIndex)
  911. if (this.data.goToCoursesId && (this.data.goToCoursesIndex || this.data.goToCoursesIndex === 0)) {
  912. httpRequestApi.getClassDetail(this.data.goToCoursesId).success(res => {
  913. console.log('刷新', res.data.data.userRead)
  914. let likeStr = `coursesData[${this.data.goToCoursesIndex}].userRead.likeAmount`;
  915. let commentStr = `coursesData[${this.data.goToCoursesIndex}].userRead.commentAmount`;
  916. let playStr = `coursesData[${this.data.goToCoursesIndex}].userRead.playAmount`;
  917. let shareStr = `coursesData[${this.data.goToCoursesIndex}].userRead.shareAmount`;
  918. let collectStr = `coursesData[${this.data.goToCoursesIndex}].userRead.collectAmount`;
  919. console.log(1, this.data.coursesData[this.data.goToCoursesIndex].userRead.likeAmount)
  920. console.log(2, res.data.data.userRead.likeAmount)
  921. this.setData({
  922. [likeStr]: res.data.data.userRead.likeAmount,
  923. [commentStr]: res.data.data.userRead.commentAmount,
  924. [playStr]: res.data.data.userRead.playAmount,
  925. [shareStr]: res.data.data.userRead.shareAmount,
  926. [collectStr]: res.data.data.userRead.collectAmount,
  927. }, () => {
  928. console.log(111222333, this.data.coursesData[this.data.goToCoursesIndex])
  929. })
  930. })
  931. }
  932. },
  933. courseCollectTap: function collectClass(e) {
  934. console.log('收藏按钮', e);
  935. const data = {
  936. targetCode: e.target.dataset.id ? e.target.dataset.id : e.currentTarget.dataset.id,
  937. favoritesType: e.target.dataset.type ? e.target.dataset.type : e.currentTarget.dataset.type
  938. }
  939. const index = e.target.dataset.index ? e.target.dataset.index : e.currentTarget.dataset.index;
  940. let str = `coursesData[${index}].isFavorites`
  941. httpRequestApi.collectClass(data).success((res) => {
  942. console.log('this.data.coursesData[index]', this.data.coursesData[index])
  943. this.setData({
  944. [str]: !this.data.coursesData[index].isFavorites
  945. })
  946. });
  947. },
  948. coursesOpenShare: function coursesOpenShare(e) {
  949. const obj = e.currentTarget.dataset
  950. console.log('分享', obj)
  951. console.log('分享', e)
  952. if (1) {
  953. this.shareDialog = this.selectComponent("#share-dialog");
  954. const data = {
  955. avatar: obj.avatar,
  956. author: obj.author,
  957. iconImg: obj.iconImg,
  958. title: obj.title,
  959. path: `pages/index/index`,
  960. scene: obj.id,
  961. productId: 1
  962. // tip: this.data.tip,
  963. }
  964. // console.log(data)
  965. this.setData({
  966. noScroll: 'noScroll',
  967. shareTitle: obj.title,
  968. shareId: obj.id,
  969. shareImg: obj.shareimg
  970. })
  971. this.shareDialog.share(data);
  972. }
  973. },
  974. collectTap: function (e) {
  975. const index = e.detail.index;
  976. let str = `videoList[${index}].isFavorite`;
  977. let str2 = `videoList[${index}].favoritesAmount`;
  978. let favoritesAmount = e.detail.isCollect ? this.data.videoList[index].favoritesAmount + 1 : this.data.videoList[index].favoritesAmount - 1
  979. this.setData({
  980. [str]: e.detail.isCollect,
  981. [str2]: favoritesAmount
  982. })
  983. },
  984. likeTap: function (e) {
  985. console.log('点赞', e)
  986. const index = e.detail.index;
  987. let likeStr = `videoList[${index}].isLike`;
  988. let likeNumStr = `videoList[${index}].likes`;
  989. this.setData({
  990. [likeStr]: true,
  991. [likeNumStr]: this.data.videoList[index].likes + 1
  992. })
  993. // this.flowerAnimationHandler()
  994. },
  995. flowerAnimationHandler: function () {
  996. this.flowerBox = this.selectComponent("#flower-box");
  997. console.log('this.flower', this.flowerBox)
  998. this.flowerBox.comeOut();
  999. },
  1000. addShareAmount: function (e) {
  1001. console.log('+++++1', e)
  1002. let str = `videoList[${e.detail.index}].shareAmount`;
  1003. this.setData({
  1004. [str]: this.data.videoList[e.detail.index].shareAmount + 1
  1005. })
  1006. },
  1007. /**
  1008. * 跳转到活动页
  1009. */
  1010. goToActivity() {
  1011. wx.navigateTo({
  1012. url: `../activity/index/index`
  1013. });
  1014. },
  1015. goToActivityPrice(){
  1016. wx.navigateTo({
  1017. url: `../activity/priceList/priceList`
  1018. });
  1019. }
  1020. })