|
@@ -14,17 +14,19 @@
|
|
|
<view v-if="item" class="border-#8FC1EC b-radius bg-#fff ov-hd">
|
|
<view v-if="item" class="border-#8FC1EC b-radius bg-#fff ov-hd">
|
|
|
<pack-card :item="item" :dict="{ pt_pack_ref_type }"></pack-card>
|
|
<pack-card :item="item" :dict="{ pt_pack_ref_type }"></pack-card>
|
|
|
</view>
|
|
</view>
|
|
|
- <view class="pd-30 d-flex j-c">
|
|
|
|
|
|
|
+ <view class="pd-30 text-center">
|
|
|
<view class="c-primary f-s-28">
|
|
<view class="c-primary f-s-28">
|
|
|
<span>待关联数量:</span>
|
|
<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>
|
|
<span>{{ item?.unit }}</span>
|
|
|
</view>
|
|
</view>
|
|
|
|
|
+ <view v-if="isLinkingZeroPackage" class="f-s-22 c-ccc">包装存在零包,请先完成零包关联后,在进行非零包的关联</view>
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
|
<view class="d-flex a-c">
|
|
<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" />
|
|
<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>
|
|
</view>
|
|
|
<view class="pl-50">
|
|
<view class="pl-50">
|
|
@@ -85,7 +87,7 @@
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
|
</template>
|
|
</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" />
|
|
<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>
|
|
<span>请选择追溯码</span>
|
|
|
</up-button>
|
|
</up-button>
|
|
@@ -94,7 +96,7 @@
|
|
|
<template #bottom>
|
|
<template #bottom>
|
|
|
<view class="pd3-10-24-20">
|
|
<view class="pd3-10-24-20">
|
|
|
<view class="f-s-28 c-#333 text-center mb-5">此次共关联{{ totalSumCount }}个追溯码</view>
|
|
<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>
|
|
</view>
|
|
|
</template>
|
|
</template>
|
|
|
</z-paging>
|
|
</z-paging>
|
|
@@ -111,11 +113,28 @@ const item = ref<any>(null);
|
|
|
const did = ref('');
|
|
const did = ref('');
|
|
|
const relations = ref<any[]>([]);
|
|
const relations = ref<any[]>([]);
|
|
|
const callbackName = 'refreshCodesRange';
|
|
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获取基地详情
|
|
// 根据id获取基地详情
|
|
|
const getDetailById = async (id: string) => {
|
|
const getDetailById = async (id: string) => {
|
|
|
|
|
+ uni.showLoading({
|
|
|
|
|
+ title: '加载中...',
|
|
|
|
|
+ mask: true,
|
|
|
|
|
+ });
|
|
|
const res = await useClientRequest.get(`/plt-api/app/packTask/${id}`);
|
|
const res = await useClientRequest.get(`/plt-api/app/packTask/${id}`);
|
|
|
if (res && res.code === 200) {
|
|
if (res && res.code === 200) {
|
|
|
item.value = res.data || null;
|
|
item.value = res.data || null;
|
|
|
|
|
+ uni.hideLoading();
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
const onRefresh = () => {
|
|
const onRefresh = () => {
|
|
@@ -125,14 +144,19 @@ const onRefresh = () => {
|
|
|
const totalSumCount = computed(() => {
|
|
const totalSumCount = computed(() => {
|
|
|
return relations.value.reduce((sum, item) => sum + +(item?.sumnCount || 0), 0);
|
|
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
|
|
// 判断节点是否在可视区域内如果在则切换tab createIntersectionObserver
|
|
|
onLoad((options: any) => {
|
|
onLoad((options: any) => {
|
|
|
did.value = options?.packId || getUrlParams(recursiveDecodeURIComponent(options?.q))?.packId || '';
|
|
did.value = options?.packId || getUrlParams(recursiveDecodeURIComponent(options?.q))?.packId || '';
|
|
|
getDetailById(did.value);
|
|
getDetailById(did.value);
|
|
|
- uni.$on('refreshBase', () => {
|
|
|
|
|
- onRefresh();
|
|
|
|
|
- });
|
|
|
|
|
- uni.$on(callbackName, onCodeRangeSelected);
|
|
|
|
|
});
|
|
});
|
|
|
onUnload(() => {
|
|
onUnload(() => {
|
|
|
uni.$off(callbackName, onCodeRangeSelected);
|
|
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}`, {
|
|
const res = await useClientRequest.get(`/plt-api/app/traceCodeLog/checkCodeRange/${row?.form?.id}`, {
|
|
|
...row?.form,
|
|
...row?.form,
|
|
|
});
|
|
});
|
|
|
- console.log(res);
|
|
|
|
|
if (!res || res.code !== 200) {
|
|
if (!res || res.code !== 200) {
|
|
|
row.hasChecked = false;
|
|
row.hasChecked = false;
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
const validCodes = res.data;
|
|
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;
|
|
row.hasChecked = true;
|
|
|
};
|
|
};
|
|
|
// 校验码段是否有用
|
|
// 校验码段是否有用
|
|
@@ -206,22 +239,24 @@ const checkCodesValid = async (data: any) => {
|
|
|
item: data,
|
|
item: data,
|
|
|
form: {
|
|
form: {
|
|
|
id: data?.id,
|
|
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,
|
|
hasChecked: false,
|
|
|
validCodes: [],
|
|
validCodes: [],
|
|
|
sumnCount: 0,
|
|
sumnCount: 0,
|
|
|
});
|
|
});
|
|
|
- console.log(relations.value);
|
|
|
|
|
}
|
|
}
|
|
|
// return [];
|
|
// return [];
|
|
|
};
|
|
};
|
|
|
const onCodeRangeSelected = (data: any) => {
|
|
const onCodeRangeSelected = (data: any) => {
|
|
|
- console.log('选中的码段数据:', data);
|
|
|
|
|
checkCodesValid(data);
|
|
checkCodesValid(data);
|
|
|
|
|
+ uni.$off(callbackName, onCodeRangeSelected);
|
|
|
};
|
|
};
|
|
|
const selectCodes = () => {
|
|
const selectCodes = () => {
|
|
|
const selectedIds = relations.value.map((row) => row?.item?.id).filter((id) => id !== null && id !== undefined);
|
|
const selectedIds = relations.value.map((row) => row?.item?.id).filter((id) => id !== null && id !== undefined);
|
|
|
|
|
+ uni.$on(callbackName, onCodeRangeSelected);
|
|
|
uni.$u.route({
|
|
uni.$u.route({
|
|
|
type: 'navigateTo',
|
|
type: 'navigateTo',
|
|
|
url: '/tools/select-code-section/index',
|
|
url: '/tools/select-code-section/index',
|
|
@@ -249,12 +284,16 @@ const batchLinkCodes = async () => {
|
|
|
});
|
|
});
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
+ if (isTotalCountExceeded(totalSumCount.value)) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
try {
|
|
try {
|
|
|
await uni.showLoading({
|
|
await uni.showLoading({
|
|
|
title: '关联中...',
|
|
title: '关联中...',
|
|
|
mask: true,
|
|
mask: true,
|
|
|
});
|
|
});
|
|
|
const params = {
|
|
const params = {
|
|
|
|
|
+ restFlag: isLinkingZeroPackage.value ? '1' : undefined, // 是否是零包关联
|
|
|
packId: did.value,
|
|
packId: did.value,
|
|
|
relations: relations.value.map((row: any) => row?.validCodes || [])?.flat(),
|
|
relations: relations.value.map((row: any) => row?.validCodes || [])?.flat(),
|
|
|
};
|
|
};
|
|
@@ -266,6 +305,20 @@ const batchLinkCodes = async () => {
|
|
|
});
|
|
});
|
|
|
uni.$emit('refreshPackTaskList');
|
|
uni.$emit('refreshPackTaskList');
|
|
|
uni.$emit('refreshPackTaskDetail');
|
|
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({
|
|
uni.navigateBack({
|
|
|
delta: 1,
|
|
delta: 1,
|
|
|
});
|
|
});
|