const util = require('../../utils/util') const app = getApp() Page({ /** * 页面的初始数据 */ data: { storeList:[], searchParams:{ storeId:'', storeName:'' }, productList:[], totalPrice:0, sellProductList:[] }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.bindProductStockList() }, 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({ skuStock: e.detail.value }) }, bindProductStockList() { //获取平台商品用来订货 var that = this util.request(util.api.orderGoods, that.data.searchParams, "GET", false, true, app.globalData.token).then((res) => { if (res.code == 200) { console.log(res) res.result.forEach(item => { item.checkout = false item.skuStock = 0 }); that.setData({ productList: res.result }) } }).catch((res) => {}) }, skuStockChange(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.skuStock = value list.splice(index,1,itemProduct) that.setData({ productList:list }) var list = this.data.productList.filter((e)=>e.checkout == true && e.skuStock > 0) var totalPrice = 0 list.forEach((e)=>{ totalPrice += e.productPrice * e.skuStock }) 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.skuStock > 0) var totalPrice = 0 list.forEach((e)=>{ totalPrice += e.productPrice * e.skuStock }) 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, // }) // } reserve(){ console.log(this.data.sellProductList) var that = this; util.request(util.api.reserve, this.data.sellProductList, "post", false, true, app.globalData.token).then((res) => { if (res.code == 200) { util.toast('订货成功,等待平台审批') wx.navigateTo({ url: '/pages/stock/index', }) } }).catch((res) => {}) } })