123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- 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(){
- if(this.data.sellProductList.length==0){
- util.toast('请选择订货商品')
- return;
- }
- 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/orderGoods/order',
- })
- }
- }).catch((res) => {})
- }
- })
|