add sku total
This commit is contained in:
@@ -1,17 +1,19 @@
|
||||
<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" />
|
||||
<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="visible"
|
||||
v-model="popupVisible"
|
||||
title="选择产品 SKU"
|
||||
height="80vh"
|
||||
right-button-text=""
|
||||
@@ -47,15 +49,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" });
|
||||
const props = withDefaults(defineProps<Props>(), { label: "产品", requiredMark: false, placeholder: "请选择产品 SKU", showField: true });
|
||||
const emit = defineEmits<{
|
||||
"update:modelValue": [value: Props["modelValue"]];
|
||||
"update:visible": [value: boolean];
|
||||
select: [selection: ProductSelection];
|
||||
}>();
|
||||
|
||||
@@ -79,7 +84,14 @@ const selectedSkuIdList = computed(() => props.modelValue?.skuId ? [props.modelV
|
||||
|
||||
// ---------- 弹窗与产品列表 ----------
|
||||
|
||||
const visible = ref(false);
|
||||
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>>([]);
|
||||
@@ -94,8 +106,10 @@ const selectorItemList = computed<ProductSkuSelectorItem[]>(() => visibleProduct
|
||||
product
|
||||
})));
|
||||
|
||||
async function open(): Promise<void> {
|
||||
visible.value = true;
|
||||
watch(popupVisible, async visible => {
|
||||
if (!visible) {
|
||||
return;
|
||||
}
|
||||
expandedProductKeyList.value = [];
|
||||
if (loading.value || productList.value.length) {
|
||||
return;
|
||||
@@ -108,10 +122,14 @@ async function open(): Promise<void> {
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
});
|
||||
|
||||
function open(): void {
|
||||
popupVisible.value = true;
|
||||
}
|
||||
|
||||
function close(): void {
|
||||
visible.value = false;
|
||||
popupVisible.value = false;
|
||||
expandedProductKeyList.value = [];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user