detail.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // pages/account/course/read/detail.js
  2. const util = require("../../../../utils/util.js")
  3. Page({
  4. data: {
  5. id:'',
  6. playerId:'',
  7. data: { title: "", content: "", readerNum: 0, myRead:0},
  8. alertStatus: false,//弹窗
  9. alert:{},
  10. showBack: false,
  11. },
  12. onLoad: function (options) {
  13. this.setData({id:options.id, playerId:options.playerId})
  14. let that = this;
  15. util.ajax({
  16. func: "v2/course/read/detail",
  17. data: {"id":that.data.id,playerId:that.data.playerId}
  18. }, function (res) {
  19. if (res.code == 0) {
  20. res.data.content = res.data.content.replace(/section/g, "div");
  21. res.data.content = res.data.content.replace(/<img/g, "<img style='max-width:100%'");
  22. that.setData({data:res.data});
  23. }else{
  24. util.showTips(res.reason);
  25. }
  26. });
  27. },
  28. read() {
  29. let that = this;
  30. util.ajax({
  31. func: "v2/course/read/confirm",
  32. method:"POST",
  33. data: { id: that.data.id, playerId: that.data.playerId},
  34. contentType: 'application/x-www-form-urlencoded'
  35. }, function (res) {
  36. if (res.code == 0) {
  37. let alert={};
  38. if (res.data.status==1){//计算积分
  39. alert= {icon: 'read-ok',title: '恭喜您,又进步一点',score: res.data.score}
  40. }else{//无效
  41. alert = { icon: res.data.overtime == 0 ? 'read-ok': 'time-out', title: '恭喜您,又进步一点', content: res.data.message, status: 1}
  42. }
  43. that.setData({alertStatus: true,alert});
  44. }else{
  45. util.showTips(res.reason);
  46. }
  47. });
  48. },
  49. close(){
  50. this.data.data.readerNum = this.data.data.readerNum*1 + 1
  51. this.data.data.myRead=1;
  52. this.setData({ data: this.data.data})
  53. },
  54. toTop() {
  55. wx.pageScrollTo({
  56. scrollTop: 0,
  57. duration: 500
  58. })
  59. },
  60. onPageScroll(e) {
  61. var showBack = this.data.showBack;
  62. if (e.scrollTop > 400) {
  63. if (!showBack) {
  64. this.setData({ showBack: true })
  65. }
  66. } else {
  67. if (showBack) {
  68. this.setData({ showBack: false })
  69. }
  70. }
  71. }
  72. })