select.js 3.7 KB

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