From f2485e01843a569549bef74aa65ac44df3cfaa3b Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期二, 03 二月 2026 17:58:21 +0800
Subject: [PATCH] 库存管理-合格库存 增加条形码和二维码

---
 src/views/inventoryManagement/stockManagement/Qualified.vue |  273 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 271 insertions(+), 2 deletions(-)

diff --git a/src/views/inventoryManagement/stockManagement/Qualified.vue b/src/views/inventoryManagement/stockManagement/Qualified.vue
index 92a1b57..64ae3d6 100644
--- a/src/views/inventoryManagement/stockManagement/Qualified.vue
+++ b/src/views/inventoryManagement/stockManagement/Qualified.vue
@@ -47,11 +47,13 @@
         <el-table-column label="搴撳瓨棰勮鏁伴噺" prop="warnNum"  show-overflow-tooltip />
         <el-table-column label="澶囨敞" prop="remark"  show-overflow-tooltip />
         <el-table-column label="鏈�杩戞洿鏂版椂闂�" prop="updateTime" show-overflow-tooltip />
-        <el-table-column fixed="right" label="鎿嶄綔" min-width="60" align="center">
+        <el-table-column fixed="right" label="鎿嶄綔" width="160" align="center">
           <template #default="scope">
             <el-button link type="primary" size="small" @click="showSubtractModal(scope.row)" :disabled="scope.row.unLockedQuantity === 0">棰嗙敤</el-button>
             <el-button link type="primary" size="small" v-if="scope.row.unLockedQuantity > 0" @click="showFrozenModal(scope.row)">鍐荤粨</el-button>
             <el-button link type="primary" size="small" v-if="scope.row.lockedQuantity > 0" @click="showThawModal(scope.row)">瑙e喕</el-button>
+            <el-button link type="success" size="small" @click="showQRCode(scope.row,2)">鐢熸垚鏉″舰鐮�</el-button>
+            <el-button link type="success" size="small" @click="showERCode(scope.row,2)">鐢熸垚浜岀淮鐮�</el-button>
           </template>
         </el-table-column>
       </el-table>
@@ -80,6 +82,109 @@
                  :operation-type="operationType"
                  type="qualified"
                  @completed="handleQuery" />
+
+    <el-dialog
+        v-model="qrCodeDialogVisible"
+        title="鍟嗗搧鏉″舰鐮�"
+        width="400px"
+        center
+    >
+      <div style="text-align: center;">
+        <img id="barcode" style="width:200px;height: 50px;"/>
+        <!-- <img :src="qrCodeUrl" alt="浜岀淮鐮�" style="width:200px;height:200px;" /> -->
+        <div style="margin: 20px;">
+          <el-button type="primary" @click="downloadQRCode">涓嬭浇鏉″舰鐮�</el-button>
+        </div>
+      </div>
+    </el-dialog>
+    <!-- 浜岀淮鐮佹樉绀哄璇濇 -->
+    <el-dialog
+        v-model="erCodeDialogVisible"
+        title="鍟嗗搧浜岀淮鐮�"
+        width="400px"
+        center
+    >
+      <div style="text-align: center;">
+        <img :src="erCodeUrl" alt="浜岀淮鐮�" style="width:200px;height:200px;" />
+        <div style="margin: 20px;">
+          <el-button type="primary" @click="downloadERCode">涓嬭浇浜岀淮鐮佸浘鐗�</el-button>
+        </div>
+      </div>
+    </el-dialog>
+    <el-dialog v-model="barcodeDia" title="浜у搧淇℃伅" width="40%" @close="closeBarcodeDia">
+      <div>
+        <el-row v-if="barcodeDetail.url" :gutter="30">
+          <el-col :span="12">
+            <div class="barcode-item">
+              <div class="barcode-label">鍥剧墖</div>
+              <img class="barcode-img" :src="javaApiUrl+barcodeDetail.url"></img>
+            </div>
+          </el-col>
+        </el-row>
+        <el-row :gutter="30">
+          <el-col :span="12">
+            <div class="barcode-item">
+              <div class="barcode-label">鍚嶇О</div>
+              <div class="barcode-value">{{barcodeDetail.productCategory}}</div>
+            </div>
+          </el-col>
+          <el-col :span="12">
+            <div class="barcode-item">
+              <div class="barcode-label">浜у搧楂樺害</div>
+              <div class="barcode-value">{{barcodeDetail.height}}</div>
+            </div>
+          </el-col>
+
+        </el-row>
+        <el-row :gutter="30">
+          <el-col :span="12">
+            <div class="barcode-item">
+              <div class="barcode-label">鍗曚环(缇庡厓)/浠�</div>
+              <div class="barcode-value">{{barcodeDetail.dollarPrice}}</div>
+            </div>
+          </el-col>
+          <el-col :span="12">
+            <div class="barcode-item">
+              <div class="barcode-label">鍗曚环(鍏�)/浠�</div>
+              <div class="barcode-value">{{barcodeDetail.taxInclusiveUnitPrice}}</div>
+            </div>
+          </el-col>
+        </el-row>
+        <el-row :gutter="30">
+          <el-col :span="12">
+            <div class="barcode-item">
+              <div class="barcode-label">鏁伴噺/浠�</div>
+              <div class="barcode-value">{{barcodeDetail.qualitity}}</div>
+            </div>
+          </el-col>
+          <el-col :span="12">
+            <div class="barcode-item">
+              <div class="barcode-label">姣忎欢鏁伴噺/鏀�</div>
+              <div class="barcode-value">{{barcodeDetail.boxNum}}</div>
+            </div>
+          </el-col>
+        </el-row>
+        <el-row :gutter="30">
+          <el-col :span="12">
+            <div class="barcode-item">
+              <div class="barcode-label">瑙勬牸</div>
+              <div class="barcode-value">{{barcodeDetail.model}}</div>
+            </div>
+          </el-col>
+          <el-col :span="12">
+            <div class="barcode-item">
+              <div class="barcode-label">鍗曚綅</div>
+              <div class="barcode-value">{{barcodeDetail.unit}}</div>
+            </div>
+          </el-col>
+        </el-row>
+      </div>
+      <template #footer>
+        <div class="dialog-footer">
+          <el-button @click="closeBarcodeDia">鍏抽棴</el-button>
+        </div>
+      </template>
+    </el-dialog>
   </div>
 </template>
 
