works.js 21 KB

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