add animated amount

This commit is contained in:
Timi
2026-10-16 18:34:01 +08:00
parent b60fc6bd80
commit fe467e8781
12 changed files with 150 additions and 96 deletions
@@ -0,0 +1,61 @@
<template>
<t-form-item
class="product-selector"
:label="props.label"
:required-mark="props.requiredMark"
content-align="right"
arrow
@click="open"
>
<span class="picker-text" v-text="selectedProductName || props.placeholder" />
</t-form-item>
<product-sku-form-item :sku="selectedSku" :unit="selectedUnit" />
<product-select-popup
v-model="selection"
v-model:visible="popupVisible"
@select="emit('select', $event)"
/>
</template>
<script setup lang="ts">
import ProductSelectPopup from "./ProductSelectPopup.vue";
import type { Product, ProductSelection } from "@/types/Product";
import type { ProductSkuSelectionValue } from "@/types/ProductSkuSelection";
interface Props {
modelValue: ProductSkuSelectionValue | undefined;
selectedProduct?: Product;
label?: string;
requiredMark?: boolean;
placeholder?: string;
}
const props = withDefaults(defineProps<Props>(), { label: "产品", requiredMark: false, placeholder: "请选择产品 SKU" });
const emit = defineEmits<{
"update:modelValue": [value: Props["modelValue"]];
select: [selection: ProductSelection];
}>();
// ---------- 表单回显 ----------
const selection = computed({
get: () => props.modelValue,
set: value => emit("update:modelValue", value)
});
const popupVisible = ref(false);
const selectedProductName = computed(() => props.selectedProduct?.name || "");
const selectedSku = computed(() => props.selectedProduct?.skuList?.find(sku => sku.id === props.modelValue?.skuId));
const selectedUnit = computed(() => selectedSku.value?.unitList?.find(unit => unit.id === props.modelValue?.skuUnitId));
function open(): void {
popupVisible.value = true;
}
</script>
<style scoped lang="less">
.product-selector {
.picker-text {
color: var(--td-text-color-primary);
}
}
</style>
@@ -1,17 +1,4 @@
<template>
<template v-if="props.showField">
<t-form-item
class="product-selector"
:label="props.label"
:required-mark="props.requiredMark"
content-align="right"
arrow
@click="open"
>
<span class="picker-text" v-text="selectedProductName || props.placeholder" />
</t-form-item>
<product-sku-form-item :sku="selectedSku" :unit="selectedUnit" />
</template>
<bottom-popup
v-model="popupVisible"
title="选择产品 SKU"
@@ -50,40 +37,18 @@ import { getProductPhotoURL } from "@/utils/product";
interface Props {
modelValue: ProductSkuSelectionValue | undefined;
visible?: boolean;
showField?: boolean;
selectedProduct?: Product;
label?: string;
requiredMark?: boolean;
placeholder?: string;
}
const props = withDefaults(defineProps<Props>(), { label: "产品", requiredMark: false, placeholder: "请选择产品 SKU", showField: true });
const props = defineProps<Props>();
const emit = defineEmits<{
"update:modelValue": [value: Props["modelValue"]];
"update:visible": [value: boolean];
select: [selection: ProductSelection];
}>();
// ---------- 表单回显 ----------
const productList = ref<Product[]>([]);
const selectedProduct = computed(() => {
const skuId = props.modelValue?.skuId;
if (!skuId) {
return undefined;
}
if (props.selectedProduct?.skuList?.some(sku => sku.id === skuId)) {
return props.selectedProduct;
}
return productList.value.find(product => product.skuList?.some(sku => sku.id === skuId));
});
const selectedProductName = computed(() => selectedProduct.value?.name || "");
const selectedSku = computed(() => selectedProduct.value?.skuList?.find(sku => sku.id === props.modelValue?.skuId));
const selectedUnit = computed(() => selectedSku.value?.unitList?.find(unit => unit.id === props.modelValue?.skuUnitId));
const selectedSkuIdList = computed(() => props.modelValue?.skuId ? [props.modelValue.skuId] : []);
// ---------- 弹窗与产品列表 ----------
const productList = ref<Product[]>([]);
const internalVisible = ref(false);
const popupVisible = computed({
get: () => props.visible ?? internalVisible.value,
@@ -95,6 +60,7 @@ const popupVisible = computed({
const loading = ref(false);
const keyword = ref("");
const expandedProductKeyList = ref<Array<string | number>>([]);
const selectedSkuIdList = computed(() => props.modelValue?.skuId ? [props.modelValue.skuId] : []);
const visibleProductList = computed(() => {
const text = keyword.value.trim().toLocaleLowerCase();
return productList.value.filter(item => !text || `${item.name}${item.code}`.toLocaleLowerCase().includes(text));
@@ -124,10 +90,6 @@ watch(popupVisible, async visible => {
}
});
function open(): void {
popupVisible.value = true;
}
function close(): void {
popupVisible.value = false;
expandedProductKeyList.value = [];
@@ -148,16 +110,10 @@ function selectUnit(selection: ProductSelection): void {
</script>
<style scoped lang="less">
.product-selector {
.picker-text {
color: var(--td-text-color-primary);
}
}
.popup {
height: 100%;
display: flex;
padding: 1rem 0;
padding: 1rem 0 0 0;
overflow: hidden;
min-height: 0;
flex-direction: column;
@@ -188,5 +144,4 @@ function selectUnit(selection: ProductSelection): void {
text-align: center;
}
}
</style>