chatIndex.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. var util = require('../../../utils/util.js');
  2. var api = require('../../../config/api.js');
  3. var app = getApp();
  4. Page({
  5. data: {
  6. cartGoods: [],
  7. cartTotal: {
  8. "goodsCount": 0,
  9. "goodsAmount": 0.00,
  10. "checkedGoodsCount": 0,
  11. "checkedGoodsAmount": 0.00
  12. },
  13. isEditCart: false,
  14. checkedAllStatus: true,
  15. editCartList: [],
  16. chatList: [],
  17. offsetTime: null,
  18. size: 10,
  19. },
  20. onLoad: function(options) {
  21. // 页面初始化 options为页面跳转所带来的参数
  22. },
  23. onReady: function() {
  24. // 页面渲染完成
  25. },
  26. onShow: function() {
  27. // 页面显示
  28. let now = new Date();
  29. console.log(now.toISOString())
  30. this.setData({
  31. offsetTime: now.toISOString()
  32. })
  33. this.getChatList();
  34. },
  35. onHide: function() {
  36. // 页面隐藏
  37. },
  38. onUnload: function() {
  39. // 页面关闭
  40. },
  41. getChatList: function() {
  42. let that = this;
  43. util.request(api.ChatIndex, {
  44. size: this.data.size,
  45. offsetTime: this.data.offsetTime
  46. }).then(function(res) {
  47. if (res.errno === 0) {
  48. console.log(res.data);
  49. that.setData({
  50. chatList: that.data.chatList.concat(res.data),
  51. });
  52. } else {
  53. console.log(res)
  54. }
  55. })
  56. },
  57. onPullDownRefresh: function () {
  58. console.log("上拉刷新")
  59. this.setData({
  60. chatList: [],
  61. offsetTime: null,
  62. size: 10,
  63. })
  64. this.onShow()
  65. setTimeout(function callback() {
  66. wx.stopPullDownRefresh()
  67. }, 500)
  68. },
  69. onReachBottom: function () {
  70. console.log("拉到底")
  71. let chatList = this.data.chatList;
  72. let offsetTime = chatList[chatList.length - 1].offsetTime;
  73. this.setData({
  74. offsetTime: offsetTime,
  75. })
  76. this.getChatList()
  77. },
  78. })