const util = require('../../utils/util') const app = getApp() Page({ /** * 页面的初始数据 */ data: { storeList:[], searchParams:{ storeId:'', storeName:'' }, productList:[], totalPrice:0, sellProductList:[] }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.bindStoreList() 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) => {}) }, bindStorePickerChange: function (e) { var item = this.data.storeList[e.detail.value] console.log(item) this.setData({ ['searchParams.storeId']: item.id, ['searchParams.storeName']: item.storeName }) this.bindProductStockList() }, changeNum: function (e) { this.setData({ productNum: e.detail.value }) }, bindProductStockList() { var that = this util.request(util.api.productStockList, that.data.searchParams, "GET", false, true, app.globalData.token).then((res) => { if (res.code == 200) { res.result.forEach(item => { item.checkout = false item.productNum = 0 }); that.setData({ productList: res.result }) } }).catch((res) => {}) }, productNumChange(e){ let that = this; let dataset = e.currentTarget.dataset; let value = e.detail.value; var list = that.data.productList var index = dataset.index; var itemProduct = dataset.item itemProduct.productNum = value list.splice(index,1,itemProduct) that.setData({ productList:list }) var list = this.data.productList.filter((e)=>e.checkout == true && e.productNum > 0) var totalPrice = 0 list.forEach((e)=>{ totalPrice += e.productPrice * e.productNum }) this.setData({ totalPrice: totalPrice, sellProductList: list }) }, checkboxChange(e){ let that = this; let dataset = e.currentTarget.dataset; let value = e.detail.value; var list = that.data.productList var index = dataset.index; var itemProduct = dataset.item itemProduct.checkout = value.length>0? true : false list.splice(index,1,itemProduct) that.setData({ productList:list }) var list = this.data.productList.filter((e)=>e.checkout == true && e.productNum > 0) var totalPrice = 0 list.forEach((e)=>{ totalPrice += e.productPrice * e.productNum }) this.setData({ totalPrice: totalPrice, sellProductList: list }) }, btnPay(){ if(this.data.sellProductList.length<1){ util.toast('请选择下单商品,并且订货数量必须大于0') return } console.log("1111") console.log(this.data.sellProductList) console.log("2222") wx.navigateTo({ url: '/pages/orderGoods/submitBuy?strJson='+encodeURIComponent(JSON.stringify(this.data.sellProductList))+'&storeId='+this.data.searchParams.storeId, }) } })