index.js 3.1 KB

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