works.js 10 KB

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