works.js 21 KB

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