C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
2.2 KiB

  1. var config = require("../../config/config.js");
  2. var app = getApp();
  3. const Http = require("../../utils/HttpBasics");
  4. let util = require("../../utils/util");
  5. const imgurl = require("../../utils/imgurl");
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. score: 10,
  12. pageNum:1,
  13. list:[],
  14. showcontent:false,
  15. loadingUrl: imgurl.loading.url,
  16. bgg: imgurl.bgg.url,
  17. allow_load: true
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function(options) {
  23. },
  24. gotorule: function() {
  25. wx.navigateTo({
  26. url: '/pages/grade/grade',
  27. })
  28. },
  29. /**
  30. * 生命周期函数--监听页面显示
  31. */
  32. onShow: function () {
  33. let that = this;
  34. that.getScore();
  35. that.record(1, 15);
  36. },
  37. record(pageNum) {
  38. var that = this;
  39. if (that.data.allow_load) {
  40. Http.get({
  41. url: config.api.scoreHistory,
  42. data: {
  43. pageNum: pageNum,
  44. pageSize: 20,
  45. }
  46. }).then(res => {
  47. wx.stopPullDownRefresh();
  48. res.data.list.map(file => {
  49. file.createDate = util.formatTime(
  50. file.createDate,
  51. "yyyy-MM-dd hh:mm:ss"
  52. );
  53. });
  54. if (pageNum >= res.data.pages) {
  55. that.setData({
  56. allow_load: false,
  57. });
  58. }
  59. that.data.list = that.data.list.concat(res.data.list);
  60. that.setData({
  61. list: that.data.list
  62. });
  63. })
  64. .catch(err => {
  65. wx.showToast({
  66. title: err.errMsg,
  67. icon: 'none',
  68. duration: 2000,
  69. mask: false
  70. });
  71. })
  72. }
  73. },
  74. /**
  75. * 刷新
  76. */
  77. onPullDownRefresh: function (e) {
  78. let that = this;
  79. that.setData({
  80. pageNum: 1,
  81. list: [],
  82. allow_load: true
  83. });
  84. that.record(1);
  85. },
  86. getScore: function() {
  87. let that = this;
  88. Http.get({
  89. url: config.api.getScore,
  90. data: {}
  91. })
  92. .then(res => {
  93. console.log(res)
  94. that.setData({
  95. score: res.data.score,
  96. levelName: res.data.levelName,
  97. })
  98. })
  99. },
  100. onReachBottom: function () {
  101. var that = this;
  102. that.data.pageNum++;
  103. that.setData({
  104. pageNum: that.data.pageNum
  105. });
  106. that.record(that.data.pageNum);
  107. }
  108. })