@@ -87,7 +192,14 @@
 import pagination from '@/components/PIMTable/Pagination.vue'
 import { ref, reactive, toRefs, onMounted, getCurrentInstance } from 'vue'
 import {ElMessage, ElMessageBox} from "element-plus";
-import { getStockInventoryListPage, getProductList } from "@/api/inventoryManagement/stockInventory.js";
+import {
+  getStockInventoryListPage,
+  getProductList,
+  getStockInventoryById
+} from "@/api/inventoryManagement/stockInventory.js";
+import QRCode from "qrcode";
+import JsBarcode from "jsbarcode";
+
 const NewStockInventory = defineAsyncComponent(() => import("@/views/inventoryManagement/stockManagement/New.vue"));
 const SubtractStockInventory = defineAsyncComponent(() => import("@/views/inventoryManagement/stockManagement/Subtract.vue"));
 const ImportStockInventory = defineAsyncComponent(() => import("@/views/inventoryManagement/stockManagement/Import.vue"));
@@ -228,7 +340,150 @@
   }
 }
 
+
+// 浜岀淮鐮佺浉鍏冲彉閲�
+const qrCodeDialogVisible = ref(false);
+const qrCodeUrl = ref("");
+const showQRCode = async (row,type) => {
+  if(barcodeDia.value)return
+  try {
+    // 鏋勫缓浜岀淮鐮佸唴瀹癸紝鍙寘鍚噰璐悎鍚屽彿锛堢函鏂囨湰锛�
+    let qrContent = row.id || '';
+    // 妫�鏌ュ唴瀹规槸鍚︿负绌�
+    if (!qrContent) {
+      proxy.$modal.msgWarning("璇ヨ鍟嗗搧id锛屾棤娉曠敓鎴愭潯褰㈢爜");
+      return;
+    }
+    qrContent+=`,${type}`
+    qrCodeDialogVisible.value = true;
+    await nextTick();
+    JsBarcode("#barcode", qrContent+'', {
+      width:10,
+      height:100,
+      displayValue: false
+    });
+  } catch (error) {
+    console.error('鐢熸垚鏉″舰鐮佸け璐�:', error);
+    proxy.$modal.msgError("鐢熸垚鏉″舰鐮佸け璐ワ細" + error.message);
+  }
+};
+
+const erCodeDialogVisible = ref(false);
+const erCodeUrl = ref("");
+const showERCode = async (row,type) => {
+  if(barcodeDia.value)return
+  let qrContent = row.id || '';
+  // 妫�鏌ュ唴瀹规槸鍚︿负绌�
+  if (!qrContent) {
+    proxy.$modal.msgWarning("璇ヨ鍟嗗搧id锛屾棤娉曠敓鎴愪簩缁寸爜");
+    return;
+  }
+  qrContent+=`,${type}`
+  try {
+    erCodeUrl.value = await QRCode.toDataURL(qrContent+'', {
+      width: 200,
+      margin: 2,
+      color: {
+        dark: '#000000',
+        light: '#FFFFFF'
+      }
+    });
+    erCodeDialogVisible.value = true;
+  } catch (error) {
+    console.error('鐢熸垚浜岀淮鐮佸け璐�:', error);
+    proxy.$modal.msgError("鐢熸垚浜岀淮鐮佸け璐ワ細" + error.message);
+  }
+};
+const downloadQRCode = () => {
+  const imgSrc = document.getElementById('barcode').src
+  const a = document.createElement('a');
+  if(!imgSrc){
+    proxy.$modal.msgWarning('鏆傛棤鏉″舰鐮�')
+    return
+  }
+  a.href = imgSrc;
+  a.download = `鍟嗗搧鏉″舰鐮乢${new Date().getTime()}.png`;
+  document.body.appendChild(a);
+  a.click();
+  document.body.removeChild(a);
+  proxy.$modal.msgSuccess("涓嬭浇鎴愬姛");
+};
+
+// 涓嬭浇浜岀淮鐮�
+const downloadERCode = () => {
+  if (!erCodeUrl.value) {
+    proxy.$modal.msgWarning("浜岀淮鐮佹湭鐢熸垚");
+    return;
+  }
+
+  const a = document.createElement('a');
+  a.href = erCodeUrl.value;
+  a.download = `鍟嗗搧浜岀淮鐮乢${new Date().getTime()}.png`;
+  document.body.appendChild(a);
+  a.click();
+  document.body.removeChild(a);
+  proxy.$modal.msgSuccess("涓嬭浇鎴愬姛");
+};
+
+//鎵爜鐩稿叧鍙傛暟
+const barcodeDia = ref(false);
+const scanBarcodeInput = ref('');
+const barcodeDetail = ref({})
+// 鎵爜鍑芥暟
+function scanBarcode (e){
+  if(!e||!e.target||!e.target.tagName){
+    return;
+  }
+  if (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA') {
+    return
+  }
+  if (e.key === 'Enter') {
+    let _value = scanBarcodeInput.value
+    getDetail(_value)
+    scanBarcodeInput.value = ""
+  } else {
+    scanBarcodeInput.value += e.key
+  }
+}
+const getDetail = (barcode)=>{
+  if(barcode.indexOf(",")==-1){
+    proxy.$modal.msgWarning("璇锋壂鎻忔纭殑鏉″舰鐮�")
+    return
+  }
+  let barcodeList = barcode.split(",")
+  let barcodeId = barcodeList[0]
+  let detailApi = getStockInventoryById
+
+  if(!detailApi){
+    proxy.$modal.msgWarning("璇锋壂鎻忔纭殑鏉″舰鐮�")
+    return
+  }
+  detailApi({id:barcodeId}).then((resp) => {
+    if(!resp.data){
+      proxy.$modal.msgError("鍟嗗搧涓嶅瓨鍦�")
+      return
+    }
+    if(resp.code!=200){
+      proxy.$modal.msgError(res.msg)
+      return
+    }
+    barcodeDetail.value = resp.data
+    barcodeDia.value = true
+  }).catch(() => {
+    proxy.$modal.msgError("鏌ョ湅璇︽儏澶辫触")
+  })
+
+}
+
+
+const closeBarcodeDia = () => {
+  barcodeDia.value = false
+}
+
 onMounted(async() => {
+  // 娣诲姞鎵爜鏋洃鍚簨浠�
+  document.removeEventListener('keypress',scanBarcode)
+  document.addEventListener('keypress', scanBarcode)
   await productCategorySelectList()
   await getList()
 })
@@ -243,4 +498,18 @@
 :deep(.row-low-stock:hover > td) {
   background-color: #fcd4d4;
 }
+
+.barcode-item{
+  display: flex;
+  justify-content: space-between;
+  padding: 5px 0;
+
+}
+
+.barcode-img{
+  width: 80px;
+  height: 80px;
+  border-radius: 5px;
+  background-color: #F5F5F5;
+}
 </style>

--
Gitblit v1.9.3