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