huangxw 1 vecka sedan
förälder
incheckning
c3577de6a2
2 ändrade filer med 93 tillägg och 16 borttagningar
  1. 68 15
      src/plant/packaging/batch-link/index.vue
  2. 25 1
      src/plant/storage/seed-source/detail/index.vue

+ 68 - 15
src/plant/packaging/batch-link/index.vue

@@ -14,17 +14,19 @@
                     <view v-if="item" class="border-#8FC1EC b-radius bg-#fff ov-hd">
                         <pack-card :item="item" :dict="{ pt_pack_ref_type }"></pack-card>
                     </view>
-                    <view class="pd-30 d-flex j-c">
+                    <view class="pd-30 text-center">
                         <view class="c-primary f-s-28">
                             <span>待关联数量:</span>
-                            <span class="f-s-46 f-w-600">{{ item?.planCount - item?.actualCount || 0 }}</span>
+                            <span class="f-s-46 f-w-600">{{ pendingCount }}</span>
                             <span>{{ item?.unit }}</span>
                         </view>
+                        <view v-if="isLinkingZeroPackage" class="f-s-22 c-ccc">包装存在零包,请先完成零包关联后,在进行非零包的关联</view>
                     </view>
                 </view>
                 <view class="d-flex a-c">
                     <image class="w-50 h-50 mr-10" src="https://ta.zycpzs.cn/oss-file/smart-trace/szyy/images-plt/print-codes/glm_icon.png" mode="widthFix" />
-                    <view class="f-s-28 c-#333 f-w-5">本批次信息要关联到哪些(提前预制的)追溯码上?</view>
+                    <view v-if="!isLinkingZeroPackage" class="f-s-28 c-#333 f-w-5">本批次信息要关联到哪些(提前预制的)追溯码上?</view>
+                    <view v-if="isLinkingZeroPackage" class="f-s-28 c-#333 f-w-5">本批次包装存在零包,这个零包要关联到哪个追溯码上?</view>
                 </view>
             </view>
             <view class="pl-50">
@@ -85,7 +87,7 @@
                         </view>
                     </view>
                 </template>
-                <up-button @click="selectCodes" type="primary" plain customStyle="background: #F5F7F5;">
+                <up-button v-if="canSelectMoreCodes" @click="selectCodes" type="primary" plain customStyle="background: #F5F7F5;">
                     <image class="w-36 h-36 mr-10" src="https://ta.zycpzs.cn/oss-file/smart-trace/szyy/images-plt/common/select_push_icon.png" mode="widthFix" />
                     <span>请选择追溯码</span>
                 </up-button>
@@ -94,7 +96,7 @@
         <template #bottom>
             <view class="pd3-10-24-20">
                 <view class="f-s-28 c-#333 text-center mb-5">此次共关联{{ totalSumCount }}个追溯码</view>
-                <up-button @click="batchLinkCodes" type="primary">批量关联</up-button>
+                <up-button @click="batchLinkCodes" type="primary">确认关联</up-button>
             </view>
         </template>
     </z-paging>
@@ -111,11 +113,28 @@ const item = ref<any>(null);
 const did = ref('');
 const relations = ref<any[]>([]);
 const callbackName = 'refreshCodesRange';
