diff --git a/src/components/Qrcode/index.vue b/src/components/Qrcode/index.vue index cdb9c25..b70c17a 100644 --- a/src/components/Qrcode/index.vue +++ b/src/components/Qrcode/index.vue @@ -93,7 +93,7 @@ const props = defineProps({ }, loadingText: { type: String, - default: "二维码生成中", + default: "", }, }); diff --git a/src/pages-order/order/components/OrderQrcode/index.vue b/src/pages-order/order/components/OrderQrcode/index.vue index 04e4bf0..3cf66a5 100644 --- a/src/pages-order/order/components/OrderQrcode/index.vue +++ b/src/pages-order/order/components/OrderQrcode/index.vue @@ -18,51 +18,46 @@ - + - {{ props.orderData.commodityName }} - - - - {{ props.orderData.commodityAddress }} + {{ selectedVoucher.name }} - - 总计{{ props.selectedVoucher.count }}{{ props.selectedVoucher.unit }} + + 总计{{ selectedVoucher.count }}{{ selectedVoucher.unit }} - 剩{{ props.selectedVoucher.count - - props.selectedVoucher.writeOffCount }}{{ props.selectedVoucher.unit }}可用 + 剩{{ selectedVoucher.count - selectedVoucher.writeOffCount }}{{ selectedVoucher.unit }}可用 - - - 凭证1 - 此码仅可核销1份 + + + 凭证{{ selectedVoucherList.length > 1 ? currentVoucherIndex + 1 : '' }} + 此码仅可核销{{ selectedVoucher.count - selectedVoucher.writeOffCount }}份 - + - {{ - props.selectedVoucher?.name }} + + {{ selectedVoucher.name }} - + - 1 - /3 + {{ currentVoucherIndex + 1 }} + /{{ selectedVoucherList.length }} 扫码后点击下一张 @@ -72,7 +67,7 @@ - + @@ -117,7 +112,7 @@ const props = defineProps({ }); // Events定义 -const emit = defineEmits(["close", "update:modelValue"]); +const emit = defineEmits(["close", "update:modelValue", "update:selectedVoucherIndex"]); // 弹窗引用 const popupRef = ref(null); @@ -125,10 +120,26 @@ const popupRef = ref(null); // 控制二维码渲染 const showQrcode = ref(false); +// 当前选择的凭证索引 +const currentVoucherIndex = ref(props.selectedVoucherIndex || 0); + +const selectedVoucherList = computed(() => { + const list = props.orderData?.commodityPackageConfig || []; + if (!Array.isArray(list)) return []; + return list.filter((item) => item?.packageStatus === 0); +}); + // 二维码内容 +const selectedVoucher = computed(() => { + const list = selectedVoucherList.value || []; + if (!list.length) return null; + const idx = Math.min(Math.max(Number(currentVoucherIndex.value || 0), 0), list.length - 1); + return list[idx] || null; +}); + const qrcodeVal = computed(() => { const orderId = props.orderData?.orderId || ""; - const voucherName = props.selectedVoucher?.name || ""; + const voucherName = selectedVoucher.value?.name || ""; return orderId ? `${orderId}&${voucherName}` : ""; }); @@ -162,17 +173,65 @@ watch( { immediate: true } ); +// 同步外部 prop -> 内部 index(初始化/外部变更) +watch( + () => props.selectedVoucherIndex, + (newIdx) => { + const len = selectedVoucherList.value.length; + let idx = Number(newIdx || 0); + if (len && idx >= len) idx = 0; + currentVoucherIndex.value = idx; + }, + { immediate: true } +); + +// 当可用凭证列表变化时,确保 currentVoucherIndex 不越界 +watch( + selectedVoucherList, + (list) => { + const len = list.length; + if (len === 0) { + if (currentVoucherIndex.value !== 0) { + currentVoucherIndex.value = 0; + } + return; + } + if (currentVoucherIndex.value >= len) { + currentVoucherIndex.value = 0; + } + }, + { immediate: true } +); + +// 当内部索引变化时,通知父组件(避免无用循环) +watch( + () => currentVoucherIndex.value, + (val, oldVal) => { + if (val !== props.selectedVoucherIndex) { + emit("update:selectedVoucherIndex", val); + } + } +); + const handleClose = () => { emit("update:modelValue", false); emit("close"); }; const upAction = () => { - console.log("点击了上一张"); + const len = selectedVoucherList.value.length; + if (!len) return; + let idx = Number(currentVoucherIndex.value || 0) - 1; + if (idx < 0) idx = len - 1; + currentVoucherIndex.value = idx; }; const downAction = () => { - console.log("点击了下一张"); + const len = selectedVoucherList.value.length; + if (!len) return; + let idx = Number(currentVoucherIndex.value || 0) + 1; + if (idx >= len) idx = 0; + currentVoucherIndex.value = idx; }; diff --git a/src/pages-order/order/components/VoucherList/index.vue b/src/pages-order/order/components/VoucherList/index.vue index 2ef1b41..1ffa2c5 100644 --- a/src/pages-order/order/components/VoucherList/index.vue +++ b/src/pages-order/order/components/VoucherList/index.vue @@ -4,7 +4,8 @@ 核销凭证列表 - {{ item.name }} @@ -14,8 +15,9 @@ - - 出示凭证 + + 出示凭证 + 已核销 @@ -36,6 +38,13 @@ const props = defineProps({ const handleShowQrcode = (item, index) => { console.log("显示核销凭证二维码,凭证信息:", item); + if (item.packageStatus !== 0) { + uni.showToast({ + title: "该凭证已核销使用", + icon: "none", + }); + return; + } emit("selected", { item, index }); }; diff --git a/src/static/scss/padding.scss b/src/static/scss/padding.scss index 6ad2114..de3f33f 100644 --- a/src/static/scss/padding.scss +++ b/src/static/scss/padding.scss @@ -297,6 +297,30 @@ padding-bottom: 24px; } +.p-32 { + padding: 32px; +} +.pt-32 { + padding-top: 32px; +} +.pb-32 { + padding-bottom: 32px; +} +.pl-32 { + padding-left: 32px; +} +.pr-32 { + padding-right: 32px; +} +.px-32 { + padding-left: 32px; + padding-right: 32px; +} +.py-32 { + padding-top: 32px; + padding-bottom: 32px; +} + .pb-safe-area { padding-bottom: Max(env(safe-area-inset-bottom), 12px); }