index.js 38 KB

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