select.js 2.9 KB

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