index.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. const app = getApp()
  2. Page({
  3. data: {
  4. tableData: [],
  5. keyword:'',
  6. from: 0,
  7. size: 10
  8. },
  9. onLoad: function(options) {
  10. this.setData({
  11. spinShow: true
  12. });
  13. this.search(true)
  14. },
  15. onPullDownRefresh() {
  16. this.setData({ spinShow: true });
  17. if (!this.loading) {
  18. this.setData({ from:0,tableData:[]});
  19. this.search(true)
  20. }
  21. },
  22. onReachBottom() {
  23. if (!this.loading && this.data.from > -1) {
  24. this.search(false)
  25. }
  26. },
  27. onInputEvent(e){
  28. let {value} = e.detail;
  29. if( this.data.keyword == value) return;
  30. this.setData({keyword: value, from:0})
  31. this.search( )
  32. },
  33. search: function() {
  34. let {from, size, keyword, tableData} = this.data;
  35. let _this = this
  36. let param = {from, size, keyword}
  37. app.formPost('User.search', param ).then(res => {
  38. _this.setData({spinShow: false});
  39. wx.stopPullDownRefresh()
  40. if (res.code === 200) {
  41. const re = res.data
  42. if( from== 0) tableData = [];
  43. _this.setData({
  44. from: re.from,
  45. tableData: tableData.concat(re.list)
  46. });
  47. }
  48. })
  49. }
  50. })