index.js 2.3 KB

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