works.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. import httpRequestApi from '../../../utils/APIClient';
  2. import {
  3. formatDate
  4. } from '../../../utils/util';
  5. import {
  6. getOpenidSessionKey
  7. } from '../../../utils/httpUtil';
  8. const app = getApp()
  9. Page({
  10. data: {
  11. fullScreenBtn: false,
  12. playBtn: true,
  13. gesture: false,
  14. author: '',
  15. videoSrc: '',
  16. total: '',
  17. authorAvatar: '',
  18. user: [],
  19. inputValue: '',
  20. inputSBValue: '',
  21. replyList: [],
  22. howMuch: '200',
  23. moneySelect: 'moneySelect',
  24. moneyNormal: 'moneyNormal',
  25. ifReward: false,
  26. id: '',
  27. path: '',
  28. replyModal: false,
  29. totalRead: 0,
  30. pageNo: 1,
  31. pageSize: 3,
  32. goBackHome: false,
  33. isIOS: app.globalData.isIOS,
  34. alertFlag: false,
  35. modalType: "text",
  36. noScroll: '',
  37. modalText: [{
  38. text: '您还不是本课程的会员',
  39. type: 'bigOrange'
  40. },
  41. {
  42. text: '您可以开团,拼团成功获得使用权',
  43. type: 'normal'
  44. }
  45. ],
  46. modalBtnText: '去开团',
  47. isModalShow: false,
  48. modalCloseShow: true,
  49. hide: true,
  50. addComeOut: '',
  51. flowerNum: '6'
  52. // shareFlag: false
  53. },
  54. showAlert: function () {
  55. this.setData({
  56. alertFlag: !this.data.alertFlag
  57. })
  58. },
  59. onLoad: function (option) {
  60. console.log(option)
  61. if (option.flowerCount > 0) {
  62. this.setData({
  63. flowerNum: option.flowerCount
  64. }, () => {
  65. this.flowerAnimationHandler();
  66. })
  67. }
  68. getOpenidSessionKey((res) => {
  69. let id = option.id ? option.id : option.scene.replace('QR', '')
  70. if (option.scene || option.shareCard) {
  71. this.setData({
  72. goBackHome: true
  73. })
  74. }
  75. // wx.setNavigationBarTitle({
  76. // title: option.title //页面标题为路由参数
  77. // })
  78. this.uid = wx.getStorageSync('uid');
  79. let stackSize = 1;
  80. if (option.stackSize) {
  81. stackSize = option.stackSize;
  82. }
  83. this.setData({
  84. // title: option.title,
  85. id,
  86. myUid: this.uid,
  87. stackSize
  88. })
  89. this.getWorks(this.uid, id);
  90. }, (error) => {
  91. this.setData({
  92. hide: !this.data.hide,
  93. onLoadOption: option
  94. })
  95. return;
  96. });
  97. },
  98. onHide: function () {
  99. // this.data.stackSize >= 2
  100. console.log('hide')
  101. if (this.innerAudioContext) {
  102. console.log('音频应该被暂停')
  103. this.innerAudioContext.pause();
  104. }
  105. // this.videoCtx = null
  106. },
  107. onUnload: function () {
  108. console.log(this.videoPlayTime)
  109. if (this.videoPlayTime) {
  110. const data = {
  111. "title": this.data.title,
  112. "lessonId": this.data.classId,
  113. "productId": this.data.productId,
  114. "playStopTime": Math.ceil(this.videoPlayTime),
  115. "userReadId": this.data.userReadId,
  116. "type": 'READ',
  117. }
  118. httpRequestApi.playLogReport(data).success(res => {
  119. console.log(res)
  120. })
  121. }
  122. if (this.innerAudioContext) {
  123. this.innerAudioContext.destroy();
  124. }
  125. this.videoCtx = null
  126. // let videoCtx = wx.createVideoContext('worksVideo', this);
  127. // videoCtx.stop();
  128. },
  129. getWorks: function (uid, id) {
  130. httpRequestApi.getWorksDetail(uid, id).success((res) => {
  131. const others = res.data.data.otherRead;
  132. const author = res.data.data.user;
  133. const works = res.data.data.userRead;
  134. wx.setNavigationBarTitle({
  135. title: works.title //页面标题为路由参数
  136. })
  137. const othersTemp = [];
  138. others.forEach((item) => {
  139. const temp = {};
  140. temp.uid = item.userRead.id;
  141. temp.title = item.userRead.title;
  142. temp.image = item.user.avatar;
  143. temp.nickName = item.user.wechatName;
  144. othersTemp.push(temp);
  145. });
  146. this.setData({
  147. user: othersTemp,
  148. totalRead: res.data.data.totalRead,
  149. author: author.wechatName,
  150. authorAvatar: author.avatar,
  151. authorProfession: author.profession,
  152. authorUid: author.uid,
  153. videoSrc: works.originVideo,
  154. audioSrc: works.audioPath,
  155. iconImg: works.iconImg,
  156. classId: works.lessonId,
  157. isLike: res.data.data.isLike,
  158. isFans: res.data.data.isFans,
  159. title: works.title,
  160. userReadId: works.id
  161. })
  162. httpRequestApi.checkLesson(works.lessonId).success(res => {
  163. const productId = res.data.data[0];
  164. this.setData({
  165. productId
  166. })
  167. });
  168. // 设置音频路径
  169. this.innerAudioContext = wx.createInnerAudioContext();
  170. this.innerAudioContext.onPause((res) => {
  171. // 播放音频失败的回调
  172. console.log('音频暂停')
  173. })
  174. this.innerAudioContext.src = this.data.audioSrc; // 这里可以是录音的临时路径
  175. });
  176. },
  177. onShow() {
  178. console.log(this.data.stackSize)
  179. this.setData({
  180. replyList: [],
  181. pageNo: 1,
  182. pageSize: 2
  183. }, () => {
  184. this.getReply();
  185. })
  186. },
  187. videoPlayHandler: function () {
  188. this.setData({
  189. videoLoad: true
  190. }, () => {
  191. this.videoCtx = wx.createVideoContext('worksVideo', this);
  192. this.videoCtx.play();
  193. })
  194. },
  195. likeWorks: function (e) {
  196. // + 1 + 1的动画
  197. this.setData({
  198. addComeOut: 'add-one-come-out'
  199. })
  200. setTimeout(() => {
  201. if (this.data.addComeOut) {
  202. this.setData({
  203. addComeOut: ''
  204. })
  205. }
  206. }, 1100)
  207. // 恭喜获得x朵小红花
  208. if (this.data.isLike) {
  209. // wx.showToast({
  210. // title: '不要重复点赞哦',
  211. // icon: 'fail',
  212. // duration: 1000
  213. // })
  214. return;
  215. }
  216. httpRequestApi.likeWorks(this.uid, this.data.id).success(res => {
  217. this.setData({
  218. isLike: true,
  219. flowerNum: res.data.count
  220. }, () => {
  221. if (res.data.count > 0) {
  222. this.flowerAnimationHandler();
  223. }
  224. });
  225. })
  226. },
  227. // 弹出分享框
  228. openShare: function (e) {
  229. if (this.data.authorAvatar && this.data.author && this.data.iconImg && this.data.title && this.data.id) {
  230. this.shareDialog = this.selectComponent("#share-dialog");
  231. const data = {
  232. avatar: this.data.authorAvatar,
  233. author: this.data.author,
  234. iconImg: this.data.iconImg,
  235. title: this.data.title,
  236. path: `pages/social/works/works`,
  237. scene: this.data.id,
  238. productId: this.data.productId
  239. // tip: this.data.tip,
  240. }
  241. // console.log(data)
  242. this.setData({
  243. noScroll: 'noScroll'
  244. })
  245. this.shareDialog.share(data);
  246. }
  247. },
  248. // 分享框关闭
  249. shareDialogClose: function (e) {
  250. this.setData({
  251. noScroll: ''
  252. })
  253. },
  254. videoPlay: function () {
  255. // 视频开始 先结束 再开始
  256. // this.innerAudioContext.play();
  257. // this.innerAudioContext.pause();
  258. // wx.showToast({
  259. // title: '加载中',
  260. // icon: 'loading',
  261. // duration: 600
  262. // })
  263. // setTimeout(() => {
  264. this.innerAudioContext.play();
  265. // }, 800)
  266. // httpRequestApi.playWorks(this.uid, this.data.id).success(() => {
  267. // console.log('容个错')
  268. // });
  269. },
  270. // 视频播放完毕销毁录音
  271. videoEnd: function (e) {
  272. console.log(e)
  273. this.innerAudioContext.stop();
  274. },
  275. videoPause: function () {
  276. console.log('视频暂停')
  277. this.innerAudioContext.pause();
  278. },
  279. videoWaiting: function () {
  280. console.log('视频缓冲')
  281. this.innerAudioContext.pause();
  282. },
  283. videoProgress: function (e) {
  284. if (e.detail.buffered <= 10) {
  285. this.innerAudioContext.pause();
  286. } else {
  287. this.innerAudioContext.play();
  288. }
  289. },
  290. videoTimeupdate: function (e) {
  291. this.videoPlayTime = e.detail.currentTime
  292. if (e.detail.currentTime - this.innerAudioContext.currentTime >= 1) {
  293. this.innerAudioContext.seek(e.detail.currentTime - 0.1);
  294. }
  295. },
  296. goToReading: function () {
  297. const classId = this.data.classId;
  298. httpRequestApi.areYouSuper(this.data.productId).success(res => {
  299. if (res.data.success) {
  300. wx.navigateTo({
  301. url: `../../main/reading/reading?id=${classId}`
  302. })
  303. } else {
  304. // ios用户 并且没有购买过此书
  305. // if (this.data.isIOS) {
  306. // wx.showModal({
  307. // title: '暂不支持',
  308. // content: '十分抱歉,由于相关规定,您暂时无法在这里朗读',
  309. // success(res) {
  310. // if (res.confirm) {
  311. // console.log('用户点击确定')
  312. // } else if (res.cancel) {
  313. // console.log('用户点击取消')
  314. // }
  315. // }
  316. // })
  317. // return;
  318. // }
  319. console.log('chulaiba')
  320. this.setData({
  321. isModalShow: true
  322. })
  323. // wx.showModal({
  324. // title: '您未购买过本书,不能朗读',
  325. // content: '超值团购进行中,快去看看',
  326. // success(res) {
  327. // if (res.confirm) {
  328. // console.log('用户点击确定')
  329. // wx.navigateTo({
  330. // url: `../../groupPage/grade-details/grade-details?productId=${productId}`
  331. // })
  332. // } else if (res.cancel) {
  333. // console.log('用户点击取消')
  334. // }
  335. // }
  336. // })
  337. }
  338. })
  339. },
  340. onShareAppMessage: function () {
  341. console.log(this.data.productId);
  342. const data = {
  343. shareTypeEnum: 'LINK',
  344. shareContentEnum: 'READ',
  345. productId: this.data.productId
  346. }
  347. httpRequestApi.shareRecord(data).success((res) => {
  348. console.log(res)
  349. })
  350. return {
  351. title: '一样的课文,不一样的味道!我的配音表演已开始,求各位大咖围观、点评!',
  352. path: `pages/social/works/works?id=${this.data.id}&title=${this.data.title}&shareCard=true`,
  353. imageUrl: `https://efunbox.lingjiao.cn/reader/resource/share/read_${this.data.productId}.jpg`,
  354. }
  355. },
  356. follow: function () {
  357. let followUid = this.data.authorUid;
  358. if (this.data.isFans) {
  359. httpRequestApi.cancerFollow(this.uid, followUid).success((res) => {
  360. this.setData({
  361. isFans: false
  362. })
  363. wx.showToast({
  364. title: '取消关注',
  365. icon: 'success',
  366. duration: 1000
  367. })
  368. });
  369. } else {
  370. httpRequestApi.followUser(this.uid, followUid).success((res) => {
  371. this.setData({
  372. isFans: true
  373. })
  374. wx.showToast({
  375. title: '关注啦',
  376. icon: 'success',
  377. duration: 1000
  378. })
  379. });
  380. }
  381. },
  382. // 点赞评论
  383. likeCommend: function (e) {
  384. console.log(e);
  385. // let uid = wx.getStorageSync('uid');
  386. let followUid = e.currentTarget.dataset.id;
  387. let index = e.currentTarget.dataset.index;
  388. httpRequestApi.likeCommend(this.uid, followUid).success(res => {
  389. console.log(res);
  390. const str = `replyList[${index}].likes`;
  391. const strImg = `replyList[${index}].isLike`;
  392. this.setData({
  393. [str]: res.data.data.favors,
  394. [strImg]: true
  395. })
  396. });
  397. },
  398. // 去用户主页
  399. goToUsers: function (e) {
  400. let uid = e.currentTarget.dataset.uid;
  401. wx.navigateTo({
  402. url: `../../user/myworks/myworks?uid=${uid}`
  403. });
  404. },
  405. // 去其他用户的作品页
  406. goToOthers: function (e) {
  407. this.data.stackSize++;
  408. console.log(this.data.stackSize)
  409. if (this.data.stackSize >= 3) {
  410. console.log('跳转', this.data.stackSize)
  411. wx.redirectTo({
  412. url: `../../social/works/works?id=${e.currentTarget.dataset.uid}&title=${e.currentTarget.dataset.title}&stackSize=${this.data.stackSize}`
  413. })
  414. } else {
  415. console.log('下一个页面', this.data.stackSize)
  416. wx.navigateTo({
  417. url: `../../social/works/works?id=${e.currentTarget.dataset.uid}&title=${e.currentTarget.dataset.title}&stackSize=${this.data.stackSize}`
  418. })
  419. }
  420. },
  421. // 查询回复
  422. getReply: function () {
  423. // let uid = wx.getStorageSync('uid');
  424. let columnId = this.data.id;
  425. let pageNo = this.data.pageNo;
  426. let pageSize = this.data.pageSize;
  427. httpRequestApi.getReply(this.uid, columnId, pageNo, pageSize).success((res) => {
  428. const replyList = res.data.data.list;
  429. // const replyTemp = [];
  430. replyList.forEach((item) => {
  431. const temp = {};
  432. temp.nickName = item.user.wechatName;
  433. temp.avatar = item.user.avatar;
  434. temp.profession = item.user.profession;
  435. temp.uid = item.user.uid;
  436. // temp.text = decodeURI(item.detailDesc);
  437. temp.text = item.detailDesc;
  438. temp.id = item.id;
  439. temp.replyCount = item.replyCount;
  440. temp.time = formatDate(item.gmtCreated, 3);
  441. temp.likes = item.postsAttributeInfo.favors || 0;
  442. temp.isLike = item.isLike;
  443. this.data.replyList.push(temp);
  444. });
  445. this.setData({
  446. replyList: this.data.replyList,
  447. total: res.data.data.totalSize,
  448. totalPage: res.data.data.totalNo
  449. })
  450. });
  451. },
  452. // 打开回复详情页
  453. goToDetail: function (e) {
  454. let id = e.currentTarget.dataset.id;
  455. // let count = e.currentTarget.dataset.count;
  456. wx.navigateTo({
  457. url: `../../social/replyDetail/replyDetail?id=${id}&productId=${this.data.productId}`
  458. })
  459. },
  460. // 绑定输入框内容
  461. inputValue: function (e) {
  462. this.setData({
  463. inputValue: e.detail.value
  464. });
  465. },
  466. // 发布回复
  467. sendHandler: function () {
  468. console.log(this.data.productId)
  469. if (this.data.inputValue !== '') {
  470. // let uid = wx.getStorageSync('uid');
  471. let data = {
  472. "columnId": this.data.id,
  473. colunmNames: 'what',
  474. // "detailDesc": encodeURI(this.data.inputValue)
  475. "detailDesc": this.data.inputValue,
  476. productId: this.data.productId
  477. }
  478. httpRequestApi.postReply(this.uid, data).success(res => {
  479. console.log(res)
  480. this.setData({
  481. inputValue: '',
  482. pageNo: 1,
  483. replyList: [],
  484. flowerNum: res.data.count
  485. })
  486. this.getReply();
  487. if (res.data.count > 0) {
  488. this.flowerAnimationHandler();
  489. }
  490. });
  491. // 评论成功后刷新数据
  492. }
  493. },
  494. flowerAnimationHandler: function () {
  495. this.flowerBox = this.selectComponent("#flower-box");
  496. this.flowerBox.comeOut();
  497. },
  498. // 触底加载
  499. onReachBottom: function () {
  500. // 当前在推荐页面 加载推荐
  501. if (this.data.pageNo <= this.data.totalPage) {
  502. this.setData({
  503. pageNo: this.data.pageNo + 1
  504. }, () => {
  505. this.getReply();
  506. })
  507. }
  508. },
  509. // 设置点击时的id
  510. setSBId: function (e) {
  511. this.setData({
  512. replySBId: e.currentTarget.dataset.id,
  513. replyModal: true,
  514. replyIndex: e.currentTarget.dataset.index
  515. })
  516. },
  517. // 回复某个评论
  518. replySB: function () {
  519. const data = {
  520. postsId: this.data.replySBId,
  521. content: this.data.inputSBValue,
  522. productId: this.data.productId
  523. }
  524. httpRequestApi.postReplyComment(this.uid, data).success(res => {
  525. const replyWho = this.data.replyList[this.data.replyIndex];
  526. const indexStr = `replyList[${this.data.replyIndex}]`;
  527. replyWho.replyCount++;
  528. this.setData({
  529. replyModal: false,
  530. [indexStr]: replyWho
  531. })
  532. });
  533. },
  534. // 获取回复楼中楼的内容
  535. inputSBValue: function (e) {
  536. this.setData({
  537. inputSBValue: e.detail.value
  538. });
  539. },
  540. // 选择金额
  541. setMoney: function (e) {
  542. this.setData({
  543. howMuch: e.currentTarget.dataset.money
  544. })
  545. },
  546. reward: function () {
  547. if (this.data.isIOS) {
  548. return
  549. };
  550. this.setData({
  551. ifReward: true
  552. })
  553. },
  554. quitReward: function () {
  555. this.setData({
  556. ifReward: false
  557. })
  558. },
  559. // 奖励
  560. rewardMoney: function () {
  561. const data = {
  562. targetUid: this.data.authorUid,
  563. amount: this.data.howMuch
  564. }
  565. // let uid = wx.getStorageSync('uid');
  566. httpRequestApi.rewardMoney(this.uid, data).success(res => {
  567. if (res.data.message) {
  568. wx.showModal({
  569. title: '提示',
  570. content: res.data.message,
  571. success(res) {
  572. if (res.confirm) {
  573. console.log('用户点击确定')
  574. } else if (res.cancel) {
  575. console.log('用户点击取消')
  576. }
  577. }
  578. })
  579. return false;
  580. }
  581. this.payMoney(res.data.data);
  582. })
  583. },
  584. //支付
  585. payMoney: function (orderInfo) {
  586. if (this.data.haveTapMoney) {
  587. return false
  588. }
  589. this.setData({
  590. haveTapMoney: true
  591. })
  592. wx.requestPayment({
  593. 'appId': orderInfo.appId,
  594. 'timeStamp': orderInfo.timeStamp,
  595. 'nonceStr': orderInfo.nonceStr,
  596. 'package': orderInfo.package,
  597. 'signType': orderInfo.signType,
  598. 'paySign': orderInfo.sign,
  599. 'success': res => {
  600. this.setData({
  601. modalType: 'image',
  602. isModalShow: true,
  603. modalCloseShow: false,
  604. modalBtnText: '确定',
  605. haveTapMoney: false,
  606. ifReward: false
  607. })
  608. // wx.showModal({
  609. // title: '提示',
  610. // content: '支付成功',
  611. // success(res) {
  612. // if (res.confirm) {
  613. // this.setData({
  614. // ifReward: false
  615. // })
  616. // } else if (res.cancel) {
  617. // this.setData({
  618. // ifReward: false
  619. // })
  620. // }
  621. // }
  622. // })
  623. },
  624. 'fail': res => {
  625. this.setData({
  626. haveTapMoney: false,
  627. })
  628. console.log('支付失败', res)
  629. }
  630. })
  631. },
  632. // 回到首页
  633. goBackHome: function () {
  634. wx.redirectTo({
  635. url: '../../index/index'
  636. })
  637. },
  638. modalConfirmHandler: function () {
  639. if (this.data.modalType === 'image') {
  640. this.setData({
  641. modalType: 'text',
  642. isModalShow: false,
  643. ifReward: false,
  644. modalCloseShow: true,
  645. modalBtnText: "去开团",
  646. // ifReward: false
  647. })
  648. return false
  649. }
  650. this.setData({
  651. isModalShow: false
  652. })
  653. wx.navigateTo({
  654. url: `../../groupPage/grade-details/grade-details?productId=${this.data.productId}`
  655. })
  656. },
  657. modalCloseHandler: function () {
  658. this.setData({
  659. isModalShow: false
  660. })
  661. },
  662. jurisdiction: function () {
  663. //隐藏弹框
  664. this.setData({
  665. hide: !this.data.hide
  666. })
  667. //登录页信息
  668. this.onLoad(this.data.onLoadOption);
  669. },
  670. goToClass: function () {
  671. if (!this.data.isIOS && this.videoCtx ) {
  672. this.innerAudioContext.stop();
  673. this.innerAudioContext.destroy();
  674. this.videoCtx.stop();
  675. this.setData({
  676. videoLoad: false
  677. })
  678. }
  679. setTimeout(() => {
  680. wx.navigateTo({
  681. url: `../../main/class/class?id=${this.data.classId}`
  682. })
  683. }, 100)
  684. }
  685. })