works.js 22 KB

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