works.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. import httpRequestApi from '../../../utils/APIClient';
  2. import {
  3. formatDate
  4. } from '../../../utils/util';
  5. const app = getApp()
  6. Page({
  7. data: {
  8. fullScreenBtn: false,
  9. playBtn: false,
  10. gesture: true,
  11. author: '',
  12. videoSrc: '',
  13. total: '',
  14. authorAvatar: '',
  15. user: [],
  16. inputValue: '',
  17. inputSBValue: '',
  18. replyList: [],
  19. howMuch: '200',
  20. moneySelect: 'moneySelect',
  21. moneyNormal: 'moneyNormal',
  22. ifReward: false,
  23. id: '',
  24. path: '',
  25. replyModal: false,
  26. totalRead: 0,
  27. pageNo: 1,
  28. pageSize: 3,
  29. goBackHome: false,
  30. isIOS: app.globalData.isIOS
  31. // shareFlag: false
  32. },
  33. onLoad: function (option) {
  34. console.log(option)
  35. let id = option.id ? option.id : option.scene.replace('QR', '')
  36. if(option.scene || option.shareCard ){
  37. this.setData({
  38. goBackHome: true
  39. })
  40. }
  41. wx.setNavigationBarTitle({
  42. title: option.title //页面标题为路由参数
  43. })
  44. this.uid = wx.getStorageSync('uid');
  45. this.setData({
  46. title: option.title,
  47. id,
  48. myUid: this.uid
  49. })
  50. this.getWorks(this.uid, id);
  51. },
  52. onHide: function () {
  53. if (this.innerAudioContext) {
  54. this.innerAudioContext.stop();
  55. }
  56. let videoCtx = wx.createVideoContext('worksVideo',this);
  57. videoCtx.stop();
  58. },
  59. onUnload: function () {
  60. if (this.innerAudioContext) {
  61. this.innerAudioContext.stop();
  62. }
  63. let videoCtx = wx.createVideoContext('worksVideo',this);
  64. videoCtx.stop();
  65. },
  66. getWorks: function (uid, id) {
  67. httpRequestApi.getWorksDetail(uid, id).success((res) => {
  68. console.log(res);
  69. console.log(id);
  70. const others = res.data.data.otherRead;
  71. const author = res.data.data.user;
  72. const works = res.data.data.userRead;
  73. const othersTemp = [];
  74. others.forEach((item) => {
  75. const temp = {};
  76. temp.uid = item.userRead.id;
  77. temp.title = item.userRead.title;
  78. temp.image = item.user.avatar;
  79. temp.nickName = item.user.wechatName;
  80. othersTemp.push(temp);
  81. });
  82. this.setData({
  83. user: othersTemp,
  84. totalRead: res.data.data.totalRead,
  85. author: author.wechatName,
  86. authorAvatar: author.avatar,
  87. authorUid: author.uid,
  88. videoSrc: works.originVideo,
  89. audioSrc: works.audioPath,
  90. iconImg: works.iconImg,
  91. classId: works.lessonId,
  92. isLike: res.data.data.isLike,
  93. isFans: res.data.data.isFans,
  94. })
  95. // 设置音频路径
  96. this.innerAudioContext = wx.createInnerAudioContext();
  97. this.innerAudioContext.onError((res) => {
  98. // 播放音频失败的回调
  99. })
  100. this.innerAudioContext.src = this.data.audioSrc; // 这里可以是录音的临时路径
  101. });
  102. },
  103. onShow(options) {
  104. console.log(options)
  105. this.setData({
  106. replyList: [],
  107. pageNo: 1,
  108. pageSize: 2
  109. }, () => {
  110. this.getReply();
  111. })
  112. },
  113. likeWorks: function (e) {
  114. if (this.data.isLike) {
  115. wx.showToast({
  116. title: '不要重复点赞哦',
  117. icon: 'fail',
  118. duration: 1000
  119. })
  120. return;
  121. }
  122. httpRequestApi.likeWorks(this.uid, this.data.id).success(res => {
  123. this.setData({
  124. isLike: true
  125. }, () => {
  126. wx.showToast({
  127. title: '点赞数+1',
  128. icon: 'success',
  129. duration: 1000
  130. })
  131. });
  132. })
  133. },
  134. // 弹出分享框
  135. openShare: function (e) {
  136. this.shareDialog = this.selectComponent("#share-dialog");
  137. const data = {
  138. avatar: this.data.authorAvatar,
  139. author: this.data.author,
  140. iconImg: this.data.iconImg,
  141. title: this.data.title,
  142. path: `pages/social/works/works`,
  143. scene: this.data.id
  144. // tip: this.data.tip,
  145. }
  146. this.shareDialog.share(data);
  147. },
  148. videoPlay: function () {
  149. this.innerAudioContext.play();
  150. httpRequestApi.playWorks(this.uid, this.data.id).success(res => {
  151. })
  152. },
  153. videoEnd: function () {
  154. this.innerAudioContext.stop();
  155. },
  156. videoPause: function () {
  157. this.innerAudioContext.pause();
  158. },
  159. goToReading: function () {
  160. const classId = this.data.classId;
  161. httpRequestApi.checkLesson(classId).success(res => {
  162. const productId = res.data.data[0];
  163. httpRequestApi.areYouSuper(res.data.data).success(res => {
  164. if (res.data.success) {
  165. wx.navigateTo({
  166. url: `../../main/reading/reading?id=${classId}`
  167. })
  168. } else {
  169. // ios用户 并且没有购买过此书
  170. if(this.data.isIOS){
  171. wx.showModal({
  172. title: '暂不支持',
  173. content: '十分抱歉,由于相关规定,您暂时无法在这里朗读',
  174. success(res) {
  175. if (res.confirm) {
  176. console.log('用户点击确定')
  177. } else if (res.cancel) {
  178. console.log('用户点击取消')
  179. }
  180. }
  181. })
  182. return;
  183. }
  184. wx.showModal({
  185. title: '您未购买过本书,不能朗读',
  186. content: '超值团购进行中,快去看看',
  187. success(res) {
  188. if (res.confirm) {
  189. console.log('用户点击确定')
  190. wx.navigateTo({
  191. url: `../../groupPage/grade-details/grade-details?productId=${productId}`
  192. })
  193. } else if (res.cancel) {
  194. console.log('用户点击取消')
  195. }
  196. }
  197. })
  198. }
  199. })
  200. });
  201. },
  202. onShareAppMessage: function (res) {
  203. if (res.from === 'button') {
  204. // 来自页面内转发按钮
  205. console.log(res.target)
  206. }
  207. return {
  208. title: '一样的课文,不一样的味道!我的配音表演已开始,求各位大咖围观、点评!',
  209. path: `pages/social/works/works?id=${this.data.id}&title=${this.data.title}&shareCard=true`,
  210. imageUrl: '../../../static/share/works_icon.jpg'
  211. }
  212. },
  213. follow: function () {
  214. let followUid = this.data.authorUid;
  215. if (this.data.isFans) {
  216. httpRequestApi.cancerFollow(this.uid, followUid).success((res) => {
  217. this.setData({
  218. isFans: false
  219. })
  220. wx.showToast({
  221. title: '取消关注',
  222. icon: 'success',
  223. duration: 1000
  224. })
  225. });
  226. } else {
  227. httpRequestApi.followUser(this.uid, followUid).success((res) => {
  228. this.setData({
  229. isFans: true
  230. })
  231. wx.showToast({
  232. title: '关注啦',
  233. icon: 'success',
  234. duration: 1000
  235. })
  236. });
  237. }
  238. },
  239. // 点赞评论
  240. likeCommend: function (e) {
  241. console.log(e);
  242. // let uid = wx.getStorageSync('uid');
  243. let followUid = e.currentTarget.dataset.id;
  244. let index = e.currentTarget.dataset.index;
  245. httpRequestApi.likeCommend(this.uid, followUid).success(res => {
  246. console.log(res);
  247. const str = `replyList[${index}].likes`;
  248. this.setData({
  249. [str]: res.data.data.favors
  250. })
  251. });
  252. },
  253. // 去其他用户的作品页
  254. goToOthers: function (e) {
  255. wx.navigateTo({
  256. url: `../../social/works/works?id=${e.currentTarget.dataset.uid}&title=${e.currentTarget.dataset.title}`
  257. })
  258. },
  259. // 查询回复
  260. getReply: function () {
  261. // let uid = wx.getStorageSync('uid');
  262. let columnId = this.data.id;
  263. let pageNo = this.data.pageNo;
  264. let pageSize = this.data.pageSize;
  265. httpRequestApi.getReply(this.uid, columnId, pageNo, pageSize).success((res) => {
  266. console.log(res.data.data.list);
  267. const replyList = res.data.data.list;
  268. // const replyTemp = [];
  269. replyList.forEach((item) => {
  270. const temp = {};
  271. temp.nickName = item.user.wechatName;
  272. temp.avatar = item.user.avatar;
  273. temp.text = item.detailDesc;
  274. temp.id = item.id;
  275. temp.replyCount = item.replyCount;
  276. temp.time = formatDate(item.gmtModified, 3);
  277. temp.likes = item.postsAttributeInfo.favors || 0;
  278. console.log(temp.time)
  279. this.data.replyList.push(temp);
  280. });
  281. this.setData({
  282. replyList: this.data.replyList,
  283. total: res.data.data.totalSize,
  284. totalPage: res.data.data.totalNo
  285. })
  286. });
  287. },
  288. // 打开回复详情页
  289. goToDetail: function (e) {
  290. let id = e.currentTarget.dataset.id;
  291. let count = e.currentTarget.dataset.count;
  292. console.log(e);
  293. wx.navigateTo({
  294. url: `../../social/replyDetail/replyDetail?id=${id}&count=${count}`
  295. })
  296. },
  297. // 绑定输入框内容
  298. inputValue: function (e) {
  299. this.setData({
  300. inputValue: e.detail.value
  301. });
  302. },
  303. // 发布回复
  304. sendHandler: function () {
  305. console.log(this.data.inputValue);
  306. if (this.data.inputValue !== '') {
  307. // let uid = wx.getStorageSync('uid');
  308. let data = {
  309. "columnId": this.data.id,
  310. colunmNames: 'what',
  311. "detailDesc": this.data.inputValue
  312. }
  313. httpRequestApi.postReply(this.uid, data).success(res => {
  314. console.log(res);
  315. this.setData({
  316. inputValue: '',
  317. pageNo: 1,
  318. replyList: [],
  319. })
  320. this.getReply();
  321. });
  322. // 评论成功后刷新数据
  323. }
  324. },
  325. // 触底加载
  326. onReachBottom: function () {
  327. // 当前在推荐页面 加载推荐
  328. if (this.data.pageNo <= this.data.totalPage) {
  329. this.setData({
  330. pageNo: this.data.pageNo + 1
  331. }, () => {
  332. this.getReply();
  333. })
  334. }
  335. },
  336. // 设置点击时的id
  337. setSBId: function (e) {
  338. console.log(e)
  339. this.setData({
  340. replySBId: e.currentTarget.dataset.id,
  341. replyModal: true,
  342. replyIndex: e.currentTarget.dataset.index
  343. })
  344. },
  345. // 回复某个评论
  346. replySB: function () {
  347. const data = {
  348. postsId: this.data.replySBId,
  349. content: this.data.inputSBValue
  350. }
  351. httpRequestApi.postReplyComment(this.uid, data).success(res => {
  352. console.log(res)
  353. const replyWho = this.data.replyList[this.data.replyIndex];
  354. const indexStr = `replyList[${this.data.replyIndex}]`;
  355. replyWho.replyCount++;
  356. this.setData({
  357. replyModal: false,
  358. [indexStr]: replyWho
  359. })
  360. });
  361. },
  362. // 获取回复楼中楼的内容
  363. inputSBValue: function (e) {
  364. this.setData({
  365. inputSBValue: e.detail.value
  366. });
  367. },
  368. // 选择金额
  369. setMoney: function (e) {
  370. this.setData({
  371. howMuch: e.currentTarget.dataset.money
  372. })
  373. },
  374. reward: function () {
  375. // if(this.data.isIOS){
  376. // wx.showToast({
  377. // title: '奖励成功!',
  378. // icon: 'success',
  379. // duration: 1000
  380. // })
  381. // return
  382. // };
  383. this.setData({
  384. ifReward: true
  385. })
  386. },
  387. quitReward: function () {
  388. this.setData({
  389. ifReward: false
  390. })
  391. },
  392. // 奖励
  393. rewardMoney: function () {
  394. console.log(this.data.authorUid);
  395. const data = {
  396. targetUid: this.data.authorUid,
  397. amount: this.data.howMuch
  398. }
  399. // let uid = wx.getStorageSync('uid');
  400. httpRequestApi.rewardMoney(this.uid, data).success(res => {
  401. console.log(res);
  402. this.payMoneyt(res.data.data);
  403. })
  404. },
  405. //支付
  406. payMoneyt: function (orderInfo) {
  407. wx.requestPayment({
  408. 'appId': orderInfo.appId,
  409. 'timeStamp': orderInfo.timeStamp,
  410. 'nonceStr': orderInfo.nonceStr,
  411. 'package': orderInfo.package,
  412. 'signType': orderInfo.signType,
  413. 'paySign': orderInfo.sign,
  414. 'success': function (res) {
  415. console.log(res)
  416. wx.showModal({
  417. title: '提示',
  418. content: '支付成功',
  419. success(res) {
  420. if (res.confirm) {
  421. this.setData({
  422. ifReward: false
  423. })
  424. } else if (res.cancel) {
  425. this.setData({
  426. ifReward: false
  427. })
  428. }
  429. }
  430. })
  431. },
  432. 'fail': function (res) {
  433. this.setData({
  434. ifReward: false
  435. })
  436. console.log('支付失败', res)
  437. }
  438. })
  439. },
  440. // 回到首页
  441. goBackHome: function(){
  442. wx.redirectTo({
  443. url: '../../index/index'
  444. })
  445. }
  446. })