index.js 38 KB

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