works.js 20 KB

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