works.js 8.1 KB

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