works.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  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.setData({
  137. // shareFlag: !this.data.shareFlag
  138. // })
  139. this.shareDialog = this.selectComponent("#share-dialog");
  140. const data = {
  141. avatar: this.data.authorAvatar,
  142. author: this.data.author,
  143. iconImg: this.data.iconImg,
  144. title: this.data.title,
  145. path: `pages/social/works/works`,
  146. scene: this.data.id
  147. // tip: this.data.tip,
  148. }
  149. this.shareDialog.share(data);
  150. },
  151. videoPlay: function () {
  152. this.innerAudioContext.play();
  153. httpRequestApi.playWorks(this.uid, this.data.id).success(res => {
  154. })
  155. },
  156. videoEnd: function () {
  157. this.innerAudioContext.stop();
  158. },
  159. videoPause: function () {
  160. this.innerAudioContext.pause();
  161. },
  162. goToReading: function () {
  163. // wx.navigateTo({
  164. // url: `../../main/reading/reading?id=${this.data.classId}`
  165. // })
  166. const classId = this.data.classId;
  167. httpRequestApi.checkLesson(classId).success(res => {
  168. const productId = res.data.data[0];
  169. httpRequestApi.areYouSuper(res.data.data).success(res => {
  170. if (res.data.success) {
  171. wx.navigateTo({
  172. url: `../../main/reading/reading?id=${classId}`
  173. })
  174. } else {
  175. // ios用户 并且没有购买过此书
  176. if(this.data.isIOS){
  177. wx.showModal({
  178. title: '暂不支持',
  179. content: '十分抱歉,由于相关规定,您暂时无法在这里朗读',
  180. success(res) {
  181. if (res.confirm) {
  182. console.log('用户点击确定')
  183. } else if (res.cancel) {
  184. console.log('用户点击取消')
  185. }
  186. }
  187. })
  188. return;
  189. }
  190. wx.showModal({
  191. title: '您未购买过本书,不能朗读',
  192. content: '超值团购进行中,快去看看',
  193. success(res) {
  194. if (res.confirm) {
  195. console.log('用户点击确定')
  196. wx.navigateTo({
  197. url: `../../groupPage/grade-details/grade-details?productId=${productId}`
  198. })
  199. } else if (res.cancel) {
  200. console.log('用户点击取消')
  201. }
  202. }
  203. })
  204. }
  205. })
  206. });
  207. },
  208. onShareAppMessage: function (res) {
  209. if (res.from === 'button') {
  210. // 来自页面内转发按钮
  211. console.log(res.target)
  212. }
  213. return {
  214. title: '一样的课文,不一样的味道!我的配音表演已开始,求各位大咖围观、点评!',
  215. path: `pages/social/works/works?id=${this.data.id}&title=${this.data.title}&shareCard=true`,
  216. imageUrl: '../../../static/share/works_icon.jpg'
  217. }
  218. },
  219. follow: function () {
  220. // let uid = wx.getStorageSync('uid');
  221. let followUid = this.data.authorUid;
  222. if (this.data.isFans) {
  223. httpRequestApi.cancerFollow(this.uid, followUid).success((res) => {
  224. this.setData({
  225. isFans: false
  226. })
  227. wx.showToast({
  228. title: '取消关注',
  229. icon: 'success',
  230. duration: 1000
  231. })
  232. });
  233. } else {
  234. httpRequestApi.followUser(this.uid, followUid).success((res) => {
  235. this.setData({
  236. isFans: true
  237. })
  238. wx.showToast({
  239. title: '关注啦',
  240. icon: 'success',
  241. duration: 1000
  242. })
  243. });
  244. }
  245. },
  246. // 点赞评论
  247. likeCommend: function (e) {
  248. console.log(e);
  249. // let uid = wx.getStorageSync('uid');
  250. let followUid = e.currentTarget.dataset.id;
  251. let index = e.currentTarget.dataset.index;
  252. httpRequestApi.likeCommend(this.uid, followUid).success(res => {
  253. console.log(res);
  254. const str = `replyList[${index}].likes`;
  255. this.setData({
  256. [str]: res.data.data.favors
  257. })
  258. });
  259. },
  260. // 去其他用户的作品页
  261. goToOthers: function (e) {
  262. wx.navigateTo({
  263. url: `../../social/works/works?id=${e.currentTarget.dataset.uid}&title=${e.currentTarget.dataset.title}`
  264. })
  265. },
  266. // 查询回复
  267. getReply: function () {
  268. // let uid = wx.getStorageSync('uid');
  269. let columnId = this.data.id;
  270. let pageNo = this.data.pageNo;
  271. let pageSize = this.data.pageSize;
  272. httpRequestApi.getReply(this.uid, columnId, pageNo, pageSize).success((res) => {
  273. console.log(res.data.data.list);
  274. const replyList = res.data.data.list;
  275. // const replyTemp = [];
  276. replyList.forEach((item) => {
  277. const temp = {};
  278. temp.nickName = item.user.wechatName;
  279. temp.avatar = item.user.avatar;
  280. temp.text = item.detailDesc;
  281. temp.id = item.id;
  282. temp.replyCount = item.replyCount;
  283. temp.time = formatDate(item.gmtModified, 3);
  284. temp.likes = item.postsAttributeInfo.favors || 0;
  285. console.log(temp.time)
  286. this.data.replyList.push(temp);
  287. });
  288. this.setData({
  289. replyList: this.data.replyList,
  290. total: res.data.data.totalSize,
  291. totalPage: res.data.data.totalNo
  292. })
  293. });
  294. },
  295. // 打开回复详情页
  296. goToDetail: function (e) {
  297. let id = e.currentTarget.dataset.id;
  298. let count = e.currentTarget.dataset.count;
  299. console.log(e);
  300. wx.navigateTo({
  301. url: `../../social/replyDetail/replyDetail?id=${id}&count=${count}`
  302. })
  303. },
  304. // 绑定输入框内容
  305. inputValue: function (e) {
  306. this.setData({
  307. inputValue: e.detail.value
  308. });
  309. },
  310. // 发布回复
  311. sendHandler: function () {
  312. console.log(this.data.inputValue);
  313. if (this.data.inputValue !== '') {
  314. // let uid = wx.getStorageSync('uid');
  315. let data = {
  316. "columnId": this.data.id,
  317. colunmNames: 'what',
  318. "detailDesc": this.data.inputValue
  319. }
  320. httpRequestApi.postReply(this.uid, data).success(res => {
  321. console.log(res);
  322. this.setData({
  323. inputValue: '',
  324. pageNo: 1,
  325. replyList: [],
  326. })
  327. this.getReply();
  328. });
  329. // 评论成功后刷新数据
  330. }
  331. },
  332. // 触底加载
  333. onReachBottom: function () {
  334. // 当前在推荐页面 加载推荐
  335. if (this.data.pageNo <= this.data.totalPage) {
  336. this.setData({
  337. pageNo: this.data.pageNo + 1
  338. }, () => {
  339. this.getReply();
  340. })
  341. }
  342. },
  343. // 设置点击时的id
  344. setSBId: function (e) {
  345. console.log(e)
  346. this.setData({
  347. replySBId: e.currentTarget.dataset.id,
  348. replyModal: true,
  349. replyIndex: e.currentTarget.dataset.index
  350. })
  351. },
  352. // 回复某个评论
  353. replySB: function () {
  354. const data = {
  355. postsId: this.data.replySBId,
  356. content: this.data.inputSBValue
  357. }
  358. httpRequestApi.postReplyComment(this.uid, data).success(res => {
  359. console.log(res)
  360. const replyWho = this.data.replyList[this.data.replyIndex];
  361. const indexStr = `replyList[${this.data.replyIndex}]`;
  362. replyWho.replyCount++;
  363. this.setData({
  364. replyModal: false,
  365. [indexStr]: replyWho
  366. })
  367. });
  368. },
  369. // 获取回复楼中楼的内容
  370. inputSBValue: function (e) {
  371. this.setData({
  372. inputSBValue: e.detail.value
  373. });
  374. },
  375. // 选择金额
  376. setMoney: function (e) {
  377. this.setData({
  378. howMuch: e.currentTarget.dataset.money
  379. })
  380. },
  381. reward: function () {
  382. if(this.data.isIOS){
  383. wx.showToast({
  384. title: '奖励成功!',
  385. icon: 'success',
  386. duration: 1000
  387. })
  388. return
  389. };
  390. this.setData({
  391. ifReward: true
  392. })
  393. },
  394. quitReward: function () {
  395. this.setData({
  396. ifReward: false
  397. })
  398. },
  399. // 奖励
  400. rewardMoney: function () {
  401. console.log(this.data.authorUid);
  402. const data = {
  403. targetUid: this.data.authorUid,
  404. amount: this.data.howMuch
  405. }
  406. // let uid = wx.getStorageSync('uid');
  407. httpRequestApi.rewardMoney(this.uid, data).success(res => {
  408. console.log(res);
  409. this.payMoneyt(res.data.data);
  410. })
  411. },
  412. //支付
  413. payMoneyt: function (orderInfo) {
  414. wx.requestPayment({
  415. 'appId': orderInfo.appId,
  416. 'timeStamp': orderInfo.timeStamp,
  417. 'nonceStr': orderInfo.nonceStr,
  418. 'package': orderInfo.package,
  419. 'signType': orderInfo.signType,
  420. 'paySign': orderInfo.sign,
  421. 'success': function (res) {
  422. console.log(res)
  423. wx.showModal({
  424. title: '提示',
  425. content: '支付成功',
  426. success(res) {
  427. if (res.confirm) {
  428. this.setData({
  429. ifReward: false
  430. })
  431. } else if (res.cancel) {
  432. this.setData({
  433. ifReward: false
  434. })
  435. }
  436. }
  437. })
  438. },
  439. 'fail': function (res) {
  440. this.setData({
  441. ifReward: false
  442. })
  443. console.log('支付失败', res)
  444. }
  445. })
  446. },
  447. // 回到首页
  448. goBackHome: function(){
  449. wx.redirectTo({
  450. url: '../../index/index'
  451. })
  452. }
  453. })