works.js 13 KB

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