works.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. },
  21. onLoad: function (option) {
  22. if (option.title) {
  23. wx.setNavigationBarTitle({
  24. title: option.title //页面标题为路由参数
  25. })
  26. this.setData({
  27. title: option.title,
  28. id: option.id
  29. })
  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. goToOthers: function (e) {
  98. wx.navigateTo({
  99. url: `../../main/reading/reading?id=${id}&title=${title}`
  100. })
  101. },
  102. // 查询回复
  103. getReply: function () {
  104. let uid = wx.getStorageSync('uid');
  105. let columnId = this.data.id;
  106. let pageNo = 1;
  107. let pageSize = 10;
  108. httpRequestApi.getReply(uid, columnId, pageNo, pageSize).success((res) => {
  109. console.log(res.data.data.list);
  110. const replyList = res.data.data.list;
  111. const replyTemp = [];
  112. replyList.forEach((item) => {
  113. const temp = {};
  114. temp.nickName = item.user.wechatName;
  115. temp.avatar = item.user.avatar;
  116. temp.text = item.detailDesc;
  117. temp.id = item.id;
  118. temp.replyCount = item.replyCount;
  119. temp.time = formatDate(item.gmtCreated, 3);
  120. console.log(temp.time)
  121. replyTemp.push(temp);
  122. });
  123. this.setData({
  124. replyList: replyTemp,
  125. total: res.data.data.totalSize
  126. })
  127. });
  128. },
  129. // 打开回复详情页
  130. goToDetail: function (e) {
  131. let id = e.currentTarget.dataset.id;
  132. let count = e.currentTarget.dataset.count;
  133. console.log(e);
  134. wx.navigateTo({
  135. url: `../../social/replyDetail/replyDetail?id=${id}&count=${count}`
  136. })
  137. },
  138. // 绑定输入框内容
  139. inputValue: function (e) {
  140. this.setData({
  141. inputValue: e.detail.value
  142. });
  143. },
  144. // 发布回复
  145. sendHandler: function () {
  146. console.log(this.data.inputValue);
  147. if (this.data.inputValue !== '') {
  148. let uid = wx.getStorageSync('uid');
  149. let data = {
  150. "columnId": this.data.id,
  151. colunmNames: 'what',
  152. "detailDesc": this.data.inputValue
  153. }
  154. httpRequestApi.postReply(uid, data).success(res => {
  155. console.log(res);
  156. });
  157. }
  158. },
  159. // 选择金额
  160. setMoney: function(e){
  161. this.setData({
  162. howMuch: e.currentTarget.dataset.money
  163. })
  164. },
  165. // 奖励
  166. rewardMoney: function () {
  167. console.log(this.data.authorUid);
  168. const data = {
  169. targetUid: this.data.authorUid,
  170. amount: "50"
  171. }
  172. let uid = wx.getStorageSync('uid');
  173. httpRequestApi.rewardMoney(uid, data).success(res => {
  174. console.log(res);
  175. this.payMoneyt(res.data.data);
  176. })
  177. },
  178. //支付
  179. payMoneyt: function (orderInfo) {
  180. wx.requestPayment({
  181. 'appId': orderInfo.appId,
  182. 'timeStamp': orderInfo.timeStamp,
  183. 'nonceStr': orderInfo.nonceStr,
  184. 'package': orderInfo.package,
  185. 'signType': orderInfo.signType,
  186. 'paySign': orderInfo.sign,
  187. 'success': function (res) {
  188. console.log(res)
  189. wx.showModal({
  190. title: '提示',
  191. content: '支付成功',
  192. success(res) {
  193. if (res.confirm) {
  194. console.log('点击确定')
  195. } else if (res.cancel) {
  196. console.log('取消')
  197. }
  198. }
  199. })
  200. },
  201. 'fail': function (res) {
  202. console.log('支付失败', res)
  203. }
  204. })
  205. },
  206. })