works.js 7.3 KB

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