works.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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`,
  109. scene: `QR${this.data.id}`
  110. // tip: this.data.tip,
  111. }
  112. this.shareDialog.share(data);
  113. },
  114. videoPlay: function () {
  115. this.innerAudioContext.play();
  116. httpRequestApi.playWorks(this.uid, this.data.id).success(res => {
  117. })
  118. },
  119. videoEnd: function () {
  120. this.innerAudioContext.stop();
  121. },
  122. videoPause: function () {
  123. this.innerAudioContext.pause();
  124. },
  125. goToReading: function () {
  126. let id = this.data.id;
  127. let title = this.data.title;
  128. wx.navigateTo({
  129. url: `../../main/reading/reading?id=${this.data.classId}`
  130. })
  131. },
  132. onShareAppMessage: function (res) {
  133. if (res.from === 'button') {
  134. // 来自页面内转发按钮
  135. console.log(res.target)
  136. }
  137. return {
  138. title: this.data.title,
  139. path: `pages/social/works/works?id=${this.data.id}&title=${this.data.title}`,
  140. imageUrl: this.data.iconImg
  141. }
  142. },
  143. follow: function () {
  144. // let uid = wx.getStorageSync('uid');
  145. let followUid = this.data.authorUid;
  146. if (this.data.isFans) {
  147. httpRequestApi.cancerFollow(this.uid, followUid).success((res) => {
  148. this.setData({
  149. isFans: false
  150. })
  151. wx.showToast({
  152. title: '取消关注',
  153. icon: 'success',
  154. duration: 1000
  155. })
  156. });
  157. } else {
  158. httpRequestApi.followUser(this.uid, followUid).success((res) => {
  159. this.setData({
  160. isFans: true
  161. })
  162. wx.showToast({
  163. title: '关注啦',
  164. icon: 'success',
  165. duration: 1000
  166. })
  167. });
  168. }
  169. },
  170. // 点赞评论
  171. likeCommend: function (e) {
  172. console.log(e);
  173. // let uid = wx.getStorageSync('uid');
  174. let followUid = e.currentTarget.dataset.id;
  175. let index = e.currentTarget.dataset.index;
  176. httpRequestApi.likeCommend(this.uid, followUid).success(res => {
  177. console.log(res);
  178. const str = `replyList[${index}].likes`;
  179. this.setData({
  180. [str]: res.data.data.favors
  181. })
  182. });
  183. },
  184. // 去其他用户的作品页
  185. goToOthers: function (e) {
  186. wx.navigateTo({
  187. url: `../../main/reading/reading?id=${id}&title=${title}`
  188. })
  189. },
  190. // 查询回复
  191. getReply: function () {
  192. // let uid = wx.getStorageSync('uid');
  193. let columnId = this.data.id;
  194. let pageNo = 1;
  195. let pageSize = 10;
  196. httpRequestApi.getReply(this.uid, columnId, pageNo, pageSize).success((res) => {
  197. console.log(res.data.data.list);
  198. const replyList = res.data.data.list;
  199. const replyTemp = [];
  200. replyList.forEach((item) => {
  201. const temp = {};
  202. temp.nickName = item.user.wechatName;
  203. temp.avatar = item.user.avatar;
  204. temp.text = item.detailDesc;
  205. temp.id = item.id;
  206. temp.replyCount = item.replyCount;
  207. temp.time = formatDate(item.gmtModified, 3);
  208. temp.likes = item.postsAttributeInfo.favors || 0;
  209. console.log(temp.time)
  210. replyTemp.push(temp);
  211. });
  212. this.setData({
  213. replyList: replyTemp,
  214. total: res.data.data.totalSize
  215. })
  216. });
  217. },
  218. // 打开回复详情页
  219. goToDetail: function (e) {
  220. let id = e.currentTarget.dataset.id;
  221. let count = e.currentTarget.dataset.count;
  222. console.log(e);
  223. wx.navigateTo({
  224. url: `../../social/replyDetail/replyDetail?id=${id}&count=${count}`
  225. })
  226. },
  227. // 绑定输入框内容
  228. inputValue: function (e) {
  229. this.setData({
  230. inputValue: e.detail.value
  231. });
  232. },
  233. // 发布回复
  234. sendHandler: function () {
  235. console.log(this.data.inputValue);
  236. if (this.data.inputValue !== '') {
  237. // let uid = wx.getStorageSync('uid');
  238. let data = {
  239. "columnId": this.data.id,
  240. colunmNames: 'what',
  241. "detailDesc": this.data.inputValue
  242. }
  243. httpRequestApi.postReply(this.uid, data).success(res => {
  244. console.log(res);
  245. });
  246. }
  247. },
  248. // 设置点击时的id
  249. setSBId: function (e) {
  250. console.log(e)
  251. this.setData({
  252. replySBId: e.currentTarget.dataset.id,
  253. replyModal: true
  254. })
  255. },
  256. // 回复某个评论
  257. replySB: function () {
  258. const data = {
  259. postsId: this.data.replySBId,
  260. content: this.data.inputSBValue
  261. }
  262. httpRequestApi.postReplyComment(this.uid, data).success(res => {
  263. this.setData({
  264. replyModal: false
  265. })
  266. });
  267. },
  268. // 获取回复楼中楼的内容
  269. inputSBValue: function (e) {
  270. this.setData({
  271. inputSBValue: e.detail.value
  272. });
  273. },
  274. // 选择金额
  275. setMoney: function (e) {
  276. this.setData({
  277. howMuch: e.currentTarget.dataset.money
  278. })
  279. },
  280. reward: function () {
  281. this.setData({
  282. ifReward: true
  283. })
  284. },
  285. quitReward: function () {
  286. this.setData({
  287. ifReward: false
  288. })
  289. },
  290. // 奖励
  291. rewardMoney: function () {
  292. console.log(this.data.authorUid);
  293. const data = {
  294. targetUid: this.data.authorUid,
  295. amount: this.data.howMuch
  296. }
  297. // let uid = wx.getStorageSync('uid');
  298. httpRequestApi.rewardMoney(this.uid, data).success(res => {
  299. console.log(res);
  300. this.payMoneyt(res.data.data);
  301. })
  302. },
  303. //支付
  304. payMoneyt: function (orderInfo) {
  305. wx.requestPayment({
  306. 'appId': orderInfo.appId,
  307. 'timeStamp': orderInfo.timeStamp,
  308. 'nonceStr': orderInfo.nonceStr,
  309. 'package': orderInfo.package,
  310. 'signType': orderInfo.signType,
  311. 'paySign': orderInfo.sign,
  312. 'success': function (res) {
  313. console.log(res)
  314. wx.showModal({
  315. title: '提示',
  316. content: '支付成功',
  317. success(res) {
  318. if (res.confirm) {
  319. this.setData({
  320. ifReward: false
  321. })
  322. } else if (res.cancel) {
  323. this.setData({
  324. ifReward: false
  325. })
  326. }
  327. }
  328. })
  329. },
  330. 'fail': function (res) {
  331. this.setData({
  332. ifReward: false
  333. })
  334. console.log('支付失败', res)
  335. }
  336. })
  337. },
  338. })