index.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. onUnload: function () {
  24. wx.reLaunch({
  25. url: '../vendingMachine/index',
  26. })
  27. },
  28. /**
  29. * 页面相关事件处理函数--监听用户下拉动作
  30. */
  31. onPullDownRefresh: function () {
  32. this.setData({
  33. ["searchParams.pageNo"]: 1,
  34. pullUpOn: true,
  35. loadding: false,
  36. productList: []
  37. })
  38. this.bindProductList()
  39. setTimeout(() => {
  40. wx.stopPullDownRefresh()
  41. }, 300);
  42. },
  43. /**
  44. * 页面上拉触底事件的处理函数
  45. */
  46. onReachBottom: function () {
  47. var that = this
  48. //只是测试效果,逻辑以实际数据为准
  49. this.setData({
  50. loadding: true,
  51. pullUpOn: true
  52. })
  53. this.setData({
  54. ["searchParams.pageNo"]: that.data.searchParams.pageNo + 1
  55. })
  56. this.bindProductList()
  57. },
  58. toEdit: function (e) {
  59. wx.navigateTo({
  60. url: 'edit?id=' + e.currentTarget.dataset.id
  61. })
  62. },
  63. toAddProduct() {
  64. wx.navigateTo({
  65. url: '/pages/product/select',
  66. })
  67. },
  68. deleteProduct(e){
  69. var id = e.currentTarget.dataset.id;
  70. var that = this
  71. util.request(util.api.deleteMgVmProductById, {'id':id}, "POST", true, true, app.globalData.token).then((res) => {
  72. console.log(res)
  73. if(res.code == 200){
  74. that.setData({
  75. productList: []
  76. })
  77. that.bindProductList();
  78. }else{
  79. util.toast(res.message);
  80. }
  81. }).catch((res) => {})
  82. },
  83. bindProductList() {
  84. var that = this
  85. util.request(util.api.MgVmProductSkuPage, 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. console.log(list)
  94. console.log(666)
  95. that.setData({
  96. productList: list
  97. })
  98. } else {
  99. that.setData({
  100. productList: res.result.records
  101. })
  102. }
  103. } else {
  104. that.setData({
  105. loadding: false,
  106. pullUpOn: false,
  107. ["searchParams.pageNo"]:that.data.searchParams.pageNo-1
  108. })
  109. }
  110. }
  111. }).catch((res) => {})
  112. },
  113. inputedit: function (e) {
  114. let _this = this;
  115. let dataset = e.currentTarget.dataset;
  116. let value = e.detail.value;
  117. let name = dataset.name;
  118. _this.data[name] = value;
  119. _this.setData({
  120. [name]: _this.data[name]
  121. });
  122. },
  123. btnsearch(){
  124. this.setData({
  125. ["searchParams.pageNo"]: 1,
  126. pullUpOn: true,
  127. loadding: false,
  128. productList: []
  129. })
  130. this.bindProductList()
  131. }
  132. })