huangxw 1 zi în urmă
părinte
comite
b88fe4910d
1 a modificat fișierele cu 47 adăugiri și 38 ștergeri
  1. 47 38
      src/plant/code/code-query/index.vue

+ 47 - 38
src/plant/code/code-query/index.vue

@@ -3,74 +3,83 @@
         <template #top>
             <ut-navbar title="追溯码查询" :fixed="false"></ut-navbar>
         </template>
-        <view class="pd-20">
+        <view class="pd-24">
             <up-button class="bg-fff" type="primary" plain @click="handleScan">
                 <image class="w-36 h-36 mr-10" src="https://yujin-szyy.oss-cn-chengdu.aliyuncs.com/szyy/images-plt/common/primary_scan.png" mode="widthFix" />
                 <span>请扫描追溯码查询</span>
             </up-button>
         </view>
         <view v-if="!info">
-            <ut-empty class="mg-at" color="#ccc" size="28rpx"
-                image="https://yujin-szyy.oss-cn-chengdu.aliyuncs.com/szyy/images-plt/plant/noEmpty.png">
+            <ut-empty class="mg-at" color="#ccc" size="28rpx" image="https://yujin-szyy.oss-cn-chengdu.aliyuncs.com/szyy/images-plt/plant/noEmpty.png">
                 <view class="text-center">暂无查询结果</view>
                 <view class="text-center">点击上方按钮扫描追溯码查询</view>
             </ut-empty>
         </view>
-        <view v-if="info">
-            <view></view>
+        <view v-if="info" class="pd-24">
+            <view class="f-s-32 c-#333 f-w-5 mb-20">查询结果:</view>
+            <view class="bg-#fff b-radius">
+                <view>
+                    <view></view>
+                </view>
+                <view class="pd-24">
+                    <view class="mb-10">
+                        <span class="f-s-34 c-#333 f-w-5 mr-10">{{ info?.proName || '-' }}</span>
+                        <span class="f-s-24 c-#666">{{ info?.proLevel || '-' }}</span>
+                    </view>
+                    <view class="f-s-28 pd2-4-0">
+                        <span class="c-#666">成品批号:</span>
+                        <span class="c-#333 f-w-5">{{ info?.batchSn || '-' }}</span>
+                    </view>
+                    <view class="f-s-28 pd2-4-0">
+                        <span class="c-#666">包装批号:</span>
+                        <span class="c-#333 f-w-5">{{ info?.packSn || '-' }}</span>
+                    </view>
+                    <view class="d-flex flex-cln j-c a-c">
+                        <up-qrcode cid="ex4asdasdasdasewqeq" :size="uni.$u.getPx('200rpx')" :val="info?.packBatchUrl || ''" showLoading loadingText="loading..."></up-qrcode>
+                        <view class="f-s-26 c-#333 pt-10">点击查看追溯详情</view>
+                    </view>
+                </view>
+            </view>
         </view>
     </z-paging>
 </template>
 
 <script setup lang="ts">
 import { useClientRequest } from '@/utils/request';
+import { getUrlParams, isUrl } from '@/utils/ruoyi';
 const { proxy } = getCurrentInstance() as ComponentInternalInstance;
 const { pt_code_downflag } = toRefs<any>(proxy?.useDict('pt_code_downflag'));
 const paging = ref();
 const info = ref<any>(null);
 // 获取追溯码信息
-const getInfo = async (code: string) => {
-    // 
-}
-
-const getQueryParam = (url: string, key: string) => {
-    const queryIndex = url.indexOf('?');
-    if (queryIndex < 0) {
-        return '';
-    }
-    const query = url.slice(queryIndex + 1);
-    const pairs = query.split('&').filter(Boolean);
-    for (const pair of pairs) {
-        const [rawKey, ...rest] = pair.split('=');
-        if (decodeURIComponent(rawKey || '') !== key) {
-            continue;
-        }
-        return decodeURIComponent((rest.join('=') || '').replace(/\+/g, ' '));
+const getInfo = async (traceCode: string) => {
+    try {
+        const res = await useClientRequest.get('/plt-api/app/packTask/getPackTraceSimpleInfoByTraceCode', { traceCode });
+        info.value = res.data;
+    } catch (error) {
+        console.error('查询追溯码信息失败:', error);
+        info.value = null;
     }
-    return '';
 };
-
-const resolveTraceCode = (result: string) => {
-    const value = (result || '').trim();
-    if (!value) {
-        return '';
-    }
-    // 扫描到地址码时优先取参数 c,普通码则直接返回原值。
-    return getQueryParam(value, 'c') || value;
-};
-
 const handleScan = () => {
     // #ifdef MP-WEIXIN
     uni.scanCode({
         onlyFromCamera: true,
         success: (res) => {
             const result = (res.result || '').trim();
-            const code = resolveTraceCode(result);
-            if (!code) {
+            if (result) {
+                // 判断是否是url
+                if (isUrl(result)) {
+                    const urlParams = getUrlParams(result);
+                    const traceCode = urlParams['c'] || urlParams['code'];
+                    if (traceCode) {
+                        getInfo(traceCode);
+                    }
+                } else {
+                    getInfo(result);
+                }
                 return;
             }
-            console.log('扫码结果:', result);
-            console.log('追溯码:', code);
         },
         fail: () => {},
     });
@@ -78,7 +87,7 @@ const handleScan = () => {
 };
 
 onMounted(() => {
-
+    getInfo('PCC1W12603180000065C4');
 });
 </script>