works.js 11 KB

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