index.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. const utils = require('../../utils/util')
  2. const app = getApp();
  3. Page({
  4. data: {
  5. searchParams: {
  6. pageNo: 1,
  7. pageSize: 10,
  8. },
  9. list:[],
  10. },
  11. /**
  12. * 页面相关事件处理函数--监听用户下拉动作
  13. */
  14. onPullDownRefresh: function () {
  15. this.setData({
  16. ["searchParams.pageNo"]: 1,
  17. pullUpOn: true,
  18. loadding: false,
  19. list: []
  20. })
  21. this.getList()
  22. setTimeout(() => {
  23. wx.stopPullDownRefresh()
  24. }, 300);
  25. },
  26. /**
  27. * 页面上拉触底事件的处理函数
  28. */
  29. onReachBottom: function () {
  30. let that = this;
  31. //只是测试效果,逻辑以实际数据为准
  32. this.setData({
  33. loadding: true,
  34. pullUpOn: true
  35. })
  36. this.setData({
  37. ["searchParams.pageNo"]: that.data.searchParams.pageNo + 1
  38. })
  39. this.getList()
  40. },
  41. onLoad: function (options) {
  42. this.getList();
  43. },
  44. onReady: function (options) {
  45. },
  46. searchAgent(){
  47. this.setData({
  48. ["searchParams.pageNo"]: 1,
  49. pullUpOn: true,
  50. loadding: false,
  51. list: []
  52. })
  53. this.getList()
  54. },
  55. getList() {
  56. var that = this
  57. utils.request(utils.api.agentList, that.data.searchParams, "GET", true, false, app.globalData.token).then((res) => {
  58. if (res.code == 200) {
  59. if (res.result.records.length > 0) {
  60. if (that.data.searchParams.pageNo > 0) {
  61. let list = that.data.list
  62. res.result.records.forEach((e)=>{
  63. list.push(e)
  64. })
  65. that.setData({
  66. list: list
  67. })
  68. }else{
  69. that.setData({
  70. list: res.result.records
  71. })
  72. }
  73. } else {
  74. that.setData({
  75. loadding: false,
  76. pullUpOn: false,
  77. ["searchParams.pageNo"]:that.data.searchParams.pageNo-1
  78. })
  79. }
  80. }
  81. }).catch((res) => {})
  82. },
  83. toAddAgent(){
  84. wx.navigateTo({
  85. url: '/pages/agent/add',
  86. })
  87. },
  88. toDetail(e){
  89. wx.navigateTo({
  90. url: '/pages/agent/edit?id='+e.currentTarget.dataset.id,
  91. })
  92. },
  93. inputedit: function (e) {
  94. let _this = this;
  95. let dataset = e.currentTarget.dataset;
  96. let value = e.detail.value;
  97. let name = dataset.name;
  98. _this.data[name] = value;
  99. _this.setData({
  100. [name]: _this.data[name]
  101. });
  102. },
  103. })