works.js 15 KB

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