works.js 10 KB

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