index.js 46 KB

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