works.js 21 KB

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