index.js 2.3 KB

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