Ver código fonte

购物车数量调整

xiaohaizhao 2 anos atrás
pai
commit
c996a007f6

+ 278 - 233
packageA/shopping/modules/standard/index.js

@@ -1,245 +1,290 @@
 const _Http = getApp().globalData.http,
-  currency = require("../../../../utils/currency"),
-  CNY = sum => currency(sum, {
-    symbol: "¥",
-    precision: 2
-  }).format();
+    currency = require("../../../../utils/currency"),
+    CNY = sum => currency(sum, {
+        symbol: "¥",
+        precision: 2
+    }).format();
 let downCount = {};
 
 Component({
-  options: {
-    addGlobalClass: true,
-  },
-  properties: {
-    figure: Number
-  },
-  data: {
-    isGet: false,
-    list: [],
-    results: [], //选中结果
-    sa_brandid: null, //当前选中品牌id
-    classList: [], //生成订单时所选
-    sum: 0, //价格合
-  },
-  methods: {
-    /* 获取列表 */
-    getList() {
-      _Http.basic({
-        "id": 20220924095302,
-        "content": {
-          nocache: true,
-          istool: 0,
-          "pageNumber": 1,
-          "pageSize": getApp().globalData.num + 5,
-          "where": {
-            "condition": ""
-          }
-        }
-      }).then(res => {
-        console.log('购物车列表', res)
-        if (res.msg != '成功') return wx.showToast({
-          title: res.msg,
-          icon: "none"
-        })
-        this.setData({
-          list: res.data.map(v => {
-            v.showPrice = CNY(v.oldprice)
-            return v
-          }),
-          isGet: true
-        });
-
-        if (wx.getStorageSync('shopping')) {
-          this.setData({
-            ...wx.getStorageSync('shopping')
-          });
-          this.computeSum();
-        }
-      })
+    options: {
+        addGlobalClass: true,
     },
-    clickBut(e) {
-      this.data.classList.length >= 2 ? wx.showToast({
-        title: '请选择订单领域(订单只允许同品牌/同领域的商品)',
-        icon: "none",
-        duration: 3000
-      }) : this.handleSubmit(0);
+    properties: {
+        figure: Number
     },
-    /* 提交 */
-    submit(e) {
-      this.handleSubmit(e.detail.value)
+    data: {
+        isGet: false,
+        list: [],
+        results: [], //选中结果
+        sa_brandid: null, //当前选中品牌id
+        classList: [], //生成订单时所选
+        sum: 0, //价格合
     },
-    handleSubmit(index) {
-      let data = this.data.classList[index];
-      _Http.basic({
-        "id": 20221128183202,
-        "content": {
-          istool: 0,
-          "tradefield": data.type, //必选
-          "items": data.list.map(v => {
-            return {
-              "sa_orderitemsid": 0,
-              "itemid": v.itemid,
-              "sa_brandid": v.sa_brandid,
-              "qty": v.qty
+    methods: {
+        /* 获取列表 */
+        getList() {
+            _Http.basic({
+                "id": 20220924095302,
+                "content": {
+                    nocache: true,
+                    istool: 0,
+                    "pageNumber": 1,
+                    "pageSize": getApp().globalData.num + 5,
+                    "where": {
+                        "condition": ""
+                    }
+                }
+            }).then(res => {
+                console.log('购物车列表', res)
+                if (res.msg != '成功') return wx.showToast({
+                    title: res.msg,
+                    icon: "none"
+                })
+                this.setData({
+                    list: res.data.map(v => {
+                        v.showPrice = CNY(v.oldprice)
+                        return v
+                    }),
+                    isGet: true
+                });
+
+                if (wx.getStorageSync('shopping')) {
+                    this.setData({
+                        ...wx.getStorageSync('shopping')
+                    });
+                    this.computeSum();
+                }
+            })
+        },
+        clickBut(e) {
+            this.data.classList.length >= 2 ? wx.showToast({
+                title: '请选择订单领域(订单只允许同品牌/同领域的商品)',
+                icon: "none",
+                duration: 3000
+            }) : this.handleSubmit(0);
+        },
+        /* 提交 */
+        submit(e) {
+            this.handleSubmit(e.detail.value)
+        },
+        handleSubmit(index) {
+            let data = this.data.classList[index];
+            _Http.basic({
+                "id": 20221128183202,
+                "content": {
+                    istool: 0,
+                    "tradefield": data.type, //必选
+                    "items": data.list.map(v => {
+                        return {
+                            "sa_orderitemsid": 0,
+                            "itemid": v.itemid,
+                            "sa_brandid": v.sa_brandid,
+                            "qty": v.qty
+                        }
+                    })
+                }
+            }).then(res => {
+                console.log("转化订单", res)
+                if (res.msg != '成功') return wx.showToast({
+                    title: res.msg,
+                    icon: "none"
+                });
+                wx.showModal({
+                    title: '提示',
+                    content: '生成成功!是否立即前往',
+                    complete: (s) => {
+                        if (s.confirm) {
+                            wx.navigateTo({
+                                url: '/packageA/orderForm/detail?id=' + res.data.sa_orderid,
+                            })
+                        }
+                    }
+                });
+                this.getList();
+            })
+        },
+        /* 切换选中项 */
+        changeResults(e, my = false) {
+            const {
+                item
+            } = my ? e : e.currentTarget.dataset;
+            let results = this.data.results,
+                sa_brandid = this.data.sa_brandid;
+            if (sa_brandid && sa_brandid != item.sa_brandid) return;
+            if (results.length == 0) {
+                results.push(item.sa_shoppingcartid);
+                sa_brandid = item.sa_brandid;
+            } else {
+                let index = results.findIndex(v => v == item.sa_shoppingcartid)
+                if (index == -1) {
+                    results.push(item.sa_shoppingcartid);
+                } else {
+                    results.splice(index, 1);
+                    if (results.length == 0) sa_brandid = null;
+                }
+            };
+            this.setData({
+                results,
+                sa_brandid
+            })
+            this.computeSum();
+        },
+        /* 计算总价/产品领域分类 */
+        computeSum() {
+            let results = this.data.results,
+                sum = 0,
+                deteleList = [],
+                classList = [];
+            if (results.length) results.forEach((v, i) => {
+                let item = this.data.list.find(va => va.sa_shoppingcartid == v);
+                if (item) {
+                    sum = currency(sum).add(currency(item.qty).multiply(item.oldprice)).value;
+                    /* 领域分类 */
+                    let index = classList.findIndex(value => value.type == item.tradefield_shoppingcart);
+                    if (index == -1) {
+                        classList.push({
+                            type: item.tradefield_shoppingcart,
+                            list: [item],
+                            name: item.tradefield_shoppingcart + "(1件商品)"
+                        })
+                    } else {
+                        classList[index].list.push(item)
+                        classList[index].name = classList[index].type + `(${classList[index].list.length}件商品)`
+                    }
+                } else {
+                    deteleList.push(i)
+                }
+            });
+            if (deteleList.length) {
+                deteleList.forEach(v => {
+                    results.splice(v, 1);
+                });
+                getApp().globalData.num = getApp().globalData.num - deteleList.length;
+            };
+            let sa_brandid = results.length ? this.data.sa_brandid : null;
+            wx.setStorageSync('shopping', {
+                results,
+                sa_brandid
+            })
+            this.setData({
+                sum: CNY(sum),
+                results,
+                sa_brandid,
+                classList
+            });
+            this.setLogisticsMsg(sum)
+        },
+        /* 免运费信息 */
+        setLogisticsMsg(sum) {
+            let logistics = null,
+                figure = this.data.figure;
+            if (figure == -1) {
+                logistics = '到付'
+            } else if (figure == 0) {
+                logistics = '预付'
+            } else {
+                logistics = sum >= figure ? '免运费' : '差' + currency(currency(figure).subtract(sum).value, {
+                    symbol: "",
+                    precision: 2
+                }).format() + '元免运费';
             }
-          })
-        }
-      }).then(res => {
-        console.log("转化订单", res)
-        if (res.msg != '成功') return wx.showToast({
-          title: res.msg,
-          icon: "none"
-        });
-        wx.showModal({
-          title: '提示',
-          content: '生成成功!是否立即前往',
-          complete: (s) => {
-            if (s.confirm) {
-              wx.navigateTo({
-                url: '/packageA/orderForm/detail?id=' + res.data.sa_orderid,
-              })
+            this.setData({
+                logistics
+            })
+        },
+        /* 删除产品 */
+        deteleItem(e) {
+            const {
+                item
+            } = e.currentTarget.dataset;
+            _Http.basic({
+                "id": 20220924095202,
+                "content": {
+                    "sa_shoppingcartids": [item.sa_shoppingcartid]
+                }
+            }).then(res => {
+                if (res.msg != '成功') return wx.showToast({
+                    title: res.msg,
+                    icon: "none"
+                });
+                this.setData({
+                    list: this.data.list.filter(v => v.sa_shoppingcartid != item.sa_shoppingcartid)
+                })
+                if (this.data.results.some(v => v == item.sa_shoppingcartid)) this.changeResults({
+                    item
+                }, true);
+                getApp().globalData.num = getApp().globalData.num - 1;
+            })
+        },
+        /* 步进器输入框失去焦点 */
+        inputBlur(e) {
+            const {
+                index
+            } = e.currentTarget.dataset;
+            let item = this.data.list[index];
+            let qty = 0;
+            if (item.orderminqty > e.detail.value) {
+                wx.showToast({
+                    title: '输入数量低于最低起订量!',
+                    icon: "none"
+                })
+                qty = item.orderminqty;
+            } else if (item.orderminqty < e.detail.value) {
+                var currencyRounding = value => currency(value, {
+                    increment: item.orderaddqty
+                });
+                qty = currency(currencyRounding(currency(e.detail.value).subtract(item.orderminqty)).format()).add(item.orderminqty).value;
+
+            } else {
+                qty = e.detail.value;
             }
-          }
-        });
-        this.getList();
-      })
-    },
-    /* 切换选中项 */
-    changeResults(e, my = false) {
-      const {
-        item
-      } = my ? e : e.currentTarget.dataset;
-      let results = this.data.results,
-        sa_brandid = this.data.sa_brandid;
-      if (sa_brandid && sa_brandid != item.sa_brandid) return;
-      if (results.length == 0) {
-        results.push(item.sa_shoppingcartid);
-        sa_brandid = item.sa_brandid;
-      } else {
-        let index = results.findIndex(v => v == item.sa_shoppingcartid)
-        if (index == -1) {
-          results.push(item.sa_shoppingcartid);
-        } else {
-          results.splice(index, 1);
-          if (results.length == 0) sa_brandid = null;
-        }
-      };
-      this.setData({
-        results,
-        sa_brandid
-      })
-      this.computeSum();
-    },
-    /* 计算总价/产品领域分类 */
-    computeSum() {
-      let results = this.data.results,
-        sum = 0,
-        deteleList = [],
-        classList = [];
-      if (results.length) results.forEach((v, i) => {
-        let item = this.data.list.find(va => va.sa_shoppingcartid == v);
-        if (item) {
-          sum += item.qty * item.oldprice;
-          /* 领域分类 */
-          let index = classList.findIndex(value => value.type == item.tradefield_shoppingcart);
-          if (index == -1) {
-            classList.push({
-              type: item.tradefield_shoppingcart,
-              list: [item],
-              name: item.tradefield_shoppingcart + "(1件商品)"
+            this.setData({
+                [`list[${index}].qty`]: 0
+            });
+            this.setData({
+                [`list[${index}].qty`]: qty
+            });
+            this.computeSum();
+            clearTimeout(downCount['count' + index])
+            downCount['count' + index] = setTimeout(() => {
+                _Http.basic({
+                    "id": 20220924104302,
+                    "content": {
+                        "sa_shoppingcartid": item.sa_shoppingcartid,
+                        "qty": item.qty
+                    },
+                }, false).then(res => {
+                    console.log("修改数量", res)
+                })
+            }, 2000)
+        },
+        stepperChange(e) {
+            const {
+                index
+            } = e.currentTarget.dataset;
+            let item = this.data.list[index];
+            if (e.type == 'plus') {
+                item.qty += item.orderaddqty
+            } else {
+                item.qty -= item.orderaddqty
+            }
+            this.setData({
+                [`list[${index}]`]: item
             })
-          } else {
-            classList[index].list.push(item)
-            classList[index].name = classList[index].type + `(${classList[index].list.length}件商品)`
-          }
-        } else {
-          deteleList.push(i)
+            this.computeSum();
+            clearTimeout(downCount['count' + index])
+            downCount['count' + index] = setTimeout(() => {
+                _Http.basic({
+                    "id": 20220924104302,
+                    "content": {
+                        "sa_shoppingcartid": item.sa_shoppingcartid,
+                        "qty": item.qty
+                    },
+                }, false).then(res => {
+                    console.log("修改数量", res)
+                })
+            }, 2000)
         }
-      });
-      if (deteleList.length) {
-        deteleList.forEach(v => {
-          results.splice(v, 1);
-        });
-        getApp().globalData.num = getApp().globalData.num - deteleList.length;
-      };
-      let sa_brandid = results.length ? this.data.sa_brandid : null;
-      wx.setStorageSync('shopping', {
-        results,
-        sa_brandid
-      })
-      this.setData({
-        sum: CNY(sum),
-        results,
-        sa_brandid,
-        classList
-      });
-      this.setLogisticsMsg(sum)
-    },
-    /* 免运费信息 */
-    setLogisticsMsg(sum) {
-      let logistics = null,
-        figure = this.data.figure;
-      if (figure == -1) {
-        logistics = '到付'
-      } else if (figure == 0) {
-        logistics = '预付'
-      } else {
-        logistics = sum >= figure ? '免运费' : '差' + currency(currency(figure).subtract(sum).value, {
-          symbol: "",
-          precision: 2
-        }).format() + '元免运费';
-      }
-      this.setData({
-        logistics
-      })
-    },
-    /* 删除产品 */
-    deteleItem(e) {
-      const {
-        item
-      } = e.currentTarget.dataset;
-      _Http.basic({
-        "id": 20220924095202,
-        "content": {
-          "sa_shoppingcartids": [item.sa_shoppingcartid]
-        }
-      }).then(res => {
-        if (res.msg != '成功') return wx.showToast({
-          title: res.msg,
-          icon: "none"
-        });
-        this.setData({
-          list: this.data.list.filter(v => v.sa_shoppingcartid != item.sa_shoppingcartid)
-        })
-        if (this.data.results.some(v => v == item.sa_shoppingcartid)) this.changeResults({
-          item
-        }, true);
-        getApp().globalData.num = getApp().globalData.num - 1;
-      })
-    },
-    /* 步进器调整 */
-    stepperChange(e) {
-      const {
-        index
-      } = e.currentTarget.dataset;
-      let item = this.data.list[index];
-      item.qty = e.detail;
-      this.setData({
-        [`list[${index}]`]: item
-      })
-      this.computeSum();
-      clearTimeout(downCount['count' + index])
-      downCount['count' + index] = setTimeout(() => {
-        _Http.basic({
-          "id": 20220924104302,
-          "content": {
-            "sa_shoppingcartid": item.sa_shoppingcartid,
-            "qty": item.qty
-          },
-        }, false).then(res => {
-          console.log("修改数量", res)
-        })
-      }, 2000)
-    },
-  }
+    }
 })

+ 50 - 50
packageA/shopping/modules/standard/index.wxml

@@ -1,61 +1,61 @@
 <navigator url="#" wx:for="{{list}}" wx:key="itemid" class="item-box">
-	<view class="top" bindtap="changeResults" data-item="{{item}}">
-		<view class="image">
-			<van-image width="100%" height="100%" fit="cover" src="{{item.attinfos[0].subfiles[0].url||item.attinfos[0].url||item.cover}}" use-loading-slot use-error-slot lazy-load>
-				<van-loading slot="loading" type="spinner" size="20" vertical />
-				<text slot="error">加载失败</text>
-			</van-image>
-		</view>
-		<view class="content">
-			<view class="title">
-				<text class="line-1">{{item.itemname}}</text>
-				<text class="iconfont icon-guanlian-shanchu" catchtap="deteleItem" data-item="{{item}}" />
-			</view>
-			<view class="exp">编号:{{item.itemno}}</view>
-			<view class="exp">规格:{{item.spec}}</view>
-			<view class="exp">型号:{{item.model}}</view>
-			<view class="exp">品牌:{{item.brandname}}</view>
-			<view class="exp">领域:{{item.tradefield_shoppingcart}}</view>
-			<view class="exp"><text style="font-size: 24rpx;font-weight: 600;color: #FF3B30;">{{item.showPrice}}</text></view><!-- /<text style="font-size: 20rpx;">¥{{item.oldprice}}</text> -->
-		</view>
-	</view>
-	<view class="bottom">
-		<view class="check" bindtap="changeResults" data-item="{{item}}">
-			<van-checkbox shape='square' disabled="{{sa_brandid && sa_brandid!=item.sa_brandid}}" icon-size='24rpx' label-class='label-class' value="{{ decide.checked(item.sa_shoppingcartid,results) }}" bind:change="onChange">
-				起订量:{{item.orderminqty}},增减量:{{item.orderaddqty}}
-			</van-checkbox>
-		</view><!--  max='{{item.cansaleqty}}' -->
-		<van-stepper value="{{ item.qty }}" min="{{item.orderminqty}}" step="{{item.orderaddqty}}" disable-input input-class='input-class' data-index="{{index}}" catch:change="stepperChange" />
-	</view>
+    <view class="top" bindtap="changeResults" data-item="{{item}}">
+        <view class="image">
+            <van-image width="100%" height="100%" fit="cover" src="{{item.attinfos[0].subfiles[0].url||item.attinfos[0].url||item.cover}}" use-loading-slot use-error-slot lazy-load>
+                <van-loading slot="loading" type="spinner" size="20" vertical />
+                <text slot="error">加载失败</text>
+            </van-image>
+        </view>
+        <view class="content">
+            <view class="title">
+                <text class="line-1">{{item.itemname}}</text>
+                <text class="iconfont icon-guanlian-shanchu" catchtap="deteleItem" data-item="{{item}}" />
+            </view>
+            <view class="exp">编号:{{item.itemno}}</view>
+            <view class="exp">规格:{{item.spec}}</view>
+            <view class="exp">型号:{{item.model}}</view>
+            <view class="exp">品牌:{{item.brandname}}</view>
+            <view class="exp">领域:{{item.tradefield_shoppingcart}}</view>
+            <view class="exp"><text style="font-size: 24rpx;font-weight: 600;color: #FF3B30;">{{item.showPrice}}</text></view><!-- /<text style="font-size: 20rpx;">¥{{item.oldprice}}</text> -->
+        </view>
+    </view>
+    <view class="bottom">
+        <view class="check" bindtap="changeResults" data-item="{{item}}">
+            <van-checkbox shape='square' disabled="{{sa_brandid && sa_brandid!=item.sa_brandid}}" icon-size='24rpx' label-class='label-class' value="{{ decide.checked(item.sa_shoppingcartid,results) }}" bind:change="onChange">
+                起订量:{{item.orderminqty}},增减量:{{item.orderaddqty}}
+            </van-checkbox>
+        </view>
+        <van-stepper value="{{ item.qty }}" min="{{item.orderminqty}}" step="{{item.orderaddqty}}" input-class='input-class' data-index="{{index}}" bind:minus='stepperChange' bind:plus='stepperChange' bind:blur='inputBlur' />
+    </view>
 </navigator>
 <Yl_Empty wx:if="{{list.length === 0}}" />
 <!-- 底部 -->
 <view style="height: 130rpx;" />
 <view class="footer">
-	<view class="left">
-		<view class="sum">
-			商品合计:<text>{{sum}}</text>
-		</view>
-		<view class="transport">
-			{{logistics}}
-		</view>
-	</view>
-	<picker wx:if="{{classList.length>=2}}" range='{{classList}}' range-key='name' disabled='{{!results.length}}' bindchange="submit">
-		<van-button custom-class='but' disabled='{{!results.length}}' bind:click="clickBut">生成订单</van-button>
-	</picker>
-	<van-button wx:else custom-class='but' disabled='{{!results.length}}' bind:click="clickBut">生成订单</van-button>
+    <view class="left">
+        <view class="sum">
+            商品合计:<text>{{sum}}</text>
+        </view>
+        <view class="transport">
+            {{logistics}}
+        </view>
+    </view>
+    <picker wx:if="{{classList.length>=2}}" range='{{classList}}' range-key='name' disabled='{{!results.length}}' bindchange="submit">
+        <van-button custom-class='but' disabled='{{!results.length}}' bind:click="clickBut">生成订单</van-button>
+    </picker>
+    <van-button wx:else custom-class='but' disabled='{{!results.length}}' bind:click="clickBut">生成订单</van-button>
 </view>
 <wxs module="decide">
-	module.exports = {
-		checked: function (id, list) {
-			return list.some(function (v) {
-				return v == id
-			});
-		}
-	}
+    module.exports = {
+        checked: function (id, list) {
+            return list.some(function (v) {
+                return v == id
+            });
+        }
+    }
 </wxs>
 <wxs module="gap">
-	module.exports.price = function (figure, defaultamount) {
-		return (figure - defaultamount).toFixed(2)
-	}
+    module.exports.price = function (figure, defaultamount) {
+        return (figure - defaultamount).toFixed(2)
+    }
 </wxs>

+ 280 - 235
packageA/shopping/modules/tool/index.js

@@ -1,246 +1,291 @@
 const _Http = getApp().globalData.http,
-  currency = require("../../../../utils/currency"),
-  CNY = sum => currency(sum, {
-    symbol: "¥",
-    precision: 2
-  }).format();
+    currency = require("../../../../utils/currency"),
+    CNY = sum => currency(sum, {
+        symbol: "¥",
+        precision: 2
+    }).format();
 let downCount = {};
 Component({
-  options: {
-    addGlobalClass: true,
-  },
-  properties: {
-    figure: Number
-  },
-  data: {
-    isGet: false,
-    list: [],
-    results: [], //选中结果
-    sa_brandid: null, //当前选中品牌id
-    classList: [], //生成订单时所选
-    sum: 0, //价格合
-  },
-  methods: {
-    /* 获取列表 */
-    getList() {
-      _Http.basic({
-        "id": 20220924095302,
-        "content": {
-          nocache: true,
-          "istool": 1,
-          "pageNumber": 1,
-          "pageSize": getApp().globalData.num + 5,
-          "where": {
-            "condition": ""
-          }
-        }
-      }).then(res => {
-        console.log('购物车列表', res)
-        if (res.msg != '成功') return wx.showToast({
-          title: res.msg,
-          icon: "none"
-        })
-        this.setData({
-          list: res.data.map(v => {
-            v.showPrice = CNY(v.oldprice)
-            return v
-          }),
-          isGet: true
-        });
-
-        if (wx.getStorageSync('shopping_tool')) {
-          this.setData({
-            ...wx.getStorageSync('shopping_tool')
-          });
-          this.computeSum();
-        }
-      })
+    options: {
+        addGlobalClass: true,
     },
-
-    clickBut(e) {
-      this.data.classList.length >= 2 ? wx.showToast({
-        title: '请选择订单领域(订单只允许同品牌/同领域的商品)',
-        icon: "none",
-        duration: 3000
-      }) : this.handleSubmit(0);
+    properties: {
+        figure: Number
     },
-    /* 提交 */
-    submit(e) {
-      this.handleSubmit(e.detail.value)
+    data: {
+        isGet: false,
+        list: [],
+        results: [], //选中结果
+        sa_brandid: null, //当前选中品牌id
+        classList: [], //生成订单时所选
+        sum: 0, //价格合
     },
-    handleSubmit(index) {
-      let data = this.data.classList[index];
-      _Http.basic({
-        "id": 20221128183202,
-        "content": {
-          "istool": 1,
-          "tradefield": data.type, //必选
-          "items": data.list.map(v => {
-            return {
-              "sa_orderitemsid": 0,
-              "itemid": v.itemid,
-              "sa_brandid": v.sa_brandid,
-              "qty": v.qty
+    methods: {
+        /* 获取列表 */
+        getList() {
+            _Http.basic({
+                "id": 20220924095302,
+                "content": {
+                    nocache: true,
+                    "istool": 1,
+                    "pageNumber": 1,
+                    "pageSize": getApp().globalData.num + 5,
+                    "where": {
+                        "condition": ""
+                    }
+                }
+            }).then(res => {
+                console.log('购物车列表', res)
+                if (res.msg != '成功') return wx.showToast({
+                    title: res.msg,
+                    icon: "none"
+                })
+                this.setData({
+                    list: res.data.map(v => {
+                        v.showPrice = CNY(v.oldprice)
+                        return v
+                    }),
+                    isGet: true
+                });
+
+                if (wx.getStorageSync('shopping_tool')) {
+                    this.setData({
+                        ...wx.getStorageSync('shopping_tool')
+                    });
+                    this.computeSum();
+                }
+            })
+        },
+
+        clickBut(e) {
+            this.data.classList.length >= 2 ? wx.showToast({
+                title: '请选择订单领域(订单只允许同品牌/同领域的商品)',
+                icon: "none",
+                duration: 3000
+            }) : this.handleSubmit(0);
+        },
+        /* 提交 */
+        submit(e) {
+            this.handleSubmit(e.detail.value)
+        },
+        handleSubmit(index) {
+            let data = this.data.classList[index];
+            _Http.basic({
+                "id": 20221128183202,
+                "content": {
+                    "istool": 1,
+                    "tradefield": data.type, //必选
+                    "items": data.list.map(v => {
+                        return {
+                            "sa_orderitemsid": 0,
+                            "itemid": v.itemid,
+                            "sa_brandid": v.sa_brandid,
+                            "qty": v.qty
+                        }
+                    })
+                }
+            }).then(res => {
+                console.log("转化订单", res)
+                if (res.msg != '成功') return wx.showToast({
+                    title: 'res.msg',
+                    icon: "none"
+                });
+                wx.showModal({
+                    title: '提示',
+                    content: '生成成功!是否立即前往',
+                    complete: (s) => {
+                        if (s.confirm) {
+                            wx.navigateTo({
+                                url: '/packageA/orderForm/detail?id=' + res.data.sa_orderid,
+                            })
+                        }
+                    }
+                });
+                this.getList();
+            })
+        },
+        /* 切换选中项 */
+        changeResults(e, my = false) {
+            const {
+                item
+            } = my ? e : e.currentTarget.dataset;
+            let results = this.data.results,
+                sa_brandid = this.data.sa_brandid;
+            if (sa_brandid && sa_brandid != item.sa_brandid) return;
+            if (results.length == 0) {
+                results.push(item.sa_shoppingcartid);
+                sa_brandid = item.sa_brandid;
+            } else {
+                let index = results.findIndex(v => v == item.sa_shoppingcartid)
+                if (index == -1) {
+                    results.push(item.sa_shoppingcartid);
+                } else {
+                    results.splice(index, 1);
+                    if (results.length == 0) sa_brandid = null;
+                }
+            };
+            this.setData({
+                results,
+                sa_brandid
+            })
+            this.computeSum();
+        },
+        /* 计算总价/产品领域分类 */
+        computeSum() {
+            let results = this.data.results,
+                sum = 0,
+                deteleList = [],
+                classList = [];
+            if (results.length) results.forEach((v, i) => {
+                let item = this.data.list.find(va => va.sa_shoppingcartid == v);
+                if (item) {
+                    sum = currency(sum).add(currency(item.qty).multiply(item.oldprice)).value;
+                    /* 领域分类 */
+                    let index = classList.findIndex(value => value.type == item.tradefield_shoppingcart);
+                    if (index == -1) {
+                        classList.push({
+                            type: item.tradefield_shoppingcart,
+                            list: [item],
+                            name: item.tradefield_shoppingcart + "(1件商品)"
+                        })
+                    } else {
+                        classList[index].list.push(item)
+                        classList[index].name = classList[index].type + `(${classList[index].list.length}件商品)`
+                    }
+                } else {
+                    deteleList.push(i)
+                }
+            });
+            if (deteleList.length) {
+                deteleList.forEach(v => {
+                    results.splice(v, 1);
+                });
+                getApp().globalData.num = getApp().globalData.num - deteleList.length;
+            };
+            let sa_brandid = results.length ? this.data.sa_brandid : null;
+            wx.setStorageSync('shopping_tool', {
+                results,
+                sa_brandid
+            })
+            this.setData({
+                sum: CNY(sum),
+                results,
+                sa_brandid,
+                classList
+            })
+            this.setLogisticsMsg(sum)
+        },
+        /* 免运费信息 */
+        setLogisticsMsg(sum) {
+            let logistics = null,
+                figure = this.data.figure;
+            if (figure == -1) {
+                logistics = '到付'
+            } else if (figure == 0) {
+                logistics = '预付'
+            } else {
+                logistics = sum >= figure ? '免运费' : '差' + currency(currency(figure).subtract(sum).value, {
+                    symbol: "",
+                    precision: 2
+                }).format() + '元免运费';
             }
-          })
-        }
-      }).then(res => {
-        console.log("转化订单", res)
-        if (res.msg != '成功') return wx.showToast({
-          title: 'res.msg',
-          icon: "none"
-        });
-        wx.showModal({
-          title: '提示',
-          content: '生成成功!是否立即前往',
-          complete: (s) => {
-            if (s.confirm) {
-              wx.navigateTo({
-                url: '/packageA/orderForm/detail?id=' + res.data.sa_orderid,
-              })
+            this.setData({
+                logistics
+            })
+        },
+        /* 删除产品 */
+        deteleItem(e) {
+            const {
+                item
+            } = e.currentTarget.dataset,
+                that = this;
+            _Http.basic({
+                "id": 20220924095202,
+                "content": {
+                    "sa_shoppingcartids": [item.sa_shoppingcartid]
+                }
+            }).then(res => {
+                if (res.msg != '成功') return wx.showToast({
+                    title: res.msg,
+                    icon: "none"
+                });
+                this.setData({
+                    list: that.data.list.filter(v => v.sa_shoppingcartid != item.sa_shoppingcartid)
+                })
+                if (that.data.results.some(v => v == item.sa_shoppingcartid)) that.changeResults({
+                    item
+                }, true);
+                getApp().globalData.num = getApp().globalData.num - 1;
+            })
+        },
+        /* 步进器输入框失去焦点 */
+        inputBlur(e) {
+            const {
+                index
+            } = e.currentTarget.dataset;
+            let item = this.data.list[index];
+            let qty = 0;
+            if (item.orderminqty > e.detail.value) {
+                wx.showToast({
+                    title: '输入数量低于最低起订量!',
+                    icon: "none"
+                })
+                qty = item.orderminqty;
+            } else if (item.orderminqty < e.detail.value) {
+                var currencyRounding = value => currency(value, {
+                    increment: item.orderaddqty
+                });
+                qty = currency(currencyRounding(currency(e.detail.value).subtract(item.orderminqty)).format()).add(item.orderminqty).value;
+
+            } else {
+                qty = e.detail.value;
             }
-          }
-        });
-        this.getList();
-      })
-    },
-    /* 切换选中项 */
-    changeResults(e, my = false) {
-      const {
-        item
-      } = my ? e : e.currentTarget.dataset;
-      let results = this.data.results,
-        sa_brandid = this.data.sa_brandid;
-      if (sa_brandid && sa_brandid != item.sa_brandid) return;
-      if (results.length == 0) {
-        results.push(item.sa_shoppingcartid);
-        sa_brandid = item.sa_brandid;
-      } else {
-        let index = results.findIndex(v => v == item.sa_shoppingcartid)
-        if (index == -1) {
-          results.push(item.sa_shoppingcartid);
-        } else {
-          results.splice(index, 1);
-          if (results.length == 0) sa_brandid = null;
-        }
-      };
-      this.setData({
-        results,
-        sa_brandid
-      })
-      this.computeSum();
-    },
-    /* 计算总价/产品领域分类 */
-    computeSum() {
-      let results = this.data.results,
-        sum = 0,
-        deteleList = [],
-        classList = [];
-      if (results.length) results.forEach((v, i) => {
-        let item = this.data.list.find(va => va.sa_shoppingcartid == v);
-        if (item) {
-          sum += item.qty * item.oldprice;
-          /* 领域分类 */
-          let index = classList.findIndex(value => value.type == item.tradefield_shoppingcart);
-          if (index == -1) {
-            classList.push({
-              type: item.tradefield_shoppingcart,
-              list: [item],
-              name: item.tradefield_shoppingcart + "(1件商品)"
+            this.setData({
+                [`list[${index}].qty`]: 0
+            });
+            this.setData({
+                [`list[${index}].qty`]: qty
+            });
+            this.computeSum();
+            clearTimeout(downCount['count' + index])
+            downCount['count' + index] = setTimeout(() => {
+                _Http.basic({
+                    "id": 20220924104302,
+                    "content": {
+                        "sa_shoppingcartid": item.sa_shoppingcartid,
+                        "qty": item.qty
+                    },
+                }, false).then(res => {
+                    console.log("修改数量", res)
+                })
+            }, 2000)
+        },
+        stepperChange(e) {
+            const {
+                index
+            } = e.currentTarget.dataset;
+            let item = this.data.list[index];
+            if (e.type == 'plus') {
+                item.qty += item.orderaddqty
+            } else {
+                item.qty -= item.orderaddqty
+            }
+            this.setData({
+                [`list[${index}]`]: item
             })
-          } else {
-            classList[index].list.push(item)
-            classList[index].name = classList[index].type + `(${classList[index].list.length}件商品)`
-          }
-        } else {
-          deteleList.push(i)
-        }
-      });
-      if (deteleList.length) {
-        deteleList.forEach(v => {
-          results.splice(v, 1);
-        });
-        getApp().globalData.num = getApp().globalData.num - deteleList.length;
-      };
-      let sa_brandid = results.length ? this.data.sa_brandid : null;
-      wx.setStorageSync('shopping_tool', {
-        results,
-        sa_brandid
-      })
-      this.setData({
-        sum: CNY(sum),
-        results,
-        sa_brandid,
-        classList
-      })
-      this.setLogisticsMsg(sum)
-    },
-    /* 免运费信息 */
-    setLogisticsMsg(sum) {
-      let logistics = null,
-        figure = this.data.figure;
-      if (figure == -1) {
-        logistics = '到付'
-      } else if (figure == 0) {
-        logistics = '预付'
-      } else {
-        logistics = sum >= figure ? '免运费' : '差' + currency(currency(figure).subtract(sum).value, {
-          symbol: "",
-          precision: 2
-        }).format() + '元免运费';
-      }
-      this.setData({
-        logistics
-      })
-    },
-    /* 删除产品 */
-    deteleItem(e) {
-      const {
-        item
-      } = e.currentTarget.dataset,
-        that = this;
-      _Http.basic({
-        "id": 20220924095202,
-        "content": {
-          "sa_shoppingcartids": [item.sa_shoppingcartid]
+            this.computeSum();
+            clearTimeout(downCount['count' + index])
+            downCount['count' + index] = setTimeout(() => {
+                _Http.basic({
+                    "id": 20220924104302,
+                    "content": {
+                        "sa_shoppingcartid": item.sa_shoppingcartid,
+                        "qty": item.qty
+                    },
+                }, false).then(res => {
+                    console.log("修改数量", res)
+                })
+            }, 2000)
         }
-      }).then(res => {
-        if (res.msg != '成功') return wx.showToast({
-          title: res.msg,
-          icon: "none"
-        });
-        this.setData({
-          list: that.data.list.filter(v => v.sa_shoppingcartid != item.sa_shoppingcartid)
-        })
-        if (that.data.results.some(v => v == item.sa_shoppingcartid)) that.changeResults({
-          item
-        }, true);
-        getApp().globalData.num = getApp().globalData.num - 1;
-      })
-    },
-    /* 步进器调整 */
-    stepperChange(e) {
-      const {
-        index
-      } = e.currentTarget.dataset;
-      let item = this.data.list[index];
-      item.qty = e.detail;
-      this.setData({
-        [`list[${index}]`]: item
-      })
-      this.computeSum();
-      clearTimeout(downCount['count' + index])
-      downCount['count' + index] = setTimeout(() => {
-        _Http.basic({
-          "id": 20220924104302,
-          "content": {
-            "sa_shoppingcartid": item.sa_shoppingcartid,
-            "qty": item.qty
-          },
-        }, false).then(res => {
-          console.log("修改数量", res)
-        })
-      }, 2000)
-    },
-  }
+    }
 })

+ 2 - 2
packageA/shopping/modules/tool/index.wxml

@@ -25,8 +25,8 @@
                 起订量:{{item.orderminqty}},增减量:{{item.orderaddqty}}
             </van-checkbox>
         </view>
-        <van-stepper value="{{ item.qty }}" min="{{item.orderminqty}}" step="{{item.orderaddqty}}" disable-input input-class='input-class' data-index="{{index}}" catch:change="stepperChange" />
-        <!-- <van-stepper value="{{ item.qty }}" input-class='input-class' data-index="{{index}}" catch:change="stepperChange" /> -->
+        <!-- <van-stepper value="{{ item.qty }}" min="{{item.orderminqty}}" step="{{item.orderaddqty}}" disable-input input-class='input-class' data-index="{{index}}" catch:change="stepperChange" /> -->
+        <van-stepper value="{{ item.qty }}" min="{{item.orderminqty}}" step="{{item.orderaddqty}}" input-class='input-class' data-index="{{index}}" bind:minus='stepperChange' bind:plus='stepperChange' bind:blur='inputBlur' />
     </view>
 </navigator>
 <Yl_Empty wx:if="{{list.length === 0}}" />