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. wx.setStorageSync('grade', grade)
  898. this.setData({
  899. isGradeShow: false,
  900. grade
  901. })
  902. if (this.data.oldUser) {
  903. let data = {
  904. grade: e.target.dataset.code
  905. };
  906. httpRequestApi.settingUserInfo(data).success(res => {
  907. })
  908. return;
  909. };
  910. getOpenidNoLogin((res) => {
  911. console.log('getOpenidNoLogin', res)
  912. // 登录或注册完成 展示页面
  913. if (res.data.data.wechatName) {
  914. this.setData({
  915. isLogin: true
  916. })
  917. } else {
  918. this.setData({
  919. isLogin: false
  920. })
  921. }
  922. this.showPage()
  923. }, (error) => {
  924. console.log('获取失败')
  925. wx.setStorageSync('userSourseType', 'normal')
  926. this.setData({
  927. hide: !this.data.hide
  928. })
  929. }, grade);
  930. },
  931. getFollowData: function () {
  932. httpRequestApi.getFollowWorks(this.data.followPageNo, this.data.followPageSize).success(res => {
  933. if (res.data.data.totalSize === 0) {
  934. this.setData({
  935. videoList: [],
  936. noFollow: true
  937. })
  938. console.log('没有关注人或关注的人没有发过作品')
  939. return
  940. } else {
  941. this.setData({
  942. noFollow: false
  943. })
  944. }
  945. console.log('关注列表', res)
  946. const followData = res.data.data.list;
  947. // const videoList = [];
  948. this.formatWorksList(followData);
  949. });
  950. httpRequestApi.userEvent('SUBSCRIBE');
  951. },
  952. // 点击用户头像区域
  953. headTapHandler: function (e) {
  954. console.log('点击头像', e)
  955. let tapId = e.detail.activeId;
  956. // 点击头像既关注 测试
  957. httpRequestApi.followUser(this.uid, tapId).success(res => {
  958. console.log(res)
  959. })
  960. },
  961. getCoursesList: function () {
  962. const grade = wx.getStorageSync('grade');
  963. const data = {
  964. pageNo: this.data.coursePageNo,
  965. pageSize: 6,
  966. grade,
  967. type: 'EXAMPLE'
  968. };
  969. console.log('资源', data)
  970. httpRequestApi.getClassRead(data).success(res => {
  971. console.log('资源', this.data.coursesData)
  972. this.setData({
  973. coursesData: this.data.coursesData.concat(res.data.data.list),
  974. noMoreWork: res.data.data.list.length <= 0 ? true : false
  975. }, () => {
  976. console.log(this.data.coursesData)
  977. })
  978. })
  979. httpRequestApi.userEvent('RESOURCES');
  980. },
  981. goToReading: function (e) {
  982. console.log('去朗读', e)
  983. const id = e.detail.activeId ? e.detail.activeId : e.currentTarget.dataset.id;
  984. const index = e.currentTarget.dataset.index;
  985. this.setData({
  986. goToCoursesId: id,
  987. goToCoursesIndex: index
  988. })
  989. wx.navigateTo({
  990. url: `../../pages/reading/reading?id=${id}`
  991. });
  992. httpRequestApi.userEvent('REC_READ');
  993. },
  994. refreshCourseAmount() {
  995. console.log(this.data.goToCoursesId)
  996. console.log(this.data.goToCoursesIndex)
  997. if (this.data.goToCoursesId && (this.data.goToCoursesIndex || this.data.goToCoursesIndex === 0)) {
  998. httpRequestApi.getClassDetail(this.data.goToCoursesId).success(res => {
  999. console.log('刷新', res.data.data.userRead)
  1000. let likeStr = `coursesData[${this.data.goToCoursesIndex}].userRead.likeAmount`;
  1001. let commentStr = `coursesData[${this.data.goToCoursesIndex}].userRead.commentAmount`;
  1002. let playStr = `coursesData[${this.data.goToCoursesIndex}].userRead.playAmount`;
  1003. let shareStr = `coursesData[${this.data.goToCoursesIndex}].userRead.shareAmount`;
  1004. let collectStr = `coursesData[${this.data.goToCoursesIndex}].userRead.collectAmount`;
  1005. console.log(1, this.data.coursesData[this.data.goToCoursesIndex].userRead.likeAmount)
  1006. console.log(2, res.data.data.userRead.likeAmount)
  1007. this.setData({
  1008. [likeStr]: res.data.data.userRead.likeAmount,
  1009. [commentStr]: res.data.data.userRead.commentAmount,
  1010. [playStr]: res.data.data.userRead.playAmount,
  1011. [shareStr]: res.data.data.userRead.shareAmount,
  1012. [collectStr]: res.data.data.userRead.collectAmount,
  1013. }, () => {
  1014. console.log(111222333, this.data.coursesData[this.data.goToCoursesIndex])
  1015. })
  1016. })
  1017. }
  1018. },
  1019. courseCollectTap: function collectClass(e) {
  1020. console.log('收藏按钮', e);
  1021. const data = {
  1022. targetCode: e.target.dataset.id ? e.target.dataset.id : e.currentTarget.dataset.id,
  1023. favoritesType: e.target.dataset.type ? e.target.dataset.type : e.currentTarget.dataset.type
  1024. }
  1025. const index = e.target.dataset.index ? e.target.dataset.index : e.currentTarget.dataset.index;
  1026. let str = `coursesData[${index}].isFavorites`
  1027. httpRequestApi.collectClass(data).success((res) => {
  1028. console.log('this.data.coursesData[index]', this.data.coursesData[index])
  1029. this.setData({
  1030. [str]: !this.data.coursesData[index].isFavorites
  1031. })
  1032. });
  1033. },
  1034. coursesOpenShare: function coursesOpenShare(e) {
  1035. const obj = e.currentTarget.dataset
  1036. console.log('分享', obj)
  1037. console.log('分享', e)
  1038. if (1) {
  1039. this.shareDialog = this.selectComponent("#share-dialog");
  1040. const data = {
  1041. avatar: obj.avatar,
  1042. author: obj.author,
  1043. iconImg: obj.iconImg,
  1044. title: obj.title,
  1045. path: `pages/index/index`,
  1046. scene: obj.id,
  1047. productId: 1
  1048. // tip: this.data.tip,
  1049. }
  1050. // console.log(data)
  1051. this.setData({
  1052. noScroll: 'noScroll',
  1053. shareTitle: obj.title,
  1054. shareId: obj.id,
  1055. shareImg: obj.shareimg
  1056. })
  1057. this.shareDialog.share(data);
  1058. }
  1059. },
  1060. collectTap: function (e) {
  1061. const index = e.detail.index;
  1062. let str = `videoList[${index}].isFavorite`;
  1063. let str2 = `videoList[${index}].favoritesAmount`;
  1064. let favoritesAmount = e.detail.isCollect ? this.data.videoList[index].favoritesAmount + 1 : this.data.videoList[index].favoritesAmount - 1
  1065. this.setData({
  1066. [str]: e.detail.isCollect,
  1067. [str2]: favoritesAmount
  1068. })
  1069. },
  1070. likeTap: function (e) {
  1071. console.log('点赞', e)
  1072. const index = e.detail.index;
  1073. let likeStr = `videoList[${index}].isLike`;
  1074. let likeNumStr = `videoList[${index}].likes`;
  1075. this.setData({
  1076. [likeStr]: true,
  1077. [likeNumStr]: this.data.videoList[index].likes + 1
  1078. })
  1079. // this.flowerAnimationHandler()
  1080. },
  1081. flowerAnimationHandler: function () {
  1082. this.flowerBox = this.selectComponent("#flower-box");
  1083. console.log('this.flower', this.flowerBox)
  1084. this.flowerBox.comeOut();
  1085. },
  1086. addShareAmount: function (e) {
  1087. console.log('+++++1', e)
  1088. let str = `videoList[${e.detail.index}].shareAmount`;
  1089. this.setData({
  1090. [str]: this.data.videoList[e.detail.index].shareAmount + 1
  1091. })
  1092. },
  1093. /**
  1094. * 跳转到活动页
  1095. */
  1096. goToActivity() {
  1097. httpRequestApi.postActEvent('BANNER').success(res => {
  1098. console.log('活动banner', res)
  1099. })
  1100. // wx.navigateTo({
  1101. // url: `../activity/index/index`
  1102. // // url: `../activity/rule/rule`
  1103. // });
  1104. wx.navigateTo({
  1105. url: `../activity/goodList/goodList`
  1106. });
  1107. },
  1108. /**
  1109. * banner点击
  1110. */
  1111. bannerTap() {
  1112. if (!this.data.isLogin) {
  1113. wx.navigateTo({
  1114. url: `../../pages/login/login?index=0`
  1115. });
  1116. return;
  1117. }
  1118. if (this.data.isIos || this.data.isVip) {
  1119. this.myPlase();
  1120. } else {
  1121. this.messageAuth();
  1122. }
  1123. },
  1124. /**活动改版 */
  1125. myPlase() {
  1126. if (!wx.getStorageSync('message')) {
  1127. wx.requestSubscribeMessage({
  1128. tmplIds: ['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY',
  1129. '-2ZZpWFoyKvAtX1HwEIQLQ92LnN8cryamB94LqLGo98'
  1130. ],
  1131. success: (res) => {
  1132. console.log(res)
  1133. if (res['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY'] === 'reject') {
  1134. console.log('用户不同意订阅')
  1135. // 用户不同意订阅
  1136. wx.setStorageSync('message', false)
  1137. } else if (res['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY'] === 'accept') {
  1138. console.log('订阅成功')
  1139. // 用户点击统一订阅
  1140. wx.setStorageSync('message', true)
  1141. }
  1142. wx.navigateTo({
  1143. url: `../vipActivity/vipActivity`
  1144. });
  1145. },
  1146. fail: () => {
  1147. wx.navigateTo({
  1148. url: `../vipActivity/vipActivity`
  1149. });
  1150. }
  1151. })
  1152. } else {
  1153. wx.navigateTo({
  1154. url: `../vipActivity/vipActivity`
  1155. });
  1156. }
  1157. },
  1158. // 弹窗提示
  1159. helpPayHideEvent() {
  1160. this.setData({
  1161. helpPayHide: !this.data.helpPayHide
  1162. })
  1163. },
  1164. // 支付或者助力
  1165. payAndHelp() {
  1166. if (!this.data.isLogin) {
  1167. wx.navigateTo({
  1168. url: `../../pages/login/login?index=0`
  1169. });
  1170. return;
  1171. }
  1172. if (this.data.iphoneType === 'ios') {
  1173. httpRequestApi.postUserHelp().success(res => {
  1174. console.log(res)
  1175. if (res.data.data) {
  1176. this.setData({
  1177. tipsType: 'tips',
  1178. tipsImg: 'http://reader-wx.ai160.com/images/reader/pay/help_success.png'
  1179. })
  1180. } else {
  1181. this.setData({
  1182. tipsType: 'tips',
  1183. tipsImg: 'http://reader-wx.ai160.com/images/reader/pay/helped.png'
  1184. })
  1185. }
  1186. })
  1187. } else {
  1188. // 去支付需要获取权限
  1189. this.messageAuth();
  1190. }
  1191. },
  1192. // 去产品页
  1193. goToPruduct() {
  1194. wx.navigateTo({
  1195. url: `../product/product?price=${this.data.myData.price}`
  1196. });
  1197. },
  1198. // 授权
  1199. messageAuth() {
  1200. if (!wx.getStorageSync('message')) {
  1201. wx.requestSubscribeMessage({
  1202. tmplIds: ['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY',
  1203. '-2ZZpWFoyKvAtX1HwEIQLQ92LnN8cryamB94LqLGo98'
  1204. ],
  1205. success: (res) => {
  1206. console.log(res)
  1207. if (res['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY'] === 'reject') {
  1208. console.log('用户不同意订阅')
  1209. wx.setStorageSync('message', false)
  1210. } else if (res['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY'] === 'accept') {
  1211. console.log('订阅成功')
  1212. wx.setStorageSync('message', true)
  1213. }
  1214. this.order();
  1215. },
  1216. fail: () => {
  1217. this.order();
  1218. }
  1219. })
  1220. } else {
  1221. this.order();
  1222. }
  1223. },
  1224. // 支付
  1225. order() {
  1226. // 渠道id
  1227. const productId = wx.getStorageSync('productId');
  1228. httpRequestApi.createOrder(productId).success(res => {
  1229. console.log(res.data.data.package);
  1230. const timeStamp = res.data.data.timeStamp;
  1231. const nonceStr = res.data.data.nonceStr;
  1232. const packages = res.data.data.package;
  1233. const paySign = res.data.data.sign;
  1234. wx.requestPayment({
  1235. timeStamp,
  1236. nonceStr,
  1237. package: packages,
  1238. signType: 'MD5',
  1239. paySign,
  1240. success: (res) => {
  1241. if (this.data.iphoneType === 'iphone') {
  1242. this.setData({
  1243. tipsType: 'tips',
  1244. tipsImg: 'http://reader-wx.ai160.com/images/reader/pay/success.png'
  1245. })
  1246. }
  1247. httpRequestApi.getAuthActivity().success(res => {
  1248. if (!res.data.data) {
  1249. wx.setStorageSync('vip', false)
  1250. wx.setStorageSync('date', '')
  1251. } else {
  1252. wx.setStorageSync('vip', true)
  1253. wx.setStorageSync('date', res.data.data)
  1254. this.setData({
  1255. ['myData.isVIP']: true,
  1256. ['myData.date']: res.data.data
  1257. })
  1258. this.showGift();
  1259. }
  1260. }).fail(error => {
  1261. console.log(error)
  1262. })
  1263. },
  1264. fail(res) {}
  1265. })
  1266. })
  1267. },
  1268. // 助力或者支付提示
  1269. tips() {
  1270. console.log('支付完了')
  1271. this.setData({
  1272. helpPayHide: true
  1273. })
  1274. this.updateData("2");
  1275. },
  1276. // 购买成功告诉首页显示邀请有礼
  1277. showGift() {
  1278. console.log('通知')
  1279. this.setData({
  1280. isVip: true
  1281. })
  1282. },
  1283. // 首页获取权限
  1284. getHelpAuth() {
  1285. httpRequestApi.getAuthActivity().success(res => {
  1286. if (!res.data.data) {
  1287. wx.setStorageSync('vip', false)
  1288. wx.setStorageSync('date', '')
  1289. this.setData({
  1290. isVip: false
  1291. })
  1292. } else {
  1293. wx.setStorageSync('vip', true)
  1294. wx.setStorageSync('date', res.data.data)
  1295. this.setData({
  1296. isVip: true
  1297. })
  1298. }
  1299. }).fail(error => {
  1300. console.log(error)
  1301. })
  1302. }
  1303. })