works.js 23 KB

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