+const pendingCount = computed(() => {
+    const planCount = Number(item.value?.planCount || 0);
+    const actualCount = Number(item.value?.actualCount || 0);
+    if (+item.value?.restCapacity && !+item.value?.restRelationFlag) {
+        return 1;
+    }
+    return Math.max(planCount - actualCount, 0);
+});
+// 判断当前是否是在关联零包
+const isLinkingZeroPackage = computed(() => {
+    return +item.value?.restCapacity  && !+item.value?.restRelationFlag;
+});
 // 根据id获取基地详情
 const getDetailById = async (id: string) => {
+    uni.showLoading({
+        title: '加载中...',
+        mask: true,
+    });
     const res = await useClientRequest.get(`/plt-api/app/packTask/${id}`);
     if (res && res.code === 200) {
         item.value = res.data || null;
+        uni.hideLoading();
     }
 };
 const onRefresh = () => {
@@ -125,14 +144,19 @@ const onRefresh = () => {
 const totalSumCount = computed(() => {
     return relations.value.reduce((sum, item) => sum + +(item?.sumnCount || 0), 0);
 });
+const canSelectMoreCodes = computed(() => totalSumCount.value < pendingCount.value);
+const isTotalCountExceeded = (nextTotal: number) => {
+    if (nextTotal <= pendingCount.value) return false;
+    uni.showToast({
+        title: '关联总个数不能大于待关联数量',
+        icon: 'none',
+    });
+    return true;
+};
 // 判断节点是否在可视区域内如果在则切换tab createIntersectionObserver
 onLoad((options: any) => {
     did.value = options?.packId || getUrlParams(recursiveDecodeURIComponent(options?.q))?.packId || '';
     getDetailById(did.value);
-    uni.$on('refreshBase', () => {
-        onRefresh();
-    });
-    uni.$on(callbackName, onCodeRangeSelected);
 });
 onUnload(() => {
     uni.$off(callbackName, onCodeRangeSelected);
@@ -178,14 +202,23 @@ const checkCodesValidItem = async (row: any) => {
     const res = await useClientRequest.get(`/plt-api/app/traceCodeLog/checkCodeRange/${row?.form?.id}`, {
         ...row?.form,
     });
-    console.log(res);
     if (!res || res.code !== 200) {
         row.hasChecked = false;
         return;
     }
     const validCodes = res.data;
-    row.validCodes = validCodes.map((item:any) => ({ ...item, logId: row?.form?.id }));
-    row.sumnCount = validCodes.reduce((sum: number, item: any) => sum + item.count, 0);
+    const nextValidCodes = validCodes.map((item:any) => ({ ...item, logId: row?.form?.id }));
+    const nextRowCount = validCodes.reduce((sum: number, item: any) => sum + item.count, 0);
+    const currentRowCount = Number(row?.sumnCount || 0);
+    const nextTotal = totalSumCount.value - currentRowCount + nextRowCount;
+    if (isTotalCountExceeded(nextTotal)) {
+        row.hasChecked = false;
+        row.validCodes = [];
+        row.sumnCount = 0;
+        return;
+    }
+    row.validCodes = nextValidCodes;
+    row.sumnCount = nextRowCount;
     row.hasChecked = true;
 };
 // 校验码段是否有用
@@ -206,22 +239,24 @@ const checkCodesValid = async (data: any) => {
             item: data,
             form: {
                 id: data?.id,
-                startSn: res.data[0]?.startSn?.toString().padStart(7, '0')
+                startSn: res.data[0]?.startSn?.toString().padStart(7, '0'),
+                // 如果是零包,结束编号默认为起始编号
+                endSn: isLinkingZeroPackage.value ? res.data[0]?.startSn?.toString().padStart(7, '0') : '',
             },
             hasChecked: false,
             validCodes: [],
             sumnCount: 0,
         });
-        console.log(relations.value);
     }
     // return [];
 };
 const onCodeRangeSelected = (data: any) => {
-    console.log('选中的码段数据:', data);
     checkCodesValid(data);
+    uni.$off(callbackName, onCodeRangeSelected);
 };
 const selectCodes = () => {
     const selectedIds = relations.value.map((row) => row?.item?.id).filter((id) => id !== null && id !== undefined);
+    uni.$on(callbackName, onCodeRangeSelected);
     uni.$u.route({
         type: 'navigateTo',
         url: '/tools/select-code-section/index',
@@ -249,12 +284,16 @@ const batchLinkCodes = async () => {
         });
         return;
     }
+    if (isTotalCountExceeded(totalSumCount.value)) {
+        return;
+    }
     try {
         await uni.showLoading({
             title: '关联中...',
             mask: true,
         });
         const params = {
+            restFlag: isLinkingZeroPackage.value ? '1' : undefined, // 是否是零包关联
             packId: did.value,
             relations: relations.value.map((row: any) => row?.validCodes || [])?.flat(),
         };
@@ -266,6 +305,20 @@ const batchLinkCodes = async () => {
         });
         uni.$emit('refreshPackTaskList');
         uni.$emit('refreshPackTaskDetail');
+        if (isLinkingZeroPackage.value) {
+            await uni.showModal({
+                title: '提示',
+                content: '关联成功,请继续关联剩下产品的追溯码信息。',
+                showCancel: false,
+                confirmText: '知道了',
+                confirmColor: '#37A954'
+            });
+            // 清空当前零包关联数据,刷新批次详情,继续进行非零包关联
+            relations.value = [];
+            onRefresh();
+            return
+        }
+        await new Promise((resolve) => setTimeout(resolve, 1000));
         uni.navigateBack({
             delta: 1,
         });

+ 25 - 1
src/plant/storage/seed-source/detail/index.vue

@@ -23,7 +23,7 @@
                     </view>
                 </SeedSourceCard>
             </view>
-            <template v-if="form?.instoreType == '3'">
+            <template v-if="form?.harvestId">
                 <view class="pd-24">
                     <view class="startline-title">采收信息</view>
                 </view>
@@ -47,6 +47,30 @@
                     </view>
                 </view>
             </template>
+            <template v-if="form?.harvestId">
+                <view class="pd-24">
+                    <view class="startline-title">加工信息</view>
+                </view>
+                <view class="bg-#fff pd-24" v-if="form?.harvestInfo">
+                    <view class="f-s-30 pd2-16-0 info-border-bottom">
+                        <span class="c-#666">采收日期:</span>
+                        <span class="c-#333 f-w-600">{{ form?.harvestInfo?.harvestDate || '-' }}至{{ form?.harvestInfo?.harvestDateEnd || '-' }}</span>
+                    </view>
+                    <view class="f-s-30 pd2-16-0 info-border-bottom">
+                        <span class="c-#666">采收批号:</span>
+                        <span class="c-#333 f-w-600">
+                            {{ form?.harvestInfo?.harvestCode || '-' }}
+                        </span>
+                    </view>
+                    <!-- 基地挖坑 -->
+                    <view class="f-s-30 pd2-16-0 info-border-bottom">
+                        <span class="c-#666">种源加工处理工艺:</span>
+                        <span class="c-#333 f-w-600">
+                            {{ form?.harvestInfo?.ptech ? form?.harvestInfo?.ptech.replace(/,/g, '→') : '-' }}
+                        </span>
+                    </view>
+                </view>
+            </template>
             <view class="pd-24">
                 <view class="startline-title">种源信息</view>
             </view>