works.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. import httpRequestApi from '../../../utils/APIClient';
  2. import {
  3. formatDate
  4. } from '../../../utils/util';
  5. Page({
  6. data: {
  7. fullScreenBtn: false,
  8. playBtn: false,
  9. gesture: true,
  10. author: '',
  11. videoSrc: '',
  12. total: '',
  13. authorAvatar: '',
  14. user: [],
  15. inputValue: '',
  16. inputSBValue: '',
  17. replyList: [],
  18. howMuch: '200',
  19. moneySelect: 'moneySelect',
  20. moneyNormal: 'moneyNormal',
  21. ifReward: false,
  22. id: '',
  23. path: '',
  24. replyModal: false,
  25. totalRead: 0,
  26. pageNo: 1,
  27. pageSize: 2,
  28. goBackHome: false
  29. // shareFlag: false
  30. },
  31. onLoad: function (option) {
  32. console.log(option)
  33. let id = option.id ? option.id : option.scene.replace('QR', '')
  34. if(option.scene || option.shareCard ){
  35. this.setData({
  36. goBackHome: true
  37. })
  38. }
  39. wx.setNavigationBarTitle({
  40. title: option.title //页面标题为路由参数
  41. })
  42. this.uid = wx.getStorageSync('uid');
  43. this.setData({
  44. title: option.title,
  45. id,
  46. myUid: this.uid
  47. })
  48. this.getWorks(this.uid, id);
  49. },
  50. onHide: function () {
  51. if (this.innerAudioContext) {
  52. this.innerAudioContext.stop();
  53. }
  54. let videoCtx = wx.createVideoContext('worksVideo',this);
  55. videoCtx.stop();
  56. },
  57. onUnload: function () {
  58. if (this.innerAudioContext) {
  59. this.innerAudioContext.stop();
  60. }
  61. let videoCtx = wx.createVideoContext('worksVideo',this);
  62. videoCtx.stop();
  63. },
  64. getWorks: function (uid, id) {
  65. httpRequestApi.getWorksDetail(uid, id).success((res) => {
  66. console.log(res);
  67. console.log(id);
  68. const others = res.data.data.otherRead;
  69. const author = res.data.data.user;
  70. const works = res.data.data.userRead;
  71. const othersTemp = [];
  72. others.forEach((item) => {
  73. const temp = {};
  74. temp.uid = item.userRead.id;
  75. temp.title = item.userRead.title;
  76. temp.image = item.user.avatar;
  77. temp.nickName = item.user.wechatName;
  78. othersTemp.push(temp);
  79. });
  80. this.setData({
  81. user: othersTemp,
  82. totalRead: res.data.data.totalRead,
  83. author: author.wechatName,
  84. authorAvatar: author.avatar,
  85. authorUid: author.uid,
  86. videoSrc: works.originVideo,
  87. audioSrc: works.audioPath,
  88. iconImg: works.iconImg,
  89. classId: works.lessonId,
  90. isLike: res.data.data.isLike,
  91. isFans: res.data.data.isFans,
  92. })
  93. // 设置音频路径
  94. this.innerAudioContext = wx.createInnerAudioContext();
  95. this.innerAudioContext.onError((res) => {
  96. // 播放音频失败的回调
  97. })
  98. this.innerAudioContext.src = this.data.audioSrc; // 这里可以是录音的临时路径
  99. });
  100. },
  101. onShow(options) {
  102. console.log(options)
  103. this.setData({
  104. replyList: [],
  105. pageNo: 1,
  106. pageSize: 2
  107. }, () => {
  108. this.getReply();
  109. })
  110. },
  111. likeWorks: function (e) {
  112. if (this.data.isLike) {
  113. wx.showToast({
  114. title: '不要重复点赞哦',
  115. icon: 'fail',
  116. duration: 1000
  117. })
  118. return;
  119. }
  120. httpRequestApi.likeWorks(this.uid, this.data.id).success(res => {
  121. this.setData({
  122. isLike: true
  123. }, () => {
  124. wx.showToast({
  125. title: '点赞数+1',
  126. icon: 'success',
  127. duration: 1000
  128. })
  129. });
  130. })
  131. },
  132. // 弹出分享框
  133. openShare: function (e) {
  134. // this.setData({
  135. // shareFlag: !this.data.shareFlag
  136. // })
  137. this.shareDialog = this.selectComponent("#share-dialog");
  138. const data = {
  139. avatar: this.data.authorAvatar,
  140. author: this.data.author,
  141. iconImg: this.data.iconImg,
  142. title: this.data.title,
  143. path: `pages/social/works/works`,
  144. scene: this.data.id
  145. // tip: this.data.tip,
  146. }
  147. this.shareDialog.share(data);
  148. },
  149. videoPlay: function () {
  150. this.innerAudioContext.play();
  151. httpRequestApi.playWorks(this.uid, this.data.id).success(res => {
  152. })
  153. },
  154. videoEnd: function () {
  155. this.innerAudioContext.stop();
  156. },
  157. videoPause: function () {
  158. this.innerAudioContext.pause();
  159. },
  160. goToReading: function () {
  161. // wx.navigateTo({
  162. // url: `../../main/reading/reading?id=${this.data.classId}`
  163. // })
  164. const classId = this.data.classId;
  165. httpRequestApi.checkLesson(classId).success(res => {
  166. const productId = res.data.data[0];
  167. httpRequestApi.areYouSuper(res.data.data).success(res => {
  168. if (res.data.success) {
  169. wx.navigateTo({
  170. url: `../../main/reading/reading?id=${classId}`
  171. })
  172. } else {
  173. wx.showModal({
  174. title: '您未购买过本书,不能朗读',
  175. content: '超值团购进行中,快去看看',
  176. success(res) {
  177. if (res.confirm) {
  178. console.log('用户点击确定')
  179. wx.navigateTo({
  180. url: `../../groupPage/grade-details/grade-details?productId=${productId}`
  181. })
  182. } else if (res.cancel) {
  183. console.log('用户点击取消')
  184. }
  185. }
  186. })
  187. }
  188. })
  189. });
  190. },
  191. onShareAppMessage: function (res) {
  192. if (res.from === 'button') {
  193. // 来自页面内转发按钮
  194. console.log(res.target)
  195. }
  196. return {
  197. title: '一样的课文,不一样的味道!我的配音表演已开始,求各位大咖围观、点评!',
  198. path: `pages/social/works/works?id=${this.data.id}&title=${this.data.title}&shareCard=true`,
  199. imageUrl: this.data.iconImg
  200. }
  201. },
  202. follow: function () {
  203. // let uid = wx.getStorageSync('uid');
  204. let followUid = this.data.authorUid;
  205. if (this.data.isFans) {
  206. httpRequestApi.cancerFollow(this.uid, followUid).success((res) => {
  207. this.setData({
  208. isFans: false
  209. })
  210. wx.showToast({
  211. title: '取消关注',
  212. icon: 'success',
  213. duration: 1000
  214. })
  215. });
  216. } else {
  217. httpRequestApi.followUser(this.uid, followUid).success((res) => {
  218. this.setData({
  219. isFans: true
  220. })
  221. wx.showToast({
  222. title: '关注啦',
  223. icon: 'success',
  224. duration: 1000
  225. })
  226. });
  227. }
  228. },
  229. // 点赞评论
  230. likeCommend: function (e) {
  231. console.log(e);
  232. // let uid = wx.getStorageSync('uid');
  233. let followUid = e.currentTarget.dataset.id;
  234. let index = e.currentTarget.dataset.index;
  235. httpRequestApi.likeCommend(this.uid, followUid).success(res => {
  236. console.log(res);
  237. const str = `replyList[${index}].likes`;
  238. this.setData({
  239. [str]: res.data.data.favors
  240. })
  241. });
  242. },
  243. // 去其他用户的作品页
  244. goToOthers: function (e) {
  245. wx.navigateTo({
  246. url: `../../social/works/works?id=${e.currentTarget.dataset.uid}&title=${e.currentTarget.dataset.title}`
  247. })
  248. },
  249. // 查询回复
  250. getReply: function () {
  251. // let uid = wx.getStorageSync('uid');
  252. let columnId = this.data.id;
  253. let pageNo = this.data.pageNo;
  254. let pageSize = this.data.pageSize;
  255. httpRequestApi.getReply(this.uid, columnId, pageNo, pageSize).success((res) => {
  256. console.log(res.data.data.list);
  257. const replyList = res.data.data.list;
  258. // const replyTemp = [];
  259. replyList.forEach((item) => {
  260. const temp = {};
  261. temp.nickName = item.user.wechatName;
  262. temp.avatar = item.user.avatar;
  263. temp.text = item.detailDesc;
  264. temp.id = item.id;
  265. temp.replyCount = item.replyCount;
  266. temp.time = formatDate(item.gmtModified, 3);
  267. temp.likes = item.postsAttributeInfo.favors || 0;
  268. console.log(temp.time)
  269. this.data.replyList.push(temp);
  270. });
  271. this.setData({
  272. replyList: this.data.replyList,
  273. total: res.data.data.totalSize,
  274. totalPage: res.data.data.totalNo
  275. })
  276. });
  277. },
  278. // 打开回复详情页
  279. goToDetail: function (e) {
  280. let id = e.currentTarget.dataset.id;
  281. let count = e.currentTarget.dataset.count;
  282. console.log(e);
  283. wx.navigateTo({
  284. url: `../../social/replyDetail/replyDetail?id=${id}&count=${count}`
  285. })
  286. },
  287. // 绑定输入框内容
  288. inputValue: function (e) {
  289. this.setData({
  290. inputValue: e.detail.value
  291. });
  292. },
  293. // 发布回复
  294. sendHandler: function () {
  295. console.log(this.data.inputValue);
  296. if (this.data.inputValue !== '') {
  297. // let uid = wx.getStorageSync('uid');
  298. let data = {
  299. "columnId": this.data.id,
  300. colunmNames: 'what',
  301. "detailDesc": this.data.inputValue
  302. }
  303. httpRequestApi.postReply(this.uid, data).success(res => {
  304. console.log(res);
  305. this.setData({
  306. inputValue: ''
  307. })
  308. this.getReply();
  309. });
  310. // 评论成功后刷新数据
  311. }
  312. },
  313. // 触底加载
  314. onReachBottom: function () {
  315. // 当前在推荐页面 加载推荐
  316. if (this.data.pageNo <= this.data.totalPage) {
  317. this.setData({
  318. pageNo: this.data.pageNo + 1
  319. }, () => {
  320. this.getReply();
  321. })
  322. }
  323. },
  324. // 设置点击时的id
  325. setSBId: function (e) {
  326. console.log(e)
  327. this.setData({
  328. replySBId: e.currentTarget.dataset.id,
  329. replyModal: true,
  330. replyIndex: e.currentTarget.dataset.index
  331. })
  332. },
  333. // 回复某个评论
  334. replySB: function () {
  335. const data = {
  336. postsId: this.data.replySBId,
  337. content: this.data.inputSBValue
  338. }
  339. httpRequestApi.postReplyComment(this.uid, data).success(res => {
  340. console.log(res)
  341. const replyWho = this.data.replyList[this.data.replyIndex];
  342. const indexStr = `replyList[${this.data.replyIndex}]`;
  343. replyWho.replyCount++;
  344. this.setData({
  345. replyModal: false,
  346. [indexStr]: replyWho
  347. })
  348. });
  349. },
  350. // 获取回复楼中楼的内容
  351. inputSBValue: function (e) {
  352. this.setData({
  353. inputSBValue: e.detail.value
  354. });
  355. },
  356. // 选择金额
  357. setMoney: function (e) {
  358. this.setData({
  359. howMuch: e.currentTarget.dataset.money
  360. })
  361. },
  362. reward: function () {
  363. this.setData({
  364. ifReward: true
  365. })
  366. },
  367. quitReward: function () {
  368. this.setData({
  369. ifReward: false
  370. })
  371. },
  372. // 奖励
  373. rewardMoney: function () {
  374. console.log(this.data.authorUid);
  375. const data = {
  376. targetUid: this.data.authorUid,
  377. amount: this.data.howMuch
  378. }
  379. // let uid = wx.getStorageSync('uid');
  380. httpRequestApi.rewardMoney(this.uid, data).success(res => {
  381. console.log(res);
  382. this.payMoneyt(res.data.data);
  383. })
  384. },
  385. //支付
  386. payMoneyt: function (orderInfo) {
  387. wx.requestPayment({
  388. 'appId': orderInfo.appId,
  389. 'timeStamp': orderInfo.timeStamp,
  390. 'nonceStr': orderInfo.nonceStr,
  391. 'package': orderInfo.package,
  392. 'signType': orderInfo.signType,
  393. 'paySign': orderInfo.sign,
  394. 'success': function (res) {
  395. console.log(res)
  396. wx.showModal({
  397. title: '提示',
  398. content: '支付成功',
  399. success(res) {
  400. if (res.confirm) {
  401. this.setData({
  402. ifReward: false
  403. })
  404. } else if (res.cancel) {
  405. this.setData({
  406. ifReward: false
  407. })
  408. }
  409. }
  410. })
  411. },
  412. 'fail': function (res) {
  413. this.setData({
  414. ifReward: false
  415. })
  416. console.log('支付失败', res)
  417. }
  418. })
  419. },
  420. // 回到首页
  421. goBackHome: function(){
  422. wx.redirectTo({
  423. url: '../../index/index'
  424. })
  425. }
  426. })