index.js 45 KB

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