works.js 22 KB

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