const util = require('../../utils/util') const app = getApp() Page({ /** * 页面的初始数据 */ data: { storeList: [], searchParams: { storeId: '', storeName: '', }, stockList: [] }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.bindStoreList() this.bindProductStockList() }, bindStorePickerChange: function (e) { var item = this.data.storeList[e.detail.value] console.log(item) this.setData({ ['searchParams.storeName']: item.storeName, ['searchParams.storeId']: item.id }) this.bindProductStockList() }, bindStoreList() { var that = this util.request(util.api.storeList, {}, "GET", false, true, app.globalData.token).then((res) => { if (res.code == 200) { that.setData({ storeList: res.result }) } }).catch((res) => {}) }, formSubmit: function (e) { var that = this console.log(that.data.stockList) util.request(util.api.editVmProductStock, that.data.stockList, "POST", false, true, app.globalData.token).then((res) => { if (res.code == 200) { util.toast('保存成功') setTimeout(() => { wx.navigateBack() }, 500) } }).catch((res) => {}) }, formReset: function (e) { console.log("清空数据") }, inputedit: function (e) { let _this = this; let dataset = e.currentTarget.dataset; let value = e.detail.value; let name = dataset.name; _this.data[name] = value; _this.setData({ [name]: _this.data[name] }); }, inputeditRow: function (e) { let that = this; let dataset = e.currentTarget.dataset; let value = e.detail.value; let name = dataset.name; var list = that.data.stockList var index = dataset.index; var itemProduct = dataset.item console.log(name) console.log(itemProduct) itemProduct.skuStock = value list.splice(index, 1, itemProduct) that.setData({ stockList: list }) }, bindProductStockList() { var that = this util.request(util.api.productStockList, that.data.searchParams, "GET", true, true, app.globalData.token).then((res) => { console.log(res) if (res.code == 200) { that.setData({ stockList: res.result }) } }).catch((res) => {}) } })