index.js 2.5 KB

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