works.js 13 KB

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