index.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. const util = require('../../utils/util.js');
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. searchParams: {
  9. pageNo: 1,
  10. pageSize: 20,
  11. storeName:'',
  12. },
  13. storeList: [],
  14. loadding: false,
  15. pullUpOn: true,
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. this.bindStoreList()
  22. },
  23. /**
  24. * 生命周期函数--监听页面初次渲染完成
  25. */
  26. onReady: function () {
  27. },
  28. /**
  29. * 生命周期函数--监听页面显示
  30. */
  31. onShow: function () {
  32. },
  33. /**
  34. * 生命周期函数--监听页面隐藏
  35. */
  36. onHide: function () {
  37. },
  38. onUnload: function () {
  39. wx.reLaunch({
  40. url: '../index/index',
  41. })
  42. },
  43. /**
  44. * 页面相关事件处理函数--监听用户下拉动作
  45. */
  46. onPullDownRefresh: function () {
  47. this.setData({
  48. ["searchParams.pageNo"]: 1,
  49. pullUpOn: true,
  50. loadding: false,
  51. storeList: []
  52. })
  53. this.bindStoreList()
  54. setTimeout(() => {
  55. wx.stopPullDownRefresh()
  56. }, 300);
  57. },
  58. /**
  59. * 页面上拉触底事件的处理函数
  60. */
  61. onReachBottom: function () {
  62. //只是测试效果,逻辑以实际数据为准
  63. this.setData({
  64. loadding: true,
  65. pullUpOn: true
  66. })
  67. this.setData({
  68. ["searchParams.pageNo"]: that.data.searchParams.pageNo + 1
  69. })
  70. this.bindStoreList()
  71. },
  72. /**
  73. * 用户点击右上角分享
  74. */
  75. onShareAppMessage: function () {
  76. },
  77. toDevice(e) {
  78. wx.navigateTo({
  79. url: '/pages/device/list?storeId=' + e.currentTarget.dataset.id,
  80. })
  81. },
  82. searchStore(){
  83. this.setData({
  84. ["searchParams.pageNo"]: 1,
  85. pullUpOn: true,
  86. loadding: false,
  87. storeList: []
  88. })
  89. this.bindStoreList()
  90. },
  91. bindStoreList() {
  92. var that = this
  93. util.request(util.api.storeListPage, that.data.searchParams, "GET", true, false, app.globalData.token).then((res) => {
  94. if (res.code == 200) {
  95. if (res.result.records.length > 0) {
  96. if (that.data.storeList.length > 0) {
  97. let list = that.data.storeList
  98. res.result.records.forEach((e)=>{
  99. list.push(e)
  100. })
  101. that.setData({
  102. storeList: list
  103. })
  104. }else{
  105. that.setData({
  106. storeList: res.result.records
  107. })
  108. }
  109. } else {
  110. that.setData({
  111. loadding: false,
  112. pullUpOn: false,
  113. ["searchParams.pageNo"]:that.data.searchParams.pageNo-1
  114. })
  115. }
  116. }
  117. }).catch((res) => {})
  118. },
  119. inputedit: function (e) {
  120. let _this = this;
  121. let dataset = e.currentTarget.dataset;
  122. let value = e.detail.value;
  123. let name = dataset.name;
  124. _this.data[name] = value;
  125. _this.setData({
  126. [name]: _this.data[name]
  127. });
  128. },
  129. })