select.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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.productName = row.skuProductName
  93. itemProduct.productImg = row.productImg
  94. itemProduct.productSchemePrice = row.productPrice
  95. itemProduct.productPrice = row.productPrice
  96. list.splice(this.data.index,1,itemProduct)
  97. prevPage.setData({
  98. selectGridProductList:list,
  99. })
  100. wx.navigateBack()
  101. },
  102. bindProductList() {
  103. var that = this
  104. util.request(util.api.mgVmStoreProductSkuList, that.data.searchParams, "GET", false, false, app.globalData.token).then((res) => {
  105. if (res.code == 200) {
  106. if (res.result.records.length > 0) {
  107. if (that.data.productList.length > 0) {
  108. let list = that.data.productList
  109. res.result.records.forEach((e)=>{
  110. list.push(e)
  111. })
  112. that.setData({
  113. productList: list
  114. })
  115. } else {
  116. that.setData({
  117. productList: res.result.records
  118. })
  119. }
  120. } else {
  121. that.setData({
  122. loadding: false,
  123. pullUpOn: false,
  124. ["searchParams.pageNo"]:that.data.searchParams.pageNo-1
  125. })
  126. }
  127. }
  128. }).catch((res) => {})
  129. },
  130. inputedit: function (e) {
  131. let _this = this;
  132. let dataset = e.currentTarget.dataset;
  133. let value = e.detail.value;
  134. let name = dataset.name;
  135. _this.data[name] = value;
  136. _this.setData({
  137. [name]: _this.data[name]
  138. });
  139. },
  140. btnSearch(){
  141. console.log("1111")
  142. console.log(this.data.searchParams)
  143. console.log("2222")
  144. this.setData({
  145. ["searchParams.pageNo"]: 1,
  146. pullUpOn: true,
  147. loadding: false,
  148. productList: []
  149. })
  150. this.bindProductList()
  151. }
  152. })