works.js 12 KB

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