works.js 11 KB

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