index.js 46 KB

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