index.js 38 KB

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