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