index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. const util = require('../../utils/util')
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. storeList: [],
  9. userInfo: app.globalData.userInfo,
  10. searchParams: {
  11. storeId: '',
  12. storeName: '',
  13. },
  14. stockList: []
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function (options) {
  20. // this.bindStoreList()
  21. this.bindProductStockList()
  22. },
  23. bindStorePickerChange: function (e) {
  24. var item = this.data.storeList[e.detail.value]
  25. console.log(item)
  26. this.setData({
  27. ['searchParams.storeName']: item.storeName,
  28. ['searchParams.storeId']: item.id
  29. })
  30. this.bindProductStockList()
  31. },
  32. // bindStoreList() {
  33. // var that = this
  34. // util.request(util.api.storeList, {}, "GET", false, true, app.globalData.token).then((res) => {
  35. // if (res.code == 200) {
  36. // that.setData({
  37. // storeList: res.result
  38. // })
  39. // }
  40. // }).catch((res) => {})
  41. // },
  42. formSubmit: function (e) {
  43. var that = this
  44. console.log(that.data.stockList)
  45. util.request(util.api.editVmProductStock, that.data.stockList, "POST", false, true, app.globalData.token).then((res) => {
  46. if (res.code == 200) {
  47. util.toast('保存成功')
  48. setTimeout(() => {
  49. wx.navigateBack()
  50. }, 500)
  51. }
  52. }).catch((res) => {})
  53. },
  54. formReset: function (e) {
  55. console.log("清空数据")
  56. },
  57. inputedit: function (e) {
  58. let _this = this;
  59. let dataset = e.currentTarget.dataset;
  60. let value = e.detail.value;
  61. let name = dataset.name;
  62. _this.data[name] = value;
  63. _this.setData({
  64. [name]: _this.data[name]
  65. });
  66. },
  67. inputeditRow: function (e) {
  68. let that = this;
  69. let dataset = e.currentTarget.dataset;
  70. let value = e.detail.value;
  71. let name = dataset.name;
  72. var list = that.data.stockList
  73. var index = dataset.index;
  74. var itemProduct = dataset.item
  75. console.log(name)
  76. console.log(itemProduct)
  77. itemProduct.skuStock = value
  78. list.splice(index, 1, itemProduct)
  79. that.setData({
  80. stockList: list
  81. })
  82. },
  83. bindProductStockList() {
  84. var that = this
  85. console.log( this.data.userInfo)
  86. util.request(util.api.productStockList, null, "GET", true, true, app.globalData.token).then((res) => {
  87. console.log(res)
  88. if (res.code == 200) {
  89. that.setData({
  90. stockList: res.result
  91. })
  92. }
  93. }).catch((res) => {})
  94. }
  95. })