works.js 21 KB

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