index.js 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345
  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. ifHaveMore: true,
  62. indexSignDialog: false,
  63. indexMissionDialog: false,
  64. unfinishedCount: 0,
  65. videoList: [],
  66. nextMargin: '400rpx', // 视频下边距
  67. commentShow: false,
  68. commentList: [],
  69. commentNum: 0,
  70. followPageNo: 1,
  71. followPageSize: 3,
  72. coursePageNo: 1,
  73. coursesData: [],
  74. updateId: 0, // 刷新id
  75. statusbarobj: {
  76. isshowbtn: true, //是否显示按钮
  77. title: "小学语文朗读配音", //标题
  78. },
  79. grade: wx.getStorageSync('grade'),
  80. noMoreWork: false, // 没有更多作品 已经到底了
  81. upgradeHide: true,
  82. gradeActivity: '',
  83. helpPayHide: true,
  84. tipsType: '',
  85. helpPayImg: '',
  86. tipsImg: '',
  87. payPrice: '',
  88. iphoneType: '',
  89. isVip: null,
  90. isIos: null
  91. },
  92. jurisdiction: function () {
  93. //隐藏弹框
  94. this.setData({
  95. hide: !this.data.hide
  96. })
  97. //登录页信息
  98. this.updateData(0)
  99. },
  100. // 隐藏升级弹窗
  101. hideUpgrade() {
  102. this.setData({
  103. upgradeHide: true
  104. })
  105. },
  106. //tab点击
  107. switcher: function ({
  108. currentTarget
  109. }) {
  110. if (currentTarget.dataset.index === this.data.myIndex) return;
  111. this.updateData(currentTarget.dataset.index);
  112. },
  113. // 根据index 更新template
  114. updateData: function (index) {
  115. let myIndex = parseInt(index);
  116. this.setData({
  117. myIndex,
  118. noMoreWork: false
  119. });
  120. // 获取推荐列表
  121. if (myIndex == 0) {
  122. this.setData({
  123. recommendPageNo: 1,
  124. videoList: [],
  125. isSwiper: false
  126. }, () => {
  127. // 转为异步
  128. setTimeout(() => {
  129. this.getHotRecommend(this.uid);
  130. }, 0)
  131. })
  132. return;
  133. }
  134. /* 关注和我的需要登陆后查看 */
  135. if (!this.data.isLogin) {
  136. wx.navigateTo({
  137. url: `../../pages/login/login?index=${myIndex}`
  138. });
  139. return;
  140. }
  141. console.log('继续')
  142. // 刷新关注列表
  143. if (myIndex == 1) {
  144. this.setData({
  145. videoList: [],
  146. isSwiper: false,
  147. followPageNo: 1
  148. }, () => {
  149. this.getFollowData()
  150. })
  151. return;
  152. }
  153. // 刷新资源
  154. if (myIndex == 2) {
  155. this.setData({
  156. videoList: [],
  157. coursesData: [],
  158. templates: 'courses',
  159. coursePageNo: 1
  160. }, () => {
  161. this.getCoursesList();
  162. })
  163. return;
  164. }
  165. // 刷新我的
  166. if (myIndex == 3) {
  167. this.setData({
  168. videoList: [],
  169. templates: 'my',
  170. isSwiper: false
  171. }, () => {
  172. myInit(this);
  173. httpRequestApi.userEvent('MY');
  174. })
  175. return;
  176. }
  177. },
  178. showPage: function () {
  179. let options = this.data.options;
  180. console.log('this.data.workId', this.data.workId)
  181. if (this.data.workId) {
  182. // 需要在推荐第一个上插入一条分享或者刚朗读完数据
  183. let id = this.data.workId;
  184. this.setData({
  185. workId: null,
  186. myIndex: 0,
  187. videoList: [],
  188. isSwiper: false,
  189. recommendTotalNo: 1
  190. })
  191. httpRequestApi.getClassDetail(id).success(res => {
  192. console.log('有一条数据', res)
  193. let tempList = [];
  194. tempList.push(res.data.data);
  195. this.setData({
  196. videoList: [],
  197. isSwiper: false,
  198. recommendTotalNo: 1
  199. }, () => {
  200. this.formatWorksList(tempList, true);
  201. this.getHotRecommend(this.uid);
  202. })
  203. })
  204. } else {
  205. console.log('没有分享')
  206. if (options && options.index) {
  207. this.updateData(options.index)
  208. } else {
  209. console.log('又加载一边')
  210. this.updateData(0)
  211. }
  212. }
  213. setTimeout(() => {
  214. if (wx.getStorageSync('uid')) {
  215. httpRequestApi.userLoginRecord().success(res => {
  216. if (res.data.data && res.data.data.length !== 0) {
  217. // 有数据弹签到
  218. if (this.data.unfinishedCount > 0) {
  219. this.setData({
  220. indexSignDialog: true
  221. })
  222. }
  223. } else {
  224. // 没数据弹任务
  225. let oldDay = wx.getStorageSync('oldDay');
  226. let newDate = new Date();
  227. let day = newDate.getDate() < 10 ? '0' + newDate.getDate() : newDate.getDate()
  228. let timeStep = (newDate.getMonth() + 1).toString() + day
  229. if (oldDay) {
  230. let temp = parseInt(timeStep) - parseInt(oldDay)
  231. if (temp > 0) {
  232. wx.setStorageSync('oldDay', timeStep);
  233. this.setData({
  234. indexMissionDialog: true
  235. })
  236. }
  237. } else {
  238. wx.setStorageSync('oldDay', timeStep);
  239. this.setData({
  240. indexMissionDialog: true
  241. })
  242. }
  243. }
  244. })
  245. }
  246. }, 2800)
  247. },
  248. onLoad: function (options) {
  249. this.setData({
  250. isIos: app.globalData.isIOS
  251. })
  252. console.log('onload', options);
  253. if (options.scene) {
  254. // this.setData({
  255. // workId: options.scene
  256. // })
  257. let optionsStr = decodeURIComponent(options.scene);
  258. let optionsArr = optionsStr.split('&');
  259. // 暂时这样写
  260. if (optionsArr[0].split("=")[0] === "type") {
  261. console.log('我是团购分享')
  262. options.type = optionsArr[0].split("=")[1];
  263. options.sid = optionsArr[1].split("=")[1];
  264. } else {
  265. options.readId = optionsArr[0];
  266. options.activity = optionsArr[1];
  267. }
  268. console.log('整理后options', options)
  269. }
  270. if (options.readId) {
  271. this.setData({
  272. workId: options.readId
  273. })
  274. }
  275. /**
  276. * 活动统计
  277. */
  278. if (options.activity) {
  279. console.log('统计')
  280. httpRequestApi.shareAddHotAmount(options.readId).success(res => {
  281. console.log(res)
  282. })
  283. }
  284. /**团购弹窗时间紧逻辑越写越乱功能越加越多 */
  285. this.setData({
  286. iphoneType: options.type || ''
  287. })
  288. getOpenidNoLogin((res) => {
  289. console.log('getOpenidNoLogin', res)
  290. /**获取权限和订单信息 */
  291. // 获取商品信息
  292. httpRequestApi.getProductActivity().success(res => {
  293. wx.setStorageSync('price', res.data.data.price / 100)
  294. wx.setStorageSync('productId', res.data.data.id)
  295. if (options.type && options.type === 'iphone') {
  296. this.setData({
  297. payPrice: res.data.data.price / 100
  298. })
  299. }
  300. }).fail(error => {
  301. console.log(error)
  302. })
  303. // 获取用户权限
  304. this.getHelpAuth()
  305. if (!res.data.data.grade) {
  306. // 没有年级的老用户
  307. if (res.data.data.wechatName) {
  308. this.setData({
  309. isGradeShow: true,
  310. options,
  311. isLogin: true,
  312. oldUser: true
  313. })
  314. return;
  315. }
  316. this.setData({
  317. isGradeShow: true,
  318. options,
  319. isLogin: false,
  320. workId: options.scene ? options.scene : options.readId ? options.readId : undefined
  321. })
  322. return
  323. } else {
  324. if (res.data.data.wechatName) {
  325. this.setData({
  326. isLogin: true
  327. }, () => {
  328. this.showPage();
  329. })
  330. } else {
  331. console.log('游客未登录有年纪')
  332. this.showPage();
  333. }
  334. }
  335. // 登录或注册完成 展示页面
  336. }, (error) => {
  337. console.log('获取失败', error)
  338. });
  339. this.uid = wx.getStorageSync('uid');
  340. if (options.sid) {
  341. httpRequestApi.getUserRec(options.sid).success(res => {
  342. options.uid = res.data.data;
  343. this.shareGetPage(options)
  344. })
  345. } else {
  346. this.shareGetPage(options)
  347. }
  348. // if (!this.uid || !grade) {
  349. // this.setData({
  350. // isGradeShow: true,
  351. // options
  352. // })
  353. // console.log('没有uid 也不是游客,需要去授权')
  354. // return;
  355. // }
  356. wx.getSystemInfo({
  357. success: (res) => {
  358. console.log('系统', res)
  359. console.log('nextMargin', res.pixelRatio)
  360. console.log('windowHeight', res.windowHeight)
  361. console.log('windowWidth', res.windowWidth)
  362. // let ratio = res.pixelRatio;
  363. let ratio = (res.screenHeight / res.screenWidth) * 1.1;
  364. console.log('比例系数', ratio)
  365. let winH = res.windowHeight * ratio;
  366. let x1 = 465 * ratio;
  367. let x2 = 603 * ratio;
  368. let minusNumber = (winH * x1) / x2;
  369. let nextMargin = parseInt(winH - minusNumber);
  370. app.globalData.nextMargin = nextMargin;
  371. this.setData({
  372. winH: winH,
  373. devicePixelRatio: res.pixelRatio,
  374. nextMargin: nextMargin + 'rpx'
  375. });
  376. }
  377. });
  378. },
  379. // 封装分享方法之后跳到页面方法
  380. shareGetPage(options) {
  381. console.log(this.uid, options.uid, this.uid !== options.uid)
  382. if (options.type && options.type === 'iphone' && !app.globalData.isIOS && this.uid !== options.uid) {
  383. this.setData({
  384. helpPayHide: false,
  385. tipsType: 'helpPay',
  386. helpPayImg: 'http://reader-wx.ai160.com/images/reader/pay/buy.png',
  387. })
  388. }
  389. if (options.type && options.type === 'ios' && this.uid !== options.uid) {
  390. this.setData({
  391. helpPayHide: false,
  392. tipsType: 'helpPay',
  393. helpPayImg: 'http://reader-wx.ai160.com/images/reader/pay/help.png',
  394. })
  395. console.log(options.uid)
  396. }
  397. const recOsType = options.type === 'iphone' ? 'ANDROID' : (options.type === 'ios' && 'IOS');
  398. if (options.type && options.uid) {
  399. httpRequestApi.settingUserInfo({
  400. rec_uid: options.uid,
  401. recOsType,
  402. }).success(res => {
  403. console.log(res)
  404. })
  405. }
  406. },
  407. onShow: function () {
  408. let grade = wx.getStorageSync('grade');
  409. this.setData({
  410. gradeActivity: grade
  411. })
  412. if (this.data.myIndex === 3) {
  413. this.getUserWorksInfo(1)
  414. this.getHelpAuth()
  415. }
  416. wx.setNavigationBarTitle({
  417. title: '小学语文朗读配音'
  418. })
  419. console.log('页面返回页面返回', this.data.fromLoginIndex)
  420. if (this.data.fromLoginIndex || this.data.fromLoginIndex == 0) {
  421. console.log('页面返回页面返回', this.data.fromLoginIndex)
  422. let index = this.data.fromLoginIndex;
  423. let userInfo = wx.getStorageSync('user');
  424. this.setData({
  425. fromLoginIndex: null,
  426. isLogin: userInfo.wechatName ? true : false
  427. }, () => {
  428. this.updateData(index)
  429. })
  430. }
  431. if (this.data.fromReading) {
  432. this.setData({
  433. fromReading: false
  434. })
  435. this.updateData(3)
  436. }
  437. // 刷新课程资源的收藏数等
  438. if (this.data.myIndex === 2) {
  439. this.refreshCourseAmount()
  440. }
  441. this.setData({
  442. shareImg: '',
  443. shareId: ''
  444. })
  445. },
  446. onHide: function () {
  447. const str = 'hotData.inputFocus'
  448. this.setData({
  449. [str]: false
  450. });
  451. },
  452. /* 两个接口维护同一个数组,手动的结束后添加算法的 */
  453. // 推荐页信息 获取消息和手动推荐内容
  454. // 获取热门作品 算法出来的
  455. getHotRecommend: function () {
  456. let grade = wx.getStorageSync('grade')
  457. let pageNo = this.data.recommendPageNo;
  458. let pageSize = this.data.recommendPageSize;
  459. httpRequestApi.getHotRecommendSecond(grade, pageNo, pageSize).success(res => {
  460. console.log(res)
  461. const recommendRes = res.data.data.list;
  462. if (recommendRes.length <= 0) {
  463. this.setData({
  464. noMoreWork: true
  465. })
  466. return
  467. };
  468. // const recommendWorks = [];
  469. this.formatWorksList(recommendRes);
  470. });
  471. httpRequestApi.userEvent('RECOMMEND');
  472. },
  473. // 组装list
  474. formatWorksList(list, notSet) {
  475. // const tempList = [];
  476. console.log('列表长度列表长度', list.length)
  477. if (list.length < 3 || list.length === 0) {
  478. this.setData({
  479. noMoreWork: true
  480. })
  481. }
  482. list.forEach((item, index) => {
  483. /* if (index === list.length - 2 && list.length > 2) {
  484. console.log('设置当前id', item.id)
  485. this.setData({
  486. updateId: item.userRead.id
  487. })
  488. } */
  489. const temp = {};
  490. temp.title = item.userRead.title;
  491. temp.summary = item.userRead.summary;
  492. temp.img = item.userRead.iconImg;
  493. temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
  494. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  495. temp.commentAmount = item.userRead.commentAmount ? item.userRead.commentAmount : 0;
  496. temp.shareAmount = item.userRead.shareAmount;
  497. temp.favoritesAmount = item.userRead.favoritesAmount;
  498. temp.classId = item.userRead.exampleId ? item.userRead.exampleId : 1605097720036046;
  499. temp.time = formatDate(item.userRead.gmtCreated, 3);
  500. temp.avatar = item.user.avatar;
  501. temp.profession = item.user.profession;
  502. temp.uid = item.user.uid;
  503. temp.markPath = item.userRead.markPath ? item.userRead.markPath : item.userRead.videoPath;
  504. temp.url = item.userRead.videoPath ? item.userRead.videoPath : item.userRead.originVideo;
  505. temp.id = item.userRead.id;
  506. temp.type = item.userRead.type;
  507. temp.nickName = item.user.wechatName;
  508. temp.isLike = item.isLike;
  509. temp.isFans = item.isFans ? true : item.user.uid === this.uid ? true : false;
  510. temp.isFavorite = item.isFavorites;
  511. temp.isEfun = item.user.profession === '官方' ? true : false;
  512. temp.hasTag = item.userRead.tag && item.userRead.tag !== 'EXAMPLE' ? true : false;
  513. temp.tagUrl = item.userRead.tag ? item.userRead.tag === 'HOT' ? '../../static/index/hot_tag.png' : '../../static/index/new_tag.png' : ''
  514. temp.status = item.userRead.status;
  515. temp.coverImg = item.userRead.coverImg;
  516. temp.shareImg = item.userRead.shareImg;
  517. temp.grade = item.userRead.grade;
  518. temp.videoShow = false;
  519. item.isActivity && (temp.activity = true);
  520. this.data.videoList.push(temp);
  521. // tempList.push(temp);
  522. });
  523. console.log('当前list', this.data.videoList)
  524. // if (!notSet) {
  525. this.setData({
  526. videoList: this.data.videoList
  527. })
  528. // }
  529. },
  530. // 获取用户信息
  531. getUserWorksInfo: function (flag) {
  532. if (flag) {
  533. httpRequestApi.getUserWorksInfo().success(res => {
  534. const userInfo = this.formatGrade(res.data.data.user);
  535. const str = 'myData.userInfo.wechatName';
  536. const avatarStr = 'myData.userInfo.avatar';
  537. const gradeTextStr = 'myData.userInfo.gradeText';
  538. this.setData({
  539. [str]: userInfo.wechatName,
  540. [avatarStr]: userInfo.avatar,
  541. [gradeTextStr]: userInfo.gradeText
  542. })
  543. })
  544. return;
  545. }
  546. httpRequestApi.getUserWorksInfo().success(res => {
  547. this.data.myData.user = res.data.data;
  548. httpRequestApi.userIntoPage('pages/index/index', '首页我的').success((res) => {})
  549. if (res.data.data.myRead) {
  550. res.data.data.myRead.gmtCreated = formatDate(this.data.myData.user.myRead.gmtCreated, 4)
  551. }
  552. res.data.data.user = this.formatGrade(res.data.data.user);
  553. this.setData({
  554. // myData: res.data.data,
  555. ['myData.user']: res.data.data,
  556. ['myData.userInfo']: res.data.data.user,
  557. ['myData.isIOS']: app.globalData.isIOS
  558. }, () => {
  559. this.getMyRead()
  560. });
  561. }).fail(error => {
  562. console.log(error)
  563. })
  564. },
  565. formatGrade(userInfo) {
  566. switch (userInfo.grade) {
  567. case 'PRESCHOOL':
  568. userInfo.gradeText = '学前班'
  569. break;
  570. case 'PRIMARY_FIRST_GRADE':
  571. userInfo.gradeText = '一年级'
  572. break;
  573. case 'PRIMARY_SECOND_GRADE':
  574. userInfo.gradeText = '二年级'
  575. break;
  576. case 'PRIMARY_THREE_GRADE':
  577. userInfo.gradeText = '三年级'
  578. break;
  579. case 'PRIMARY_SENIOR_GRADE':
  580. userInfo.gradeText = '四年级';
  581. break;
  582. }
  583. return userInfo;
  584. },
  585. videoChange: function (e) {
  586. if (e.detail.activeId === this.data.updateId) {
  587. console.log('应该刷新')
  588. if (this.data.myIndex === 1) {
  589. this.setData({
  590. followPageNo: this.data.followPageNo + 1
  591. }, () => {
  592. this.getFollowData()
  593. })
  594. }
  595. if (this.data.myIndex === 0) {
  596. console.log('首页加载第二页')
  597. this.setData({
  598. recommendPageNo: this.data.recommendPageNo + 1
  599. }, () => {
  600. this.getHotRecommend()
  601. })
  602. }
  603. }
  604. },
  605. // 触底加载
  606. onReachBottom: function () {
  607. if (this.data.myIndex === 2) {
  608. this.setData({
  609. coursePageNo: this.data.coursePageNo + 1
  610. }, () => {
  611. this.getCoursesList()
  612. })
  613. }
  614. if (this.data.myIndex === 1) {
  615. this.setData({
  616. followPageNo: this.data.followPageNo + 1
  617. }, () => {
  618. this.getFollowData()
  619. })
  620. }
  621. if (this.data.myIndex === 0) {
  622. console.log('首页加载第二页')
  623. this.setData({
  624. recommendPageNo: this.data.recommendPageNo + 1
  625. }, () => {
  626. this.getHotRecommend()
  627. })
  628. }
  629. // // 当前在推荐页面 加载推荐
  630. // if (this.data.myIndex === 1) {
  631. // console.log(this.data.recommendPageNo)
  632. // console.log(this.data.recommendTotalNo)
  633. // this.setData({
  634. // recommendPageNo: this.data.recommendPageNo + 1
  635. // })
  636. // if (this.data.recommendPageNo <= this.data.recommendTotalNo) {
  637. // this.getHotRecommendSecond(this.uid, this.data.recommendPageNo, 3);
  638. // } else {
  639. // console.log('没有更多')
  640. // }
  641. // }
  642. },
  643. onPullDownRefresh: function () {
  644. //当前在团购页下拉加载
  645. this.updateData(this.data.myIndex)
  646. wx.showNavigationBarLoading() //在标题栏中显示加载
  647. //模拟加载
  648. setTimeout(function () {
  649. wx.hideNavigationBarLoading() //完成停止加载
  650. wx.stopPullDownRefresh() //停止下拉刷新
  651. }, 1000);
  652. },
  653. goToMessage: function () {
  654. wx.navigateTo({
  655. url: `../../pages/social/insideMessage/insideMessage`
  656. });
  657. const str = 'hotData.unReadMessageNum';
  658. httpRequestApi.userEvent('MESSAGE');
  659. this.setData({
  660. [str]: 0
  661. })
  662. },
  663. goToService: function () {
  664. httpRequestApi.userEvent('SERVICE');
  665. },
  666. toMyCollage: function (e) {
  667. if (app.globalData.isIOS) {
  668. wx.navigateTo({
  669. url: `../../pages/groupPage/my-group/my-group?title=我的助力`
  670. });
  671. } else {
  672. wx.navigateTo({
  673. url: `../../pages/groupPage/my-group/my-group?title=我的拼团`
  674. });
  675. }
  676. },
  677. toMyCourse: function () {
  678. wx.navigateTo({
  679. url: `../../pages/user/mycourse/mycourse?title=我的课程`
  680. });
  681. },
  682. goToFlower: function () {
  683. wx.navigateTo({
  684. url: `../../pages/social/littleFlower/littleFlower`
  685. });
  686. httpRequestApi.userEvent('INTEGRAL');
  687. },
  688. signInBtn: function (e) {
  689. this.setData({
  690. indexSignDialog: false
  691. })
  692. console.log(e.detail.formId)
  693. httpRequestApi.postFormId(e.detail.formId).success(res => {
  694. console.log(res)
  695. })
  696. this.goToFlower();
  697. },
  698. missionBtn: function () {
  699. this.setData({
  700. indexMissionDialog: false
  701. })
  702. this.goToFlower();
  703. },
  704. getUserAuth: function () {
  705. httpRequestApi.getUserAuth().success(res => {
  706. console.log(res)
  707. const str = 'myData.isVIP'
  708. if (res.data.data) {
  709. this.setData({
  710. [str]: true
  711. })
  712. } else {
  713. this.setData({
  714. [str]: false
  715. })
  716. }
  717. })
  718. },
  719. delHideMyWork: function () {
  720. this.getMyRead()
  721. },
  722. // 获取我的朗读
  723. getMyRead: function () {
  724. httpRequestApi.myRead().success(res => {
  725. console.log(123123, res)
  726. console.log('mydata', this.data.myData)
  727. const myList = res.data.data;
  728. if (myList.length === 0) {
  729. this.setData({
  730. videoList: []
  731. })
  732. return
  733. }
  734. // this.formatWorksList(myList)
  735. // const recommendWorks = [];
  736. const myWorks = [];
  737. myList.forEach(item => {
  738. const temp = {};
  739. temp.title = item.userRead.title;
  740. temp.summary = item.userRead.summary;
  741. temp.img = item.userRead.iconImg;
  742. temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
  743. temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
  744. temp.commentAmount = item.userRead.commentAmount ? item.userRead.commentAmount : 0;
  745. temp.shareAmount = item.userRead.shareAmount;
  746. temp.favoritesAmount = item.userRead.favoritesAmount;
  747. temp.classId = item.userRead.exampleId ? item.userRead.exampleId : 1605097720036046;
  748. temp.time = formatDate(item.userRead.gmtCreated, 3);
  749. temp.avatar = item.user.avatar;
  750. temp.profession = item.user.profession;
  751. temp.uid = item.user.uid;
  752. temp.markPath = item.userRead.markPath ? item.userRead.markPath : item.userRead.videoPath;
  753. temp.url = item.userRead.videoPath ? item.userRead.videoPath : item.userRead.originVideo;
  754. temp.id = item.userRead.id;
  755. temp.type = item.userRead.type;
  756. temp.nickName = item.user.wechatName;
  757. temp.isLike = item.isLike;
  758. temp.isFavorite = item.isFavorites;
  759. temp.showMyBtn = true;
  760. temp.nickName = this.data.myData.userInfo.wechatName;
  761. temp.status = item.userRead.status;
  762. temp.ifCheck = item.userRead.status === 'CHECK' ? true : false;
  763. temp.coverImg = item.userRead.coverImg;
  764. temp.grade = item.userRead.grade
  765. temp.isFans = true;
  766. temp.videoShow = false;
  767. temp.shareImg = item.userRead.shareImg;
  768. item.isActivity && (temp.activity = true);
  769. myWorks.push(temp);
  770. });
  771. console.log('myWorks', myWorks)
  772. if (this.data.myIndex === 3) {
  773. this.setData({
  774. videoList: myWorks,
  775. noMoreWork: true
  776. })
  777. }
  778. })
  779. },
  780. // 评论区点击
  781. commentTap: function (e) {
  782. console.log('点击评论区', e)
  783. if (e.target.dataset.type === 'blank') {
  784. if (this.data.commentShow && this.data.commentId) {
  785. httpRequestApi.getClassDetail(this.data.commentId).success(res => {
  786. console.log('评论回显', res.data.data.userRead.commentAmount)
  787. let str = `videoList[${this.data.commentIndex}].commentAmount`;
  788. this.setData({
  789. [str]: res.data.data.userRead.commentAmount
  790. })
  791. })
  792. }
  793. this.setData({
  794. commentShow: false
  795. })
  796. }
  797. },
  798. touchMove: function (e) {
  799. return
  800. },
  801. // 打开评论
  802. openComment: function (e) {
  803. //
  804. console.log('id', e.detail.activeId)
  805. console.log('id', e)
  806. this.setData({
  807. commentShow: !this.data.commentShow,
  808. commentId: e.detail.activeId,
  809. commentIndex: e.detail.activeIndex
  810. // commentList: []
  811. });
  812. // this.getReply(e.detail.activeId);
  813. },
  814. // 获取评论信息
  815. getReply: function (columnId) {
  816. debugger
  817. // let columnId = this.data.id;
  818. console.log(123123123, columnId)
  819. // let pageNo = this.data.pageNo;
  820. // let pageSize = this.data.pageSize;
  821. httpRequestApi.getReply(this.uid, columnId, 1, 10).success((res) => {
  822. console.log('reply', res)
  823. const commentList = res.data.data.list;
  824. const commentNum = res.data.data.totalSize;
  825. console.log('评论数量', commentNum)
  826. commentList.forEach((item) => {
  827. const temp = {};
  828. temp.nickName = item.user.wechatName;
  829. temp.avatar = item.user.avatar;
  830. temp.uid = item.user.uid;
  831. temp.text = item.detailDesc;
  832. temp.id = item.id;
  833. temp.replyCount = item.replyCount;
  834. temp.time = formatDate(item.gmtCreated, 3);
  835. temp.likes = item.postsAttributeInfo.favors || 0;
  836. temp.isLike = item.isLike;
  837. temp.replyList = item.replyVOList;
  838. this.data.commentList.push(temp);
  839. });
  840. this.setData({
  841. commentList: this.data.commentList,
  842. commentNum: commentNum
  843. })
  844. });
  845. },
  846. // 发布回复
  847. sendReply: function (e) {
  848. console.log('triger', e.detail.content);
  849. let data = {
  850. columnId: this.data.commentId,
  851. colunmNames: 'what',
  852. detailDesc: e.detail.content,
  853. // productId: this.data.productId
  854. }
  855. httpRequestApi.postReply(this.uid, data).success(res => {
  856. console.log(res)
  857. this.setData({
  858. pageNo: 1,
  859. commentList: []
  860. }, () => {
  861. this.getReply(this.data.commentId);
  862. })
  863. });
  864. },
  865. gradeTap: function () {
  866. // console.log("组件回调,返回上一页");
  867. this.setData({
  868. isGradeShow: true
  869. })
  870. },
  871. onShareAppMessage: function (res) {
  872. console.log('onShareAppMessage>>>>>>>>>>>>')
  873. console.log('this.data', this.data)
  874. if (res.from === 'button') {
  875. return {
  876. title: '请欣赏我的课文朗读作品,点赞+评论。',
  877. path: `/pages/index/index?readId=${this.data.shareId}&activity=${this.data.ifTapActivity}`,
  878. imageUrl: this.data.shareImg
  879. }
  880. } else {
  881. return {
  882. title: '课文朗读,从未如此有趣。',
  883. path: '/pages/index/index',
  884. }
  885. }
  886. },
  887. openShare: function (e) {
  888. console.log('点击分享', e)
  889. this.setData({
  890. shareTitle: e.detail.currentTarget.dataset.title,
  891. shareId: e.detail.currentTarget.dataset.id,
  892. shareImg: e.detail.currentTarget.dataset.shareimg,
  893. goToShare: true,
  894. ifTapActivity: e.detail.currentTarget.dataset.activity
  895. })
  896. },
  897. // 修改年级
  898. changeGrade: function (e) {
  899. const grade = e.target.dataset.code;
  900. wx.setStorageSync('grade', grade)
  901. this.setData({
  902. isGradeShow: false,
  903. grade
  904. })
  905. if (this.data.oldUser) {
  906. let data = {
  907. grade: e.target.dataset.code
  908. };
  909. httpRequestApi.settingUserInfo(data).success(res => {
  910. })
  911. return;
  912. };
  913. getOpenidNoLogin((res) => {
  914. console.log('getOpenidNoLogin', res)
  915. // 登录或注册完成 展示页面
  916. if (res.data.data.wechatName) {
  917. this.setData({
  918. isLogin: true
  919. })
  920. } else {
  921. this.setData({
  922. isLogin: false
  923. })
  924. }
  925. this.showPage()
  926. }, (error) => {
  927. console.log('获取失败')
  928. wx.setStorageSync('userSourseType', 'normal')
  929. this.setData({
  930. hide: !this.data.hide
  931. })
  932. }, grade);
  933. },
  934. getFollowData: function () {
  935. httpRequestApi.getFollowWorks(this.data.followPageNo, this.data.followPageSize).success(res => {
  936. if (res.data.data.totalSize === 0) {
  937. this.setData({
  938. videoList: [],
  939. noFollow: true
  940. })
  941. console.log('没有关注人或关注的人没有发过作品')
  942. return
  943. } else {
  944. this.setData({
  945. noFollow: false
  946. })
  947. }
  948. console.log('关注列表', res)
  949. const followData = res.data.data.list;
  950. // const videoList = [];
  951. this.formatWorksList(followData);
  952. });
  953. httpRequestApi.userEvent('SUBSCRIBE');
  954. },
  955. // 点击用户头像区域
  956. headTapHandler: function (e) {
  957. console.log('点击头像', e)
  958. let tapId = e.detail.activeId;
  959. // 点击头像既关注 测试
  960. httpRequestApi.followUser(this.uid, tapId).success(res => {
  961. console.log(res)
  962. })
  963. },
  964. getCoursesList: function () {
  965. const grade = wx.getStorageSync('grade');
  966. const data = {
  967. pageNo: this.data.coursePageNo,
  968. pageSize: 6,
  969. grade,
  970. type: 'EXAMPLE'
  971. };
  972. console.log('资源', data)
  973. httpRequestApi.getClassRead(data).success(res => {
  974. console.log('资源', this.data.coursesData)
  975. this.setData({
  976. coursesData: this.data.coursesData.concat(res.data.data.list),
  977. noMoreWork: res.data.data.list.length <= 0 ? true : false
  978. }, () => {
  979. console.log(this.data.coursesData)
  980. })
  981. })
  982. httpRequestApi.userEvent('RESOURCES');
  983. },
  984. goToReading: function (e) {
  985. console.log('去朗读', e)
  986. const id = e.detail.activeId ? e.detail.activeId : e.currentTarget.dataset.id;
  987. const index = e.currentTarget.dataset.index;
  988. this.setData({
  989. goToCoursesId: id,
  990. goToCoursesIndex: index
  991. })
  992. wx.navigateTo({
  993. url: `../../pages/reading/reading?id=${id}`
  994. });
  995. httpRequestApi.userEvent('REC_READ');
  996. },
  997. refreshCourseAmount() {
  998. console.log(this.data.goToCoursesId)
  999. console.log(this.data.goToCoursesIndex)
  1000. if (this.data.goToCoursesId && (this.data.goToCoursesIndex || this.data.goToCoursesIndex === 0)) {
  1001. httpRequestApi.getClassDetail(this.data.goToCoursesId).success(res => {
  1002. console.log('刷新', res.data.data.userRead)
  1003. let likeStr = `coursesData[${this.data.goToCoursesIndex}].userRead.likeAmount`;
  1004. let commentStr = `coursesData[${this.data.goToCoursesIndex}].userRead.commentAmount`;
  1005. let playStr = `coursesData[${this.data.goToCoursesIndex}].userRead.playAmount`;
  1006. let shareStr = `coursesData[${this.data.goToCoursesIndex}].userRead.shareAmount`;
  1007. let collectStr = `coursesData[${this.data.goToCoursesIndex}].userRead.collectAmount`;
  1008. console.log(1, this.data.coursesData[this.data.goToCoursesIndex].userRead.likeAmount)
  1009. console.log(2, res.data.data.userRead.likeAmount)
  1010. this.setData({
  1011. [likeStr]: res.data.data.userRead.likeAmount,
  1012. [commentStr]: res.data.data.userRead.commentAmount,
  1013. [playStr]: res.data.data.userRead.playAmount,
  1014. [shareStr]: res.data.data.userRead.shareAmount,
  1015. [collectStr]: res.data.data.userRead.collectAmount,
  1016. }, () => {
  1017. console.log(111222333, this.data.coursesData[this.data.goToCoursesIndex])
  1018. })
  1019. })
  1020. }
  1021. },
  1022. courseCollectTap: function collectClass(e) {
  1023. console.log('收藏按钮', e);
  1024. const data = {
  1025. targetCode: e.target.dataset.id ? e.target.dataset.id : e.currentTarget.dataset.id,
  1026. favoritesType: e.target.dataset.type ? e.target.dataset.type : e.currentTarget.dataset.type
  1027. }
  1028. const index = e.target.dataset.index ? e.target.dataset.index : e.currentTarget.dataset.index;
  1029. let str = `coursesData[${index}].isFavorites`
  1030. httpRequestApi.collectClass(data).success((res) => {
  1031. console.log('this.data.coursesData[index]', this.data.coursesData[index])
  1032. this.setData({
  1033. [str]: !this.data.coursesData[index].isFavorites
  1034. })
  1035. });
  1036. },
  1037. coursesOpenShare: function coursesOpenShare(e) {
  1038. const obj = e.currentTarget.dataset
  1039. console.log('分享', obj)
  1040. console.log('分享', e)
  1041. if (1) {
  1042. this.shareDialog = this.selectComponent("#share-dialog");
  1043. const data = {
  1044. avatar: obj.avatar,
  1045. author: obj.author,
  1046. iconImg: obj.iconImg,
  1047. title: obj.title,
  1048. path: `pages/index/index`,
  1049. scene: obj.id,
  1050. productId: 1
  1051. // tip: this.data.tip,
  1052. }
  1053. // console.log(data)
  1054. this.setData({
  1055. noScroll: 'noScroll',
  1056. shareTitle: obj.title,
  1057. shareId: obj.id,
  1058. shareImg: obj.shareimg
  1059. })
  1060. this.shareDialog.share(data);
  1061. }
  1062. },
  1063. collectTap: function (e) {
  1064. const index = e.detail.index;
  1065. let str = `videoList[${index}].isFavorite`;
  1066. let str2 = `videoList[${index}].favoritesAmount`;
  1067. let favoritesAmount = e.detail.isCollect ? this.data.videoList[index].favoritesAmount + 1 : this.data.videoList[index].favoritesAmount - 1
  1068. this.setData({
  1069. [str]: e.detail.isCollect,
  1070. [str2]: favoritesAmount
  1071. })
  1072. },
  1073. likeTap: function (e) {
  1074. console.log('点赞', e)
  1075. const index = e.detail.index;
  1076. let likeStr = `videoList[${index}].isLike`;
  1077. let likeNumStr = `videoList[${index}].likes`;
  1078. this.setData({
  1079. [likeStr]: true,
  1080. [likeNumStr]: this.data.videoList[index].likes + 1
  1081. })
  1082. // this.flowerAnimationHandler()
  1083. },
  1084. flowerAnimationHandler: function () {
  1085. this.flowerBox = this.selectComponent("#flower-box");
  1086. console.log('this.flower', this.flowerBox)
  1087. this.flowerBox.comeOut();
  1088. },
  1089. addShareAmount: function (e) {
  1090. console.log('+++++1', e)
  1091. let str = `videoList[${e.detail.index}].shareAmount`;
  1092. this.setData({
  1093. [str]: this.data.videoList[e.detail.index].shareAmount + 1
  1094. })
  1095. },
  1096. /**
  1097. * 跳转到活动页
  1098. */
  1099. goToActivity() {
  1100. httpRequestApi.postActEvent('BANNER').success(res => {
  1101. console.log('活动banner', res)
  1102. })
  1103. // wx.navigateTo({
  1104. // url: `../activity/index/index`
  1105. // // url: `../activity/rule/rule`
  1106. // });
  1107. wx.navigateTo({
  1108. url: `../activity/goodList/goodList`
  1109. });
  1110. },
  1111. /**
  1112. * banner点击
  1113. */
  1114. bannerTap() {
  1115. if (!this.data.isLogin) {
  1116. wx.navigateTo({
  1117. url: `../../pages/login/login?index=0`
  1118. });
  1119. return;
  1120. }
  1121. if (this.data.isIos || this.data.isVip) {
  1122. this.myPlase();
  1123. } else {
  1124. this.messageAuth();
  1125. }
  1126. },
  1127. /**活动改版 */
  1128. myPlase() {
  1129. if (!wx.getStorageSync('message')) {
  1130. wx.requestSubscribeMessage({
  1131. tmplIds: ['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY',
  1132. '-2ZZpWFoyKvAtX1HwEIQLQ92LnN8cryamB94LqLGo98'
  1133. ],
  1134. success: (res) => {
  1135. console.log(res)
  1136. if (res['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY'] === 'reject') {
  1137. console.log('用户不同意订阅')
  1138. // 用户不同意订阅
  1139. wx.setStorageSync('message', false)
  1140. } else if (res['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY'] === 'accept') {
  1141. console.log('订阅成功')
  1142. // 用户点击统一订阅
  1143. wx.setStorageSync('message', true)
  1144. }
  1145. wx.navigateTo({
  1146. url: `../vipActivity/vipActivity`
  1147. });
  1148. },
  1149. fail: () => {
  1150. wx.navigateTo({
  1151. url: `../vipActivity/vipActivity`
  1152. });
  1153. }
  1154. })
  1155. } else {
  1156. wx.navigateTo({
  1157. url: `../vipActivity/vipActivity`
  1158. });
  1159. }
  1160. },
  1161. // 弹窗提示
  1162. helpPayHideEvent() {
  1163. this.setData({
  1164. helpPayHide: !this.data.helpPayHide
  1165. })
  1166. },
  1167. // 支付或者助力
  1168. payAndHelp() {
  1169. if (!this.data.isLogin) {
  1170. wx.navigateTo({
  1171. url: `../../pages/login/login?index=0`
  1172. });
  1173. return;
  1174. }
  1175. if (this.data.iphoneType === 'ios') {
  1176. httpRequestApi.postUserHelp().success(res => {
  1177. console.log(res)
  1178. if (res.data.data) {
  1179. this.setData({
  1180. tipsType: 'tips',
  1181. tipsImg: 'http://reader-wx.ai160.com/images/reader/pay/help_success.png'
  1182. })
  1183. } else {
  1184. this.setData({
  1185. tipsType: 'tips',
  1186. tipsImg: 'http://reader-wx.ai160.com/images/reader/pay/helped.png'
  1187. })
  1188. }
  1189. })
  1190. } else {
  1191. // 去支付需要获取权限
  1192. this.messageAuth();
  1193. }
  1194. },
  1195. // 去产品页
  1196. goToPruduct() {
  1197. wx.navigateTo({
  1198. url: `../product/product?price=${this.data.myData.price}`
  1199. });
  1200. },
  1201. // 授权
  1202. messageAuth() {
  1203. if (!wx.getStorageSync('message')) {
  1204. wx.requestSubscribeMessage({
  1205. tmplIds: ['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY',
  1206. '-2ZZpWFoyKvAtX1HwEIQLQ92LnN8cryamB94LqLGo98'
  1207. ],
  1208. success: (res) => {
  1209. console.log(res)
  1210. if (res['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY'] === 'reject') {
  1211. console.log('用户不同意订阅')
  1212. wx.setStorageSync('message', false)
  1213. } else if (res['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY'] === 'accept') {
  1214. console.log('订阅成功')
  1215. wx.setStorageSync('message', true)
  1216. }
  1217. this.order();
  1218. },
  1219. fail: () => {
  1220. this.order();
  1221. }
  1222. })
  1223. } else {
  1224. this.order();
  1225. }
  1226. },
  1227. // 支付
  1228. order() {
  1229. // 渠道id
  1230. const productId = wx.getStorageSync('productId');
  1231. httpRequestApi.createOrder(productId).success(res => {
  1232. console.log(res.data.data.package);
  1233. const timeStamp = res.data.data.timeStamp;
  1234. const nonceStr = res.data.data.nonceStr;
  1235. const packages = res.data.data.package;
  1236. const paySign = res.data.data.sign;
  1237. wx.requestPayment({
  1238. timeStamp,
  1239. nonceStr,
  1240. package: packages,
  1241. signType: 'MD5',
  1242. paySign,
  1243. success: (res) => {
  1244. if (this.data.iphoneType === 'iphone') {
  1245. this.setData({
  1246. tipsType: 'tips',
  1247. tipsImg: 'http://reader-wx.ai160.com/images/reader/pay/success.png'
  1248. })
  1249. }
  1250. httpRequestApi.getAuthActivity().success(res => {
  1251. if (!res.data.data) {
  1252. wx.setStorageSync('vip', false)
  1253. wx.setStorageSync('date', '')
  1254. } else {
  1255. wx.setStorageSync('vip', true)
  1256. wx.setStorageSync('date', res.data.data)
  1257. this.setData({
  1258. ['myData.isVIP']: true,
  1259. ['myData.date']: res.data.data
  1260. })
  1261. this.showGift();
  1262. }
  1263. }).fail(error => {
  1264. console.log(error)
  1265. })
  1266. },
  1267. fail(res) {}
  1268. })
  1269. })
  1270. },
  1271. // 助力或者支付提示
  1272. tips() {
  1273. console.log('支付完了')
  1274. this.setData({
  1275. helpPayHide: true
  1276. })
  1277. this.updateData("2");
  1278. },
  1279. // 购买成功告诉首页显示邀请有礼
  1280. showGift() {
  1281. console.log('通知')
  1282. this.setData({
  1283. isVip: true
  1284. })
  1285. },
  1286. // 首页获取权限
  1287. getHelpAuth() {
  1288. httpRequestApi.getAuthActivity().success(res => {
  1289. if (!res.data.data) {
  1290. wx.setStorageSync('vip', false)
  1291. wx.setStorageSync('date', '')
  1292. this.setData({
  1293. isVip: false
  1294. })
  1295. } else {
  1296. wx.setStorageSync('vip', true)
  1297. wx.setStorageSync('date', res.data.data)
  1298. this.setData({
  1299. isVip: true
  1300. })
  1301. }
  1302. }).fail(error => {
  1303. console.log(error)
  1304. })
  1305. }
  1306. })