const util = require('../../utils/util') const app = getApp() Page({ /** * 页面的初始数据 */ data: { hotelList: [], searchParams: { hotelId: '', hotelName: '', }, stockList: [] }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.bindHotelList() this.bindProductStockList() }, bindHotelPickerChange: function (e) { var item = this.data.hotelList[e.detail.value] console.log(item) this.setData({ ['searchParams.hotelName']: item.hotelName, ['searchParams.hotelId']: item.id }) this.bindProductStockList() }, bindHotelList() { var that = this util.request(util.api.hotelList, {}, "GET", false, true, app.globalData.token).then((res) => { if (res.code == 200) { that.setData({ hotelList: res.result }) } }).catch((res) => {}) }, formSubmit: function (e) { var that = this 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 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) => { if (res.code == 200) { that.setData({ stockList: res.result }) } }).catch((res) => {}) } })