Quellcode durchsuchen

订单添加产品时 可以调控数量

xiaohaizhao vor 2 Jahren
Ursprung
Commit
ca1154c2d3

+ 0 - 5
packageA/activity/selectProduct/index.js

@@ -167,15 +167,11 @@ Page({
       index
     } = e.currentTarget.dataset;
     let item = this.data.list[index];
-    console.log(item)
-    console.log(item.qty)
-    console.log(item.orderaddqty)
     if (e.type == 'plus') {
       item.qty += (item.orderaddqty) - 0
     } else {
       item.qty -= item.orderaddqty
     }
-    console.log(item.qty)
     this.setData({
       [`list[${index}]`]: item
     })
@@ -183,6 +179,5 @@ Page({
   onUnload() {
     //回收数据
     getApp().globalData.handleSelect = null;
-
   }
 })

+ 2 - 1
packageA/orderForm/modules/product/index.js

@@ -173,6 +173,7 @@ Component({
         },
         /* 处理新增产品 */
         handleSelect(detail) {
+            console.log(detail)
             let that = this;
             wx.showModal({
                 title: '提示',
@@ -186,7 +187,7 @@ Component({
                                 return {
                                     sa_orderitemsid: 0,
                                     "itemid": v.itemid, //商品ID
-                                    "qty": 1, //数量
+                                    "qty": v.qty, //数量
                                     price: this.data.type == '工具订单' ? v.marketprice : v.contractprice
                                 }
                             })

+ 46 - 4
select/product/index.js

@@ -3,7 +3,7 @@ const _Http = getApp().globalData.http,
 import currency from "../../utils/currency";
 Page({
 	data: {
-    hidePrice: wx.getStorageSync('hidePrice'),
+		hidePrice: wx.getStorageSync('hidePrice'),
 		loading: true,
 		params: {}, //请求体
 		result: [], //返回结果
@@ -47,7 +47,7 @@ Page({
 				symbol: "¥",
 				precision: 2
 			}).format();
-			
+
 			let newPrice = this.data.newPrice;
 			res.data = res.data.map(value => {
 				if (value.attinfos.length != 0) {
@@ -58,6 +58,7 @@ Page({
 				if (newPrice) value.newPrice = CNY(value[newPrice] || 0);
 				value.brandName = value.brand.map(name => name.brandname)
 				value.tradefields = value.tradefield.map(name => name.tradefield)
+				value.qty = value.orderminqty;
 				return value;
 			})
 			this.setData({
@@ -140,9 +141,50 @@ Page({
 	onReady() {
 		this.selectComponent("#ListBox").setHeight(".total", this);
 	},
+	/* 步进器输入框失去焦点 */
+	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.setData({
+			[`list[${index}].qty`]: 0
+		});
+		this.setData({
+			[`list[${index}].qty`]: qty
+		});
+	},
+	stepperChange(e) {
+		const {
+			index
+		} = e.currentTarget.dataset;
+		let item = this.data.list[index];
+		if (e.type == 'plus') {
+			item.qty += (item.orderaddqty) - 0
+		} else {
+			item.qty -= item.orderaddqty
+		}
+		this.setData({
+			[`list[${index}]`]: item
+		})
+	},
 	onUnload() {
-		//回收数据
 		getApp().globalData.handleSelect = null;
-
 	}
 })

+ 3 - 1
select/product/index.json

@@ -1,3 +1,5 @@
 {
-	"usingComponents": {}
+	"usingComponents": {
+		"van-stepper": "@vant/weapp/stepper/index"
+	}
 }

+ 26 - 16
select/product/index.scss

@@ -16,9 +16,7 @@ page {
 
 .setclient-list-item {
 	width: 100vw;
-	padding: 0 30rpx;
 	background-color: #FFFFFF;
-	box-sizing: border-box;
 	border-bottom: 1rpx solid #DDDDDD;
 	margin-bottom: 20rpx;
 
@@ -26,9 +24,8 @@ page {
 		display: flex;
 		align-items: center;
 		width: 100%;
-		border-bottom: 1rpx solid #DDDDDD;
+		padding: 20rpx 30rpx;
 		box-sizing: border-box;
-		padding: 20rpx 0;
 
 		.img {
 			flex-shrink: 0;
@@ -100,18 +97,31 @@ page {
 		}
 	}
 
-	.bot {
-		font-size: 24rpx;
-		font-family: PingFang SC-Regular, PingFang SC;
-		color: #999999;
-		height: 72rpx;
-		line-height: 72rpx;
-
-		text {
-			width: 50%;
-			display: inline-block;
-			box-sizing: border-box;
-			padding: 4rpx;
+	.bottom {
+		display: flex;
+		justify-content: space-between;
+		align-items: center;
+		border-top: 1rpx solid #DDDDDD;
+		width: 690rpx;
+		margin: 0 auto;
+		padding: 6rpx 20rpx;
+
+		.check {
+			display: flex;
+			align-items: center;
+			height: 100%;
+			width: 380rpx;
+
+			.label-class {
+				font-size: 24rpx;
+				font-family: PingFang SC-Regular, PingFang SC;
+				color: #999999;
+				margin-left: -6rpx;
+			}
+		}
+
+		.input-class {
+			width: 120rpx;
 		}
 	}
 }

+ 17 - 7
select/product/index.wxml

@@ -5,8 +5,8 @@
 <view class="total">共{{params.content.total}}个</view>
 
 <Yl_ListBox id='ListBox' bind:getlist='getList'>
-    <navigator class="setclient-list-item" url="#" wx:for="{{list}}" wx:key="itemno" data-id="{{item[idname]}}" bindtap="changeResult">
-        <view class="mian">
+    <view class="setclient-list-item" wx:for="{{list}}" wx:key="itemno">
+        <navigator url="#" class="mian" data-id="{{item[idname]}}" bindtap="changeResult">
             <van-checkbox wx:if="{{!radio}}" value="{{ handle.isCheck(item[idname],result) }}" shape="square" icon-size='28rpx' />
             <view class="img" data-file="{{item.attinfos}}" catchtap="viewImage">
                 <van-image width="100%" height="100%" wx:if="{{item.cover}}" src="{{item.cover}}" use-loading-slot use-error-slot lazy-load>
@@ -26,16 +26,26 @@
                     <text>品牌:{{item.brandName}}</text>
                     领域:{{item.tradefields}}
                 </view>
+                <view class="subfield line-1">
+                    型号:{{item.model||' --'}}
+                </view>
+                <view class="subfield line-1">
+                    规格:{{item.spec||' --'}}
+                </view>
                 <view class="price line-1">
                     价格:<text class="num">{{handleHide.query(item.newPrice,hidePrice)}}元</text>
                 </view>
             </view>
+        </navigator>
+        <view class="bottom">
+            <view class="check" bindtap="changeResults" data-item="{{item}}">
+                <view class="label-class">
+                    起订量:{{item.orderminqty}},增减量:{{item.orderaddqty}}
+                </view>
+            </view>
+            <van-stepper value="{{ item.qty }}" min="{{item.orderminqty}}" step="{{item.orderaddqty}}" input-class='input-class' data-index="{{index}}" data-iscatch="catch" catch:minus='stepperChange' catch:plus='stepperChange' catch:blur='inputBlur' />
         </view>
-        <view class="bot">
-            <text style="padding-left:0;" class="line-1">型号:{{item.model||' --'}}</text>
-            <text class="line-1">规格:{{item.spec||' --'}}</text>
-        </view>
-    </navigator>
+    </view>
     <view wx:if="{{!radio}}" style="height: 130rpx;" />
     <Yl_Empty wx:if="{{list.length==0}}" />
 </Yl_ListBox>