works.js 11 KB

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