works.js 9.9 KB

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