works.js 21 KB

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