works.js 9.6 KB

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