From a4b95f039ae59662454df8a7541b270006c515c1 Mon Sep 17 00:00:00 2001
From: whycq <10027870+whycq@user.noreply.gitee.com>
Date: 星期三, 22 三月 2023 17:02:01 +0800
Subject: [PATCH] #

---
 pages/pakin/pakin.vue |  155 +++++++++++++++++++++++++++++++++++----------------
 1 files changed, 107 insertions(+), 48 deletions(-)

diff --git a/pages/pakin/pakin.vue b/pages/pakin/pakin.vue
index 56b20c2..6a83b6d 100644
--- a/pages/pakin/pakin.vue
+++ b/pages/pakin/pakin.vue
@@ -3,11 +3,11 @@
 		<view class="code">
 			<view class="item">
 				<view class="code-decs">鎵樼洏鐮�:</view>
-				<input type="text" placeholder=" 鎵爜 / 杈撳叆">
+				<input type="text" placeholder=" 鎵爜 / 杈撳叆" v-model="barcode" :focus="barcodeFocus" @confirm="barcodeInput()">
 			</view>
 			<view class="item">
 				<view class="code-decs">鐗╂枡鐮�:</view>
-				<input type="text" placeholder=" 鎵爜 / 杈撳叆">
+				<input type="text" placeholder=" 鎵爜 / 杈撳叆" v-model="matnr" :focus="matFocus" @input="findMat()">
 				<view class="item-right">
 					<button></button>
 					<text style="text-align: right;color: #409EFF;">鎻愬彇+</text>
@@ -122,52 +122,10 @@
 	export default {
 		data() {
 			return {
-				dataList: 
-				[
-				{
-					matnr: "whycq19950222222-232321111",
-					maktx: "wusuowei",
-					specs: "涓�",
-					batch: "鎵瑰彿",
-					anfme: "100"
-				}, {
-					matnr: "whycq19950520",
-					maktx: "wusuowei",
-					specs: "涓�",
-					batch: "鎵瑰彿",
-					anfme: "12"
-				},{
-					matnr: "whycq19950520",
-					maktx: "wusuowei",
-					specs: "涓�",
-					batch: "鎵瑰彿",
-					anfme: "12"
-				},{
-					matnr: "whycq19950520",
-					maktx: "wusuowei",
-					specs: "涓�",
-					batch: "鎵瑰彿",
-					anfme: "12"
-				},{
-					matnr: "whycq19950520",
-					maktx: "wusuowei",
-					specs: "涓�",
-					batch: "鎵瑰彿",
-					anfme: "12"
-				},{
-					matnr: "whycq19950520",
-					maktx: "wusuowei",
-					specs: "涓�",
-					batch: "鎵瑰彿",
-					anfme: "12"
-				},{
-					matnr: "whycq19950520",
-					maktx: "wusuowei",
-					specs: "涓�",
-					batch: "鎵瑰彿",
-					anfme: "12"
-				}
-				],
+				baseUrl: '',
+				token: '',
+				barcode: '',
+				dataList: [],
 				count: 0,
 				rowNum: '',
 				matnr: '',
@@ -177,17 +135,118 @@
 				messageText: '',
 				title: '',
 				content: '',
+				barcodeFocus: true,
+				matFocus: false,
+				matData: ''
 				
 			}
 		},
 		onLoad() {
 	
 		},
+		onShow() {
+			this.baseUrl = uni.getStorageSync('baseUrl');
+			this.token = uni.getStorageSync('token');
+		},
 		methods: {
 			messageToggle(type) {
 				this.msgType1 = type
 				this.$refs.message.open()
 			},
+			// barcode input 浜嬩欢
+			barcodeInput() {
+				// 涓嶈缃畾鏃跺櫒 浼氬嚭鐜版壂鍏ョ殑瀛楃涓蹭笉鍏�
+				setTimeout(()=>{
+					var len = this.barcode.length
+					if (len != 8) {
+						uni.showToast({title: '鎵樼洏鐮佹湁璇閲嶈瘯', icon: "none", position: 'top'});
+						this.barcodeFocuss()
+						return;
+					}
+					this.focuss()
+				},200)
+			},
+			// 鎵樼洏鐮佹湁璇噸缃�
+			barcodeFocuss() {
+				let that = this;
+				that.barcodeFocus = false;
+				setTimeout(()=>{
+					that.barcode = '';
+					that.barcodeFocus = true;
+				}, 100);
+			},
+			// 鍟嗗搧鍏夋爣娓呯┖閲嶇疆
+			focuss() {
+				// #ifdef APP
+				let that = this;
+				that.focus = false;
+				setTimeout(()=>{
+					that.matnr = '';
+					that.focus = true;
+				}, 100);
+				// #endif
+			},
+			// 鎼滅储鐗╂枡
+			findMat() {
+				let that = this
+				uni.request({
+				    url: that.baseUrl + '/mat/auth',
+				    data: {
+						matnr:that.matnr
+				    },
+				    header: {
+						'token':uni.getStorageSync('token')
+				    },
+					success(result) {
+						result = result.data
+						if (result.code === 200 && result.data) {
+							that.matData = result.data
+							that.matnr = ''
+							that.matData['batch'] = ''
+							uni.navigateTo({
+								url: "../mat/matSelected",
+								// 閫氳繃eventChannel鍚戣鎵撳紑椤甸潰浼犻�佹暟鎹�
+								success: function(res) {
+									res.eventChannel.emit('mat', { data: result.data })
+								},
+								// 涓烘寚瀹氫簨浠舵坊鍔犱竴涓洃鍚櫒锛岃幏鍙栬鎵撳紑椤甸潰浼犻�佸埌褰撳墠椤甸潰鐨勬暟鎹�
+								events: {
+								    dataList: function(data) {
+										that.checkMat(data.data)
+										// that.matList.push(data.data)
+									},
+								},
+							});
+						} else if (res.code == 403) {
+							uni.showToast({title: res.msg, icon: "none", position: 'top'})
+							setTimeout(() => {
+								uni.reLaunch({
+									url: '../login/login'
+								});
+							}, 1000);
+						} else {
+							console.log(res);
+							uni.showToast({title: res.msg, icon: "none",position: 'top'})
+						}
+						
+					}
+				});
+				
+			},
+			checkMat(mat) {
+				var len = this.dataList.length
+				var add = true
+				for (var i = 0; i < len; i++) {
+					if (mat.matnr == this.dataList[i].matnr) {
+						this.dataList[i].anfme += mat.anfme
+						this.$forceUpdate() // 寮哄埗鍒锋柊
+						add = false
+					}
+				}
+				if (add) {
+					this.dataList.unshift(mat)
+				}
+			},
 			// 淇敼鎵瑰彿
 			revise(item,i) {
 				this.matnr = this.dataList[i].matnr

--
Gitblit v1.9.1