works.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. import httpRequestApi from '../../../utils/APIClient';
  2. import {
  3. formatDate
  4. } from '../../../utils/util';
  5. const app = getApp()
  6. Page({
  7. data: {
  8. fullScreenBtn: false,
  9. playBtn: true,
  10. gesture: false,
  11. author: '',
  12. videoSrc: '',
  13. total: '',
  14. authorAvatar: '',
  15. user: [],
  16. inputValue: '',
  17. inputSBValue: '',
  18. replyList: [],
  19. howMuch: '200',
  20. moneySelect: 'moneySelect',
  21. moneyNormal: 'moneyNormal',
  22. ifReward: false,
  23. id: '',
  24. path: '',
  25. replyModal: false,
  26. totalRead: 0,
  27. pageNo: 1,
  28. pageSize: 3,
  29. goBackHome: false,
  30. isIOS: app.globalData.isIOS,
  31. alertFlag: false,
  32. modalType: "text",
  33. modalText: [{
  34. text: '您还不是本课程的会员',
  35. type: 'bigOrange'
  36. },
  37. {
  38. text: '您可以开团,拼团成功获得使用权',
  39. type: 'normal'
  40. }
  41. ],
  42. modalBtnText:'去开团',
  43. isModalShow: false,
  44. modalCloseShow: true
  45. // shareFlag: false
  46. },
  47. showAlert: function () {
  48. this.setData({
  49. alertFlag: !this.data.alertFlag
  50. })
  51. },
  52. onLoad: function (option) {
  53. let id = option.id ? option.id : option.scene.replace('QR', '')
  54. if (option.scene || option.shareCard) {
  55. this.setData({
  56. goBackHome: true
  57. })
  58. }
  59. wx.setNavigationBarTitle({
  60. title: option.title //页面标题为路由参数
  61. })
  62. this.uid = wx.getStorageSync('uid');
  63. let stackSize = 1;
  64. if (option.stackSize) {
  65. stackSize = option.stackSize;
  66. }
  67. this.setData({
  68. title: option.title,
  69. id,
  70. myUid: this.uid,
  71. stackSize
  72. })
  73. this.getWorks(this.uid, id);
  74. },
  75. onHide: function () {
  76. // this.data.stackSize >= 2
  77. console.log(this.data.stackSize)
  78. if (this.innerAudioContext) {
  79. this.innerAudioContext.pause();
  80. }
  81. let videoCtx = wx.createVideoContext('worksVideo', this);
  82. videoCtx.stop();
  83. },
  84. onUnload: function () {
  85. if (this.innerAudioContext) {
  86. this.innerAudioContext.destroy();
  87. }
  88. let videoCtx = wx.createVideoContext('worksVideo', this);
  89. videoCtx.stop();
  90. },
  91. getWorks: function (uid, id) {
  92. httpRequestApi.getWorksDetail(uid, id).success((res) => {
  93. const others = res.data.data.otherRead;
  94. const author = res.data.data.user;
  95. const works = res.data.data.userRead;
  96. const othersTemp = [];
  97. others.forEach((item) => {
  98. const temp = {};
  99. temp.uid = item.userRead.id;
  100. temp.title = item.userRead.title;
  101. temp.image = item.user.avatar;
  102. temp.nickName = item.user.wechatName;
  103. othersTemp.push(temp);
  104. });
  105. this.setData({
  106. user: othersTemp,
  107. totalRead: res.data.data.totalRead,
  108. author: author.wechatName,
  109. authorAvatar: author.avatar,
  110. authorProfession: author.profession,
  111. authorUid: author.uid,
  112. videoSrc: works.originVideo,
  113. audioSrc: works.audioPath,
  114. iconImg: works.iconImg,
  115. classId: works.lessonId,
  116. isLike: res.data.data.isLike,
  117. isFans: res.data.data.isFans,
  118. })
  119. // 设置音频路径
  120. this.innerAudioContext = wx.createInnerAudioContext();
  121. this.innerAudioContext.onError((res) => {
  122. // 播放音频失败的回调
  123. })
  124. this.innerAudioContext.src = this.data.audioSrc; // 这里可以是录音的临时路径
  125. });
  126. },
  127. onShow() {
  128. console.log(this.data.stackSize)
  129. this.setData({
  130. replyList: [],
  131. pageNo: 1,
  132. pageSize: 2
  133. }, () => {
  134. this.getReply();
  135. })
  136. },
  137. videoPlayHandler: function () {
  138. this.setData({
  139. videoLoad: true
  140. }, () => {
  141. this.videoCtx = wx.createVideoContext('worksVideo', this);
  142. this.videoCtx.play();
  143. })
  144. },
  145. likeWorks: function (e) {
  146. if (this.data.isLike) {
  147. wx.showToast({
  148. title: '不要重复点赞哦',
  149. icon: 'fail',
  150. duration: 1000
  151. })
  152. return;
  153. }
  154. httpRequestApi.likeWorks(this.uid, this.data.id).success(res => {
  155. this.setData({
  156. isLike: true
  157. }, () => {
  158. wx.showToast({
  159. title: '点赞数+1',
  160. icon: 'success',
  161. duration: 1000
  162. })
  163. });
  164. })
  165. },
  166. // 弹出分享框
  167. openShare: function (e) {
  168. this.shareDialog = this.selectComponent("#share-dialog");
  169. const data = {
  170. avatar: this.data.authorAvatar,
  171. author: this.data.author,
  172. iconImg: this.data.iconImg,
  173. title: this.data.title,
  174. path: `pages/social/works/works`,
  175. scene: this.data.id
  176. // tip: this.data.tip,
  177. }
  178. this.shareDialog.share(data);
  179. },
  180. videoPlay: function () {
  181. // 视频开始 先结束 再开始
  182. this.innerAudioContext.play();
  183. this.innerAudioContext.pause();
  184. wx.showToast({
  185. title: '加载中',
  186. icon: 'loading',
  187. duration: 600
  188. })
  189. setTimeout(() => {
  190. this.innerAudioContext.play();
  191. }, 800)
  192. httpRequestApi.playWorks(this.uid, this.data.id).success(() => {
  193. console.log('容个错')
  194. });
  195. },
  196. // 视频播放完毕销毁录音
  197. videoEnd: function () {
  198. this.innerAudioContext.stop();
  199. },
  200. videoPause: function () {
  201. this.innerAudioContext.pause();
  202. },
  203. goToReading: function () {
  204. const classId = this.data.classId;
  205. httpRequestApi.checkLesson(classId).success(res => {
  206. const productId = res.data.data[0];
  207. this.setData({
  208. productId
  209. })
  210. httpRequestApi.areYouSuper(res.data.data).success(res => {
  211. if (res.data.success) {
  212. wx.navigateTo({
  213. url: `../../main/reading/reading?id=${classId}`
  214. })
  215. } else {
  216. // ios用户 并且没有购买过此书
  217. // if (this.data.isIOS) {
  218. // wx.showModal({
  219. // title: '暂不支持',
  220. // content: '十分抱歉,由于相关规定,您暂时无法在这里朗读',
  221. // success(res) {
  222. // if (res.confirm) {
  223. // console.log('用户点击确定')
  224. // } else if (res.cancel) {
  225. // console.log('用户点击取消')
  226. // }
  227. // }
  228. // })
  229. // return;
  230. // }
  231. console.log('chulaiba')
  232. this.setData({
  233. isModalShow: true
  234. })
  235. // wx.showModal({
  236. // title: '您未购买过本书,不能朗读',
  237. // content: '超值团购进行中,快去看看',
  238. // success(res) {
  239. // if (res.confirm) {
  240. // console.log('用户点击确定')
  241. // wx.navigateTo({
  242. // url: `../../groupPage/grade-details/grade-details?productId=${productId}`
  243. // })
  244. // } else if (res.cancel) {
  245. // console.log('用户点击取消')
  246. // }
  247. // }
  248. // })
  249. }
  250. })
  251. });
  252. },
  253. onShareAppMessage: function (res) {
  254. if (res.from === 'button') {
  255. // 来自页面内转发按钮
  256. console.log(res.target)
  257. }
  258. return {
  259. title: '一样的课文,不一样的味道!我的配音表演已开始,求各位大咖围观、点评!',
  260. path: `pages/social/works/works?id=${this.data.id}&title=${this.data.title}&shareCard=true`,
  261. imageUrl: '../../../static/share/works_icon.jpg'
  262. }
  263. },
  264. follow: function () {
  265. let followUid = this.data.authorUid;
  266. if (this.data.isFans) {
  267. httpRequestApi.cancerFollow(this.uid, followUid).success((res) => {
  268. this.setData({
  269. isFans: false
  270. })
  271. wx.showToast({
  272. title: '取消关注',
  273. icon: 'success',
  274. duration: 1000
  275. })
  276. });
  277. } else {
  278. httpRequestApi.followUser(this.uid, followUid).success((res) => {
  279. this.setData({
  280. isFans: true
  281. })
  282. wx.showToast({
  283. title: '关注啦',
  284. icon: 'success',
  285. duration: 1000
  286. })
  287. });
  288. }
  289. },
  290. // 点赞评论
  291. likeCommend: function (e) {
  292. console.log(e);
  293. // let uid = wx.getStorageSync('uid');
  294. let followUid = e.currentTarget.dataset.id;
  295. let index = e.currentTarget.dataset.index;
  296. httpRequestApi.likeCommend(this.uid, followUid).success(res => {
  297. console.log(res);
  298. const str = `replyList[${index}].likes`;
  299. const strImg = `replyList[${index}].isLike`;
  300. this.setData({
  301. [str]: res.data.data.favors,
  302. [strImg]: true
  303. })
  304. });
  305. },
  306. // 去用户主页
  307. goToUsers: function (e) {
  308. let uid = e.currentTarget.dataset.uid;
  309. wx.navigateTo({
  310. url: `../../user/myworks/myworks?uid=${uid}`
  311. });
  312. },
  313. // 去其他用户的作品页
  314. goToOthers: function (e) {
  315. this.data.stackSize++;
  316. console.log(this.data.stackSize)
  317. if (this.data.stackSize >= 3) {
  318. console.log('跳转', this.data.stackSize)
  319. wx.redirectTo({
  320. url: `../../social/works/works?id=${e.currentTarget.dataset.uid}&title=${e.currentTarget.dataset.title}&stackSize=${this.data.stackSize}`
  321. })
  322. } else {
  323. console.log('下一个页面', this.data.stackSize)
  324. wx.navigateTo({
  325. url: `../../social/works/works?id=${e.currentTarget.dataset.uid}&title=${e.currentTarget.dataset.title}&stackSize=${this.data.stackSize}`
  326. })
  327. }
  328. },
  329. // 查询回复
  330. getReply: function () {
  331. // let uid = wx.getStorageSync('uid');
  332. let columnId = this.data.id;
  333. let pageNo = this.data.pageNo;
  334. let pageSize = this.data.pageSize;
  335. httpRequestApi.getReply(this.uid, columnId, pageNo, pageSize).success((res) => {
  336. const replyList = res.data.data.list;
  337. // const replyTemp = [];
  338. replyList.forEach((item) => {
  339. const temp = {};
  340. temp.nickName = item.user.wechatName;
  341. temp.avatar = item.user.avatar;
  342. temp.profession = item.user.profession;
  343. temp.uid = item.user.uid;
  344. temp.text = decodeURI(item.detailDesc);
  345. temp.id = item.id;
  346. temp.replyCount = item.replyCount;
  347. temp.time = formatDate(item.gmtCreated, 3);
  348. temp.likes = item.postsAttributeInfo.favors || 0;
  349. temp.isLike = item.isLike;
  350. this.data.replyList.push(temp);
  351. });
  352. this.setData({
  353. replyList: this.data.replyList,
  354. total: res.data.data.totalSize,
  355. totalPage: res.data.data.totalNo
  356. })
  357. });
  358. },
  359. // 打开回复详情页
  360. goToDetail: function (e) {
  361. let id = e.currentTarget.dataset.id;
  362. // let count = e.currentTarget.dataset.count;
  363. wx.navigateTo({
  364. url: `../../social/replyDetail/replyDetail?id=${id}`
  365. })
  366. },
  367. // 绑定输入框内容
  368. inputValue: function (e) {
  369. this.setData({
  370. inputValue: e.detail.value
  371. });
  372. },
  373. // 发布回复
  374. sendHandler: function () {
  375. if (this.data.inputValue !== '') {
  376. // let uid = wx.getStorageSync('uid');
  377. let data = {
  378. "columnId": this.data.id,
  379. colunmNames: 'what',
  380. "detailDesc": encodeURI(this.data.inputValue)
  381. }
  382. httpRequestApi.postReply(this.uid, data).success(res => {
  383. this.setData({
  384. inputValue: '',
  385. pageNo: 1,
  386. replyList: [],
  387. })
  388. this.getReply();
  389. });
  390. // 评论成功后刷新数据
  391. }
  392. },
  393. // 触底加载
  394. onReachBottom: function () {
  395. // 当前在推荐页面 加载推荐
  396. if (this.data.pageNo <= this.data.totalPage) {
  397. this.setData({
  398. pageNo: this.data.pageNo + 1
  399. }, () => {
  400. this.getReply();
  401. })
  402. }
  403. },
  404. // 设置点击时的id
  405. setSBId: function (e) {
  406. this.setData({
  407. replySBId: e.currentTarget.dataset.id,
  408. replyModal: true,
  409. replyIndex: e.currentTarget.dataset.index
  410. })
  411. },
  412. // 回复某个评论
  413. replySB: function () {
  414. const data = {
  415. postsId: this.data.replySBId,
  416. content: this.data.inputSBValue
  417. }
  418. httpRequestApi.postReplyComment(this.uid, data).success(res => {
  419. const replyWho = this.data.replyList[this.data.replyIndex];
  420. const indexStr = `replyList[${this.data.replyIndex}]`;
  421. replyWho.replyCount++;
  422. this.setData({
  423. replyModal: false,
  424. [indexStr]: replyWho
  425. })
  426. });
  427. },
  428. // 获取回复楼中楼的内容
  429. inputSBValue: function (e) {
  430. this.setData({
  431. inputSBValue: e.detail.value
  432. });
  433. },
  434. // 选择金额
  435. setMoney: function (e) {
  436. this.setData({
  437. howMuch: e.currentTarget.dataset.money
  438. })
  439. },
  440. reward: function () {
  441. // if(this.data.isIOS){
  442. // wx.showToast({
  443. // title: '奖励成功!',
  444. // icon: 'success',
  445. // duration: 1000
  446. // })
  447. // return
  448. // };
  449. this.setData({
  450. ifReward: true
  451. })
  452. },
  453. quitReward: function () {
  454. this.setData({
  455. ifReward: false
  456. })
  457. },
  458. // 奖励
  459. rewardMoney: function () {
  460. const data = {
  461. targetUid: this.data.authorUid,
  462. amount: this.data.howMuch
  463. }
  464. // let uid = wx.getStorageSync('uid');
  465. httpRequestApi.rewardMoney(this.uid, data).success(res => {
  466. if (res.data.message) {
  467. wx.showModal({
  468. title: '提示',
  469. content: res.data.message,
  470. success(res) {
  471. if (res.confirm) {
  472. console.log('用户点击确定')
  473. } else if (res.cancel) {
  474. console.log('用户点击取消')
  475. }
  476. }
  477. })
  478. return false;
  479. }
  480. this.payMoney(res.data.data);
  481. })
  482. },
  483. //支付
  484. payMoney: function (orderInfo) {
  485. wx.requestPayment({
  486. 'appId': orderInfo.appId,
  487. 'timeStamp': orderInfo.timeStamp,
  488. 'nonceStr': orderInfo.nonceStr,
  489. 'package': orderInfo.package,
  490. 'signType': orderInfo.signType,
  491. 'paySign': orderInfo.sign,
  492. 'success': res => {
  493. this.setData({
  494. modalType: 'image',
  495. isModalShow: true,
  496. modalCloseShow: false,
  497. modalBtnText: '确定'
  498. })
  499. // wx.showModal({
  500. // title: '提示',
  501. // content: '支付成功',
  502. // success(res) {
  503. // if (res.confirm) {
  504. // this.setData({
  505. // ifReward: false
  506. // })
  507. // } else if (res.cancel) {
  508. // this.setData({
  509. // ifReward: false
  510. // })
  511. // }
  512. // }
  513. // })
  514. },
  515. 'fail': function (res) {
  516. this.setData({
  517. ifReward: false
  518. })
  519. console.log('支付失败', res)
  520. }
  521. })
  522. },
  523. // 回到首页
  524. goBackHome: function () {
  525. wx.redirectTo({
  526. url: '../../index/index'
  527. })
  528. },
  529. modalConfirmHandler: function () {
  530. if (this.data.modalType === 'image') {
  531. this.setData({
  532. modalType: 'text',
  533. isModalShow: false,
  534. ifReward: false,
  535. modalCloseShow: true,
  536. modalBtnText: "去开团"
  537. })
  538. return false
  539. }
  540. this.setData({
  541. isModalShow: false
  542. })
  543. wx.navigateTo({
  544. url: `../../groupPage/grade-details/grade-details?productId=${this.data.productId}`
  545. })
  546. },
  547. modalCloseHandler: function () {
  548. this.setData({
  549. isModalShow: false
  550. })
  551. },
  552. })