index.js 37 KB

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