瀏覽代碼

扫一扫功能:扫条形码把花材加入购物车

shizhongqi 3 月之前
父節點
當前提交
6318cf9e47
共有 2 個文件被更改,包括 62 次插入8 次删除
  1. 0 5
      mallApp/src/mixins/productContrapose.js
  2. 62 3
      mallApp/src/pages/item/item.vue

+ 0 - 5
mallApp/src/mixins/productContrapose.js

@@ -47,7 +47,6 @@ export default {
 					this.initDataContrapose({ type,shopId: this.shopId});
 				}
 			}
-
 		},
 		// async initDataContrapose(extendInfo) {
 		async initDataContrapose(extendInfo) {
@@ -73,10 +72,6 @@ export default {
 			uni.hideLoading();
 		},
 
-
-
-
-
 		/**
 			* 搜索对应花材
 			*/

+ 62 - 3
mallApp/src/pages/item/item.vue

@@ -21,6 +21,11 @@
 						<text class="btn-text">买绿植花束</text>
 					</view>
 				</button>
+				<button @click="scanCode()">
+					<view class="btn-content">
+						<text class="btn-text" style="color: #666;">扫一扫</text>
+					</view>
+				</button>
 			</view>
 		</view>
 
@@ -92,6 +97,11 @@
 				<view class="commodity-view">
 					<view class="summary-bar">
 						<button class="admin-button-com blue middle" style="border:none;" @click.stop="delMemory()">清空购物车</button>
+						<button class="admin-button-com middle" @click.stop="scanCode()" style="padding:16upx 20upx; background:transparent; border: 1px solid #999; display:flex; align-items:center;">
+							<view class="btn-content">
+								<text class="btn-text" style="color: #666; font-size: 28upx;">扫一扫</text>
+							</view>
+						</button>
 					</view>
 					<view class="commodity-list">
 						<view class="commodity-item" v-for="(item, index) in selectList" :key="index">
@@ -497,6 +507,55 @@ export default {
 			} else {
 				this.tabIndex = e.index;
 			}
+		},
+		scanCode(){
+			uni.scanCode({
+				onlyFromCamera: false, // 可从相册识别
+				scanType: ['barCode'],
+				success: (res) => {
+					console.log('扫码结果:', res.result)
+					const itemId = res.result
+
+					let foundItem = null;
+					for (let i = 0; i < this.productInfo.length; i++) {
+						let classItem = this.productInfo[i];
+						if (classItem.child) {
+							for (let j = 0; j < classItem.child.length; j++) {
+								let productItem = classItem.child[j];
+								if (productItem.itemId == itemId) {
+									foundItem = productItem;
+									break;
+								}
+							}
+						}
+						if (foundItem) break;
+					}
+
+					if (foundItem) {
+						const ratio = Number(foundItem.ratio);
+						const selectItem = this.getSelectItemById(foundItem.id, foundItem.classId);
+						const bigCount = selectItem ? (selectItem.bigCount || 0) : 0;
+						const smallCount = selectItem ? (selectItem.smallCount || 0) : 0;
+
+						if(foundItem.stock<=0){
+							uni.showToast({title:'没有货了',icon:'none'})
+							return
+						}
+						if (Number(bigCount) * ratio + Number(smallCount) > Number(foundItem.bigNum) * ratio + Number(foundItem.smallNum)) {
+							this.$msg("库存只剩"+foundItem.bigNum);
+							return
+						}
+						
+						this.addEvent(foundItem);
+						this.cartItemShow = true
+					} else {
+						this.$msg("未找到对应商品");
+					}
+				},
+				fail: (err) => {
+					console.log(err)
+				}
+			})
 		}
 	}
 };
@@ -570,10 +629,10 @@ export default {
 		position: relative;
 		background: #e91e63;
 		border: none;
-		border-radius: 50upx;
+		border-radius: 45upx;
 		padding: 0;
 		height: 80upx;
-		min-width: 200upx;
+		min-width: 210upx;
 		box-shadow: 0 8upx 20upx rgba(233, 30, 99, 0.3);
 		overflow: hidden;
 
@@ -589,7 +648,7 @@ export default {
 		border-radius: 50upx;
 		padding: 0;
 		height: 80upx;
-		min-width: 260upx;
+		min-width: 210upx;
 		box-shadow: 0 8upx 20upx rgba(165, 94, 234, 0.3);
 		overflow: hidden;
 		&:active {