index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. that.setData({
  94. productList: list
  95. })
  96. } else {
  97. that.setData({
  98. productList: res.result.records
  99. })
  100. }
  101. } else {
  102. that.setData({
  103. loadding: false,
  104. pullUpOn: false,
  105. ["searchParams.pageNo"]:that.data.searchParams.pageNo-1
  106. })
  107. }
  108. }
  109. }).catch((res) => {})
  110. },
  111. inputedit: function (e) {
  112. let _this = this;
  113. let dataset = e.currentTarget.dataset;
  114. let value = e.detail.value;
  115. let name = dataset.name;
  116. _this.data[name] = value;
  117. _this.setData({
  118. [name]: _this.data[name]
  119. });
  120. },
  121. btnsearch(){
  122. this.setData({
  123. ["searchParams.pageNo"]: 1,
  124. pullUpOn: true,
  125. loadding: false,
  126. productList: []
  127. })
  128. this.bindProductList()
  129. }
  130. })