index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // pages/record/index.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. Page: 1,
  8. Size: 20,
  9. data: {
  10. list: []
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: function (options) {
  16. wx.setNavigationBarTitle({
  17. title: app.globalData.selectQuestion.name
  18. })
  19. this.getData();
  20. },
  21. getData() {
  22. const that = this;
  23. wx.showLoading();
  24. wx.cloud.callFunction({
  25. name: "quickstartFunctions",
  26. data: {
  27. type: "getQuestionRecord",
  28. data: {
  29. queId: app.globalData.selectQuestion._id,
  30. Page: this.Page,
  31. Size: this.Size
  32. }
  33. }
  34. }).then(res => {
  35. if (res.result.code !== 0) return wx.showToast({
  36. title: '网络繁忙',
  37. })
  38. let oldli = that.data.list || [];
  39. let li = res.result.data || [];
  40. li = li.map(v => {
  41. return {
  42. ...v,
  43. startTime: this.formatTime(v.startTime),
  44. endTime: this.formatTime(v.endTime),
  45. }
  46. })
  47. that.setData({
  48. list: [...oldli, ...li]
  49. })
  50. wx.hideLoading()
  51. }).catch(err => {
  52. console.log(err)
  53. wx.hideLoading()
  54. })
  55. },
  56. formatTime(T) {
  57. let date = new Date(T);
  58. let y = date.getFullYear();
  59. let m = date.getMonth() * 1 + 1;
  60. let d = date.getDate();
  61. let h = date.getHours();
  62. let min = date.getMinutes() * 1 + 1;
  63. let s = date.getSeconds();
  64. let out = y;
  65. m > 9 ? out += '-' + m : out += '-0' + m;
  66. d > 9 ? out += '-' + d + ' ' : out += '-0' + d + ' ';
  67. h > 9 ? out += h + ":" : out += '0' + h + ':';
  68. min > 9 ? out += min + ":" : out += '0' + min + ':';
  69. s > 9 ? out += s : out += '0' + s;
  70. return out;
  71. },
  72. /**
  73. * 生命周期函数--监听页面初次渲染完成
  74. */
  75. onReady: function () {
  76. },
  77. /**
  78. * 生命周期函数--监听页面显示
  79. */
  80. onShow: function () {
  81. },
  82. /**
  83. * 生命周期函数--监听页面隐藏
  84. */
  85. onHide: function () {
  86. },
  87. /**
  88. * 生命周期函数--监听页面卸载
  89. */
  90. onUnload: function () {
  91. },
  92. /**
  93. * 页面相关事件处理函数--监听用户下拉动作
  94. */
  95. onPullDownRefresh: function () {
  96. },
  97. /**
  98. * 页面上拉触底事件的处理函数
  99. */
  100. onReachBottom: function () {
  101. this.Page++;
  102. this.getData();
  103. },
  104. /**
  105. * 用户点击右上角分享
  106. */
  107. onShareAppMessage: function () {
  108. }
  109. })