works.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  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": 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. }, 1200)
  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. console.log('视频加载进度变化')
  285. console.log(e)
  286. if (e.detail.buffered <= 10) {
  287. this.innerAudioContext.pause();
  288. } else {
  289. this.innerAudioContext.play();
  290. }
  291. },
  292. videoTimeupdate: function (e) {
  293. console.log('视频播放进度发生变化')
  294. console.log('视频当前时长', e.detail.currentTime);
  295. this.videoPlayTime = e.detail.currentTime
  296. console.log('音频当前时长', this.innerAudioContext.currentTime)
  297. if (e.detail.currentTime - this.innerAudioContext.currentTime >= 1) {
  298. this.innerAudioContext.seek(e.detail.currentTime - 0.1);
  299. }
  300. },
  301. goToReading: function () {
  302. const classId = this.data.classId;
  303. httpRequestApi.areYouSuper(this.data.productId).success(res => {
  304. if (res.data.success) {
  305. wx.navigateTo({
  306. url: `../../main/reading/reading?id=${classId}`
  307. })
  308. } else {
  309. // ios用户 并且没有购买过此书
  310. // if (this.data.isIOS) {
  311. // wx.showModal({
  312. // title: '暂不支持',
  313. // content: '十分抱歉,由于相关规定,您暂时无法在这里朗读',
  314. // success(res) {
  315. // if (res.confirm) {
  316. // console.log('用户点击确定')
  317. // } else if (res.cancel) {
  318. // console.log('用户点击取消')
  319. // }
  320. // }
  321. // })
  322. // return;
  323. // }
  324. console.log('chulaiba')
  325. this.setData({
  326. isModalShow: true
  327. })
  328. // wx.showModal({
  329. // title: '您未购买过本书,不能朗读',
  330. // content: '超值团购进行中,快去看看',
  331. // success(res) {
  332. // if (res.confirm) {
  333. // console.log('用户点击确定')
  334. // wx.navigateTo({
  335. // url: `../../groupPage/grade-details/grade-details?productId=${productId}`
  336. // })
  337. // } else if (res.cancel) {
  338. // console.log('用户点击取消')
  339. // }
  340. // }
  341. // })
  342. }
  343. })
  344. },
  345. onShareAppMessage: function () {
  346. console.log(this.data.productId);
  347. const data = {
  348. shareTypeEnum: 'LINK',
  349. shareContentEnum: 'READ',
  350. productId: this.data.productId
  351. }
  352. httpRequestApi.shareRecord(data).success((res) => {
  353. console.log(res)
  354. })
  355. return {
  356. title: '一样的课文,不一样的味道!我的配音表演已开始,求各位大咖围观、点评!',
  357. path: `pages/social/works/works?id=${this.data.id}&title=${this.data.title}&shareCard=true`,
  358. imageUrl: `https://efunbox.lingjiao.cn/reader/resource/share/read_${this.data.productId}.jpg`,
  359. }
  360. },
  361. follow: function () {
  362. let followUid = this.data.authorUid;
  363. if (this.data.isFans) {
  364. httpRequestApi.cancerFollow(this.uid, followUid).success((res) => {
  365. this.setData({
  366. isFans: false
  367. })
  368. wx.showToast({
  369. title: '取消关注',
  370. icon: 'success',
  371. duration: 1000
  372. })
  373. });
  374. } else {
  375. httpRequestApi.followUser(this.uid, followUid).success((res) => {
  376. this.setData({
  377. isFans: true
  378. })
  379. wx.showToast({
  380. title: '关注啦',
  381. icon: 'success',
  382. duration: 1000
  383. })
  384. });
  385. }
  386. },
  387. // 点赞评论
  388. likeCommend: function (e) {
  389. console.log(e);
  390. // let uid = wx.getStorageSync('uid');
  391. let followUid = e.currentTarget.dataset.id;
  392. let index = e.currentTarget.dataset.index;
  393. httpRequestApi.likeCommend(this.uid, followUid).success(res => {
  394. console.log(res);
  395. const str = `replyList[${index}].likes`;
  396. const strImg = `replyList[${index}].isLike`;
  397. this.setData({
  398. [str]: res.data.data.favors,
  399. [strImg]: true
  400. })
  401. });
  402. },
  403. // 去用户主页
  404. goToUsers: function (e) {
  405. let uid = e.currentTarget.dataset.uid;
  406. wx.navigateTo({
  407. url: `../../user/myworks/myworks?uid=${uid}`
  408. });
  409. },
  410. // 去其他用户的作品页
  411. goToOthers: function (e) {
  412. this.data.stackSize++;
  413. console.log(this.data.stackSize)
  414. if (this.data.stackSize >= 3) {
  415. console.log('跳转', this.data.stackSize)
  416. wx.redirectTo({
  417. url: `../../social/works/works?id=${e.currentTarget.dataset.uid}&title=${e.currentTarget.dataset.title}&stackSize=${this.data.stackSize}`
  418. })
  419. } else {
  420. console.log('下一个页面', this.data.stackSize)
  421. wx.navigateTo({
  422. url: `../../social/works/works?id=${e.currentTarget.dataset.uid}&title=${e.currentTarget.dataset.title}&stackSize=${this.data.stackSize}`
  423. })
  424. }
  425. },
  426. // 查询回复
  427. getReply: function () {
  428. // let uid = wx.getStorageSync('uid');
  429. let columnId = this.data.id;
  430. let pageNo = this.data.pageNo;
  431. let pageSize = this.data.pageSize;
  432. httpRequestApi.getReply(this.uid, columnId, pageNo, pageSize).success((res) => {
  433. const replyList = res.data.data.list;
  434. // const replyTemp = [];
  435. replyList.forEach((item) => {
  436. const temp = {};
  437. temp.nickName = item.user.wechatName;
  438. temp.avatar = item.user.avatar;
  439. temp.profession = item.user.profession;
  440. temp.uid = item.user.uid;
  441. // temp.text = decodeURI(item.detailDesc);
  442. temp.text = item.detailDesc;
  443. temp.id = item.id;
  444. temp.replyCount = item.replyCount;
  445. temp.time = formatDate(item.gmtCreated, 3);
  446. temp.likes = item.postsAttributeInfo.favors || 0;
  447. temp.isLike = item.isLike;
  448. this.data.replyList.push(temp);
  449. });
  450. this.setData({
  451. replyList: this.data.replyList,
  452. total: res.data.data.totalSize,
  453. totalPage: res.data.data.totalNo
  454. })
  455. });
  456. },
  457. // 打开回复详情页
  458. goToDetail: function (e) {
  459. let id = e.currentTarget.dataset.id;
  460. // let count = e.currentTarget.dataset.count;
  461. wx.navigateTo({
  462. url: `../../social/replyDetail/replyDetail?id=${id}&productId=${this.data.productId}`
  463. })
  464. },
  465. // 绑定输入框内容
  466. inputValue: function (e) {
  467. this.setData({
  468. inputValue: e.detail.value
  469. });
  470. },
  471. // 发布回复
  472. sendHandler: function () {
  473. console.log(this.data.productId)
  474. if (this.data.inputValue !== '') {
  475. // let uid = wx.getStorageSync('uid');
  476. let data = {
  477. "columnId": this.data.id,
  478. colunmNames: 'what',
  479. // "detailDesc": encodeURI(this.data.inputValue)
  480. "detailDesc": this.data.inputValue,
  481. productId: this.data.productId
  482. }
  483. httpRequestApi.postReply(this.uid, data).success(res => {
  484. console.log(res)
  485. this.setData({
  486. inputValue: '',
  487. pageNo: 1,
  488. replyList: [],
  489. flowerNum: res.data.count
  490. })
  491. this.getReply();
  492. if (res.data.count > 0) {
  493. this.flowerAnimationHandler();
  494. }
  495. });
  496. // 评论成功后刷新数据
  497. }
  498. },
  499. flowerAnimationHandler: function(){
  500. this.flowerBox = this.selectComponent("#flower-box");
  501. this.flowerBox.comeOut();
  502. },
  503. // 触底加载
  504. onReachBottom: function () {
  505. // 当前在推荐页面 加载推荐
  506. if (this.data.pageNo <= this.data.totalPage) {
  507. this.setData({
  508. pageNo: this.data.pageNo + 1
  509. }, () => {
  510. this.getReply();
  511. })
  512. }
  513. },
  514. // 设置点击时的id
  515. setSBId: function (e) {
  516. this.setData({
  517. replySBId: e.currentTarget.dataset.id,
  518. replyModal: true,
  519. replyIndex: e.currentTarget.dataset.index
  520. })
  521. },
  522. // 回复某个评论
  523. replySB: function () {
  524. const data = {
  525. postsId: this.data.replySBId,
  526. content: this.data.inputSBValue,
  527. productId: this.data.productId
  528. }
  529. httpRequestApi.postReplyComment(this.uid, data).success(res => {
  530. const replyWho = this.data.replyList[this.data.replyIndex];
  531. const indexStr = `replyList[${this.data.replyIndex}]`;
  532. replyWho.replyCount++;
  533. this.setData({
  534. replyModal: false,
  535. [indexStr]: replyWho
  536. })
  537. });
  538. },
  539. // 获取回复楼中楼的内容
  540. inputSBValue: function (e) {
  541. this.setData({
  542. inputSBValue: e.detail.value
  543. });
  544. },
  545. // 选择金额
  546. setMoney: function (e) {
  547. this.setData({
  548. howMuch: e.currentTarget.dataset.money
  549. })
  550. },
  551. reward: function () {
  552. if (this.data.isIOS) {
  553. return
  554. };
  555. this.setData({
  556. ifReward: true
  557. })
  558. },
  559. quitReward: function () {
  560. this.setData({
  561. ifReward: false
  562. })
  563. },
  564. // 奖励
  565. rewardMoney: function () {
  566. const data = {
  567. targetUid: this.data.authorUid,
  568. amount: this.data.howMuch
  569. }
  570. // let uid = wx.getStorageSync('uid');
  571. httpRequestApi.rewardMoney(this.uid, data).success(res => {
  572. if (res.data.message) {
  573. wx.showModal({
  574. title: '提示',
  575. content: res.data.message,
  576. success(res) {
  577. if (res.confirm) {
  578. console.log('用户点击确定')
  579. } else if (res.cancel) {
  580. console.log('用户点击取消')
  581. }
  582. }
  583. })
  584. return false;
  585. }
  586. this.payMoney(res.data.data);
  587. })
  588. },
  589. //支付
  590. payMoney: function (orderInfo) {
  591. if (this.data.haveTapMoney) {
  592. return false
  593. }
  594. this.setData({
  595. haveTapMoney: true
  596. })
  597. wx.requestPayment({
  598. 'appId': orderInfo.appId,
  599. 'timeStamp': orderInfo.timeStamp,
  600. 'nonceStr': orderInfo.nonceStr,
  601. 'package': orderInfo.package,
  602. 'signType': orderInfo.signType,
  603. 'paySign': orderInfo.sign,
  604. 'success': res => {
  605. this.setData({
  606. modalType: 'image',
  607. isModalShow: true,
  608. modalCloseShow: false,
  609. modalBtnText: '确定',
  610. haveTapMoney: false,
  611. ifReward: false
  612. })
  613. // wx.showModal({
  614. // title: '提示',
  615. // content: '支付成功',
  616. // success(res) {
  617. // if (res.confirm) {
  618. // this.setData({
  619. // ifReward: false
  620. // })
  621. // } else if (res.cancel) {
  622. // this.setData({
  623. // ifReward: false
  624. // })
  625. // }
  626. // }
  627. // })
  628. },
  629. 'fail': res => {
  630. this.setData({
  631. haveTapMoney: false,
  632. })
  633. console.log('支付失败', res)
  634. }
  635. })
  636. },
  637. // 回到首页
  638. goBackHome: function () {
  639. wx.redirectTo({
  640. url: '../../index/index'
  641. })
  642. },
  643. modalConfirmHandler: function () {
  644. if (this.data.modalType === 'image') {
  645. this.setData({
  646. modalType: 'text',
  647. isModalShow: false,
  648. ifReward: false,
  649. modalCloseShow: true,
  650. modalBtnText: "去开团",
  651. // ifReward: false
  652. })
  653. return false
  654. }
  655. this.setData({
  656. isModalShow: false
  657. })
  658. wx.navigateTo({
  659. url: `../../groupPage/grade-details/grade-details?productId=${this.data.productId}`
  660. })
  661. },
  662. modalCloseHandler: function () {
  663. this.setData({
  664. isModalShow: false
  665. })
  666. },
  667. jurisdiction: function () {
  668. //隐藏弹框
  669. this.setData({
  670. hide: !this.data.hide
  671. })
  672. //登录页信息
  673. this.onLoad(this.data.onLoadOption);
  674. },
  675. goToClass: function () {
  676. wx.navigateTo({
  677. url: `../../main/class/class?id=${this.data.classId}`
  678. })
  679. }
  680. })