works.js 11 KB

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