select.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. agentId:''
  13. },
  14. productList: [],
  15. loadding: false,
  16. pullUpOn: true,
  17. index:0,
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function (options) {
  23. let index = parseInt(options.index)
  24. this.setData({
  25. index:index,
  26. ['searchParams.agentId']: options.agentId
  27. })
  28. this.bindProductList()
  29. },
  30. /**
  31. * 生命周期函数--监听页面初次渲染完成
  32. */
  33. onReady: function () {
  34. },
  35. /**
  36. * 生命周期函数--监听页面显示
  37. */
  38. onShow: function () {
  39. },
  40. /**
  41. * 生命周期函数--监听页面隐藏
  42. */
  43. onHide: function () {
  44. },
  45. /**
  46. * 生命周期函数--监听页面卸载
  47. */
  48. onUnload: function () {
  49. },
  50. /**
  51. * 页面相关事件处理函数--监听用户下拉动作
  52. */
  53. onPullDownRefresh: function () {
  54. this.setData({
  55. ["searchParams.pageNo"]: 1,
  56. pullUpOn: true,
  57. loadding: false,
  58. storeList: []
  59. })
  60. this.bindProductList()
  61. setTimeout(() => {
  62. wx.stopPullDownRefresh()
  63. }, 300);
  64. },
  65. /**
  66. * 页面上拉触底事件的处理函数
  67. */
  68. onReachBottom: function () {
  69. var that = this
  70. //只是测试效果,逻辑以实际数据为准
  71. this.setData({
  72. loadding: true,
  73. pullUpOn: true
  74. })
  75. this.setData({
  76. ["searchParams.pageNo"]: that.data.searchParams.pageNo + 1
  77. })
  78. this.bindProductList()
  79. },
  80. /**
  81. * 用户点击右上角分享
  82. */
  83. onShareAppMessage: function () {
  84. },
  85. toEdit(e) {
  86. var row = e.currentTarget.dataset.item;
  87. var pages = getCurrentPages();
  88. var prevPage = pages[pages.length - 2]; //上一个页面
  89. var list = prevPage.data.selectGridProductList
  90. var itemProduct = JSON.parse(JSON.stringify(list))[this.data.index]
  91. itemProduct.productId = row.productId
  92. itemProduct.productName = row.skuProductName
  93. itemProduct.productImg = row.productImg
  94. itemProduct.productSchemePrice = row.productPrice
  95. itemProduct.productPrice = row.productPrice
  96. itemProduct.gridCount = 5
  97. list.splice(this.data.index,1,itemProduct)
  98. prevPage.setData({
  99. selectGridProductList:list,
  100. })
  101. wx.navigateBack()
  102. },
  103. bindProductList() {
  104. var that = this
  105. util.request(util.api.mgVmStoreProductSkuList, that.data.searchParams, "GET", false, false, app.globalData.token).then((res) => {
  106. if (res.code == 200) {
  107. if (res.result.records.length > 0) {
  108. if (that.data.productList.length > 0) {
  109. let list = that.data.productList
  110. res.result.records.forEach((e)=>{
  111. list.push(e)
  112. })
  113. that.setData({
  114. productList: list
  115. })
  116. } else {
  117. that.setData({
  118. productList: res.result.records
  119. })
  120. }
  121. } else {
  122. that.setData({
  123. loadding: false,
  124. pullUpOn: false,
  125. ["searchParams.pageNo"]:that.data.searchParams.pageNo-1
  126. })
  127. }
  128. }
  129. }).catch((res) => {})
  130. },
  131. inputedit: function (e) {
  132. let _this = this;
  133. let dataset = e.currentTarget.dataset;
  134. let value = e.detail.value;
  135. let name = dataset.name;
  136. _this.data[name] = value;
  137. _this.setData({
  138. [name]: _this.data[name]
  139. });
  140. },
  141. btnSearch(){
  142. console.log("1111")
  143. console.log(this.data.searchParams)
  144. console.log("2222")
  145. this.setData({
  146. ["searchParams.pageNo"]: 1,
  147. pullUpOn: true,
  148. loadding: false,
  149. productList: []
  150. })
  151. this.bindProductList()
  152. }
  153. })