index.js 37 KB

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