add animated amount
This commit is contained in:
@@ -0,0 +1,147 @@
|
||||
<template>
|
||||
<bottom-popup
|
||||
v-model="popupVisible"
|
||||
title="选择产品 SKU"
|
||||
height="80vh"
|
||||
right-button-text=""
|
||||
@left-button-click="close"
|
||||
>
|
||||
<div class="popup">
|
||||
<div class="search-wrap">
|
||||
<t-input v-model="keyword" class="search" borderless placeholder="搜索产品名称或编码" />
|
||||
</div>
|
||||
<div class="items">
|
||||
<product-sku-selector
|
||||
v-if="selectorItemList.length"
|
||||
v-model:expanded-product-key-list="expandedProductKeyList"
|
||||
:items="selectorItemList"
|
||||
:selected-sku-id-list="selectedSkuIdList"
|
||||
:selected-unit-id="props.modelValue?.skuUnitId"
|
||||
@select="selectUnit"
|
||||
/>
|
||||
<div v-else class="empty" v-text="loading ? '正在加载可售产品' : '暂无可售产品'" />
|
||||
</div>
|
||||
</div>
|
||||
</bottom-popup>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { BottomPopup } from "timi-tdesign-mobile";
|
||||
import ProductAPI from "@/api/ProductAPI";
|
||||
import type { Product, ProductSelection } from "@/types/Product";
|
||||
import type { ProductSkuSelectionValue, ProductSkuSelectorItem } from "@/types/ProductSkuSelection";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { Message } from "@/utils/message";
|
||||
import { getProductPhotoURL } from "@/utils/product";
|
||||
|
||||
interface Props {
|
||||
modelValue: ProductSkuSelectionValue | undefined;
|
||||
visible?: boolean;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
const emit = defineEmits<{
|
||||
"update:modelValue": [value: Props["modelValue"]];
|
||||
"update:visible": [value: boolean];
|
||||
select: [selection: ProductSelection];
|
||||
}>();
|
||||
|
||||
// ---------- 弹窗与产品列表 ----------
|
||||
|
||||
const productList = ref<Product[]>([]);
|
||||
const internalVisible = ref(false);
|
||||
const popupVisible = computed({
|
||||
get: () => props.visible ?? internalVisible.value,
|
||||
set: value => {
|
||||
internalVisible.value = value;
|
||||
emit("update:visible", value);
|
||||
}
|
||||
});
|
||||
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));
|
||||
});
|
||||
const selectorItemList = computed<ProductSkuSelectorItem[]>(() => visibleProductList.value.map((product, index) => ({
|
||||
key: getProductKey(product, index),
|
||||
name: product.name || product.code || "未命名产品",
|
||||
photoUrl: getProductPhotoURL(product),
|
||||
product
|
||||
})));
|
||||
|
||||
watch(popupVisible, async visible => {
|
||||
if (!visible) {
|
||||
return;
|
||||
}
|
||||
expandedProductKeyList.value = [];
|
||||
if (loading.value || productList.value.length) {
|
||||
return;
|
||||
}
|
||||
loading.value = true;
|
||||
try {
|
||||
productList.value = await ProductAPI.sellableList({ index: 0, size: 1000 });
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "可售产品加载失败"));
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
});
|
||||
|
||||
function close(): void {
|
||||
popupVisible.value = false;
|
||||
expandedProductKeyList.value = [];
|
||||
}
|
||||
|
||||
function getProductKey(product: Product, index: number): string {
|
||||
return product.id || product.code || `product-${index}`;
|
||||
}
|
||||
|
||||
function selectUnit(selection: ProductSelection): void {
|
||||
if (!selection.sku.id || !selection.unit.id) {
|
||||
return;
|
||||
}
|
||||
emit("select", selection);
|
||||
emit("update:modelValue", { skuId: selection.sku.id, skuUnitId: selection.unit.id });
|
||||
close();
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.popup {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
padding: 1rem 0 0 0;
|
||||
overflow: hidden;
|
||||
min-height: 0;
|
||||
flex-direction: column;
|
||||
|
||||
.search-wrap {
|
||||
z-index: 1;
|
||||
padding: 0 0 .75rem;
|
||||
|
||||
.search {
|
||||
--td-input-vertical-padding: .5rem .875rem;
|
||||
|
||||
margin: 0 1rem;
|
||||
border: .0625rem solid var(--td-component-border);
|
||||
border-radius: .875rem;
|
||||
}
|
||||
}
|
||||
|
||||
.items {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
padding-bottom: env(safe-area-inset-bottom, 0);
|
||||
}
|
||||
|
||||
.empty {
|
||||
color: var(--td-text-color-secondary);
|
||||
padding: 2rem 1rem;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user