works.js 23 KB

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