select.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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.id
  92. itemProduct.skuProductId = row.productId
  93. itemProduct.productName = row.skuProductName
  94. itemProduct.productImg = row.productImg
  95. itemProduct.productSchemePrice = row.productPrice
  96. itemProduct.productPrice = row.productPrice
  97. itemProduct.gridCount = 5
  98. list.splice(this.data.index,1,itemProduct)
  99. prevPage.setData({
  100. selectGridProductList:list,
  101. })
  102. wx.navigateBack()
  103. },
  104. bindProductList() {
  105. var that = this
  106. util.request(util.api.mgVmStoreProductSkuList, that.data.searchParams, "GET", false, false, app.globalData.token).then((res) => {
  107. if (res.code == 200) {
  108. if (res.result.records.length > 0) {
  109. if (that.data.productList.length > 0) {
  110. let list = that.data.productList
  111. res.result.records.forEach((e)=>{
  112. list.push(e)
  113. })
  114. that.setData({
  115. productList: list
  116. })
  117. } else {
  118. that.setData({
  119. productList: res.result.records
  120. })
  121. }
  122. } else {
  123. that.setData({
  124. loadding: false,
  125. pullUpOn: false,
  126. ["searchParams.pageNo"]:that.data.searchParams.pageNo-1
  127. })
  128. }
  129. }
  130. }).catch((res) => {})
  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. btnSearch(){
  143. console.log("1111")
  144. console.log(this.data.searchParams)
  145. console.log("2222")
  146. this.setData({
  147. ["searchParams.pageNo"]: 1,
  148. pullUpOn: true,
  149. loadding: false,
  150. productList: []
  151. })
  152. this.bindProductList()
  153. }
  154. })