add ProductStockBatchSelect.vue
This commit is contained in:
@@ -0,0 +1,174 @@
|
||||
<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" />
|
||||
<bottom-popup
|
||||
v-model="visible"
|
||||
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;
|
||||
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 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 visible = ref(false);
|
||||
const loading = ref(false);
|
||||
const keyword = ref("");
|
||||
const expandedProductKeyList = ref<Array<string | number>>([]);
|
||||
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
|
||||
})));
|
||||
|
||||
async function open(): Promise<void> {
|
||||
visible.value = true;
|
||||
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 {
|
||||
visible.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">
|
||||
.product-selector {
|
||||
.picker-text {
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
}
|
||||
|
||||
.popup {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
padding: 1rem 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>
|
||||
@@ -0,0 +1,284 @@
|
||||
<template>
|
||||
<div class="product-sku-selector">
|
||||
<div v-if="specList.length && selectableSkuList.length" class="specs">
|
||||
<div v-for="spec in specList" :key="spec.id || spec.name" class="spec">
|
||||
<strong v-text="spec.name" />
|
||||
<div class="values">
|
||||
<t-button
|
||||
v-for="value in enabledValues(spec)"
|
||||
:key="value.id"
|
||||
size="extra-small"
|
||||
:theme="isSelectedSpecValue(spec.id || '', value.id || '') ? 'primary' : 'default'"
|
||||
:variant="isSelectedSpecValue(spec.id || '', value.id || '') ? 'base' : 'outline'"
|
||||
:content="value.name"
|
||||
@click="selectSpecValue(spec.id || '', value.id || '')"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<template v-if="isMultiple">
|
||||
<t-cell-group v-if="!specList.length && selectableSkuList.length" theme="card" class="sku-list">
|
||||
<t-cell
|
||||
v-for="sku in selectableSkuList"
|
||||
:key="sku.id"
|
||||
:title="sku.name || '未命名 SKU'"
|
||||
:description="getSkuNote(sku)"
|
||||
@click="toggleSku(sku)"
|
||||
>
|
||||
<template #leftIcon>
|
||||
<t-checkbox
|
||||
:model-value="isSelectedSku(sku)"
|
||||
borderless
|
||||
@click.stop
|
||||
@change="toggleSku(sku)"
|
||||
/>
|
||||
</template>
|
||||
</t-cell>
|
||||
</t-cell-group>
|
||||
<div v-else-if="!selectableSkuList.length || isSpecSelectionComplete && !matchedSkuList.length" class="empty" v-text="multipleEmptyText" />
|
||||
</template>
|
||||
<template v-else>
|
||||
<div v-if="matchedSku" class="sku-card">
|
||||
<div class="units">
|
||||
<t-button
|
||||
v-for="unit in saleableUnits(matchedSku)"
|
||||
:key="unit.id"
|
||||
size="small"
|
||||
:theme="isSelectedUnit(matchedSku, unit) ? 'primary' : 'default'"
|
||||
:variant="isSelectedUnit(matchedSku, unit) ? 'base' : 'outline'"
|
||||
@click="selectUnit(matchedSku, unit)"
|
||||
>
|
||||
<span v-text="unit.name" />
|
||||
<span v-if="unit.salePrice !== null && unit.salePrice !== undefined" class="price" v-text="`¥${formatProductAmount(unit.salePrice)}`" />
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="empty" v-text="specList.length && selectableSkuList.length ? '请选择每个规格项的规格值' : '暂无可售 SKU'" />
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { Product, ProductSelection, ProductSku, ProductSkuUnit, ProductSpec, ProductSpecValue } from "@/types/Product";
|
||||
import type { ProductSkuSelectionMode } from "@/types/ProductSkuSelection";
|
||||
import { formatProductAmount } from "@/utils/product";
|
||||
|
||||
interface Props {
|
||||
product: Product;
|
||||
/** 多选时可传入已过滤的 SKU 列表。 */
|
||||
skuList?: ProductSku[];
|
||||
selectedSkuIdList: string[];
|
||||
selectedUnitId?: string;
|
||||
selectionMode?: ProductSkuSelectionMode;
|
||||
emptyText?: string;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), { selectionMode: "single", emptyText: "暂无可选 SKU" });
|
||||
const emit = defineEmits<{
|
||||
select: [selection: ProductSelection];
|
||||
toggle: [sku: ProductSku];
|
||||
}>();
|
||||
|
||||
// ---------- SKU 多选 ----------
|
||||
|
||||
const isMultiple = computed(() => props.selectionMode === "multiple");
|
||||
const selectableSkuList = computed(() => (props.skuList || props.product.skuList || [])
|
||||
.filter(sku => sku.status === "ACTIVE"));
|
||||
|
||||
function getSkuNote(sku: ProductSku): string {
|
||||
return [sku.code, sku.specSummary].filter(Boolean).join(" · ");
|
||||
}
|
||||
|
||||
function isSelectedSku(sku: ProductSku): boolean {
|
||||
return !!sku.id && props.selectedSkuIdList.includes(sku.id);
|
||||
}
|
||||
|
||||
function toggleSku(sku: ProductSku): void {
|
||||
if (isMultiple.value && sku.id) {
|
||||
emit("toggle", sku);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- 规格和销售单位单选 ----------
|
||||
|
||||
const selectedSpecValueMap = reactive<Record<string, string>>({});
|
||||
const selectedSpecValueIdMap = reactive<Record<string, string[]>>({});
|
||||
const specList = computed(() => props.product.specList || []);
|
||||
const isSpecSelectionComplete = computed(() => specList.value.every(spec => !!spec.id && !!selectedSpecValueIdMap[spec.id]?.length));
|
||||
const multipleEmptyText = computed(() => {
|
||||
if (!specList.value.length || !selectableSkuList.value.length) {
|
||||
return props.emptyText;
|
||||
}
|
||||
return isSpecSelectionComplete.value ? "当前规格组合暂无可选 SKU" : "请为每个规格项至少选择一个规格值";
|
||||
});
|
||||
const matchedSkuList = computed(() => selectableSkuList.value.filter(sku =>
|
||||
isSpecSelectionComplete.value && specList.value.every(spec =>
|
||||
sku.specValueIdList?.some(valueId => selectedSpecValueIdMap[spec.id || ""]?.includes(valueId))
|
||||
)
|
||||
));
|
||||
const matchedSku = computed(() => selectableSkuList.value.find(sku =>
|
||||
specList.value.every(spec => sku.specValueIdList?.includes(selectedSpecValueMap[spec.id || ""] || ""))
|
||||
));
|
||||
|
||||
function enabledValues(spec: ProductSpec): ProductSpecValue[] {
|
||||
const precedingSelectedValueIdList: string[][] = [];
|
||||
for (const precedingSpec of specList.value) {
|
||||
if (precedingSpec === spec) {
|
||||
break;
|
||||
}
|
||||
const selectedValueIdList = isMultiple.value
|
||||
? selectedSpecValueIdMap[precedingSpec.id || ""] || []
|
||||
: [selectedSpecValueMap[precedingSpec.id || ""] || ""].filter(Boolean);
|
||||
if (selectedValueIdList.length) {
|
||||
precedingSelectedValueIdList.push(selectedValueIdList);
|
||||
}
|
||||
}
|
||||
return (spec.valueList || []).filter(value => value.enabled !== false && !!value.id && selectableSkuList.value.some(sku => {
|
||||
const skuValueIdList = sku.specValueIdList || [];
|
||||
return skuValueIdList.includes(value.id || "")
|
||||
&& precedingSelectedValueIdList.every(selectedValueIdList => skuValueIdList.some(id => selectedValueIdList.includes(id)));
|
||||
}));
|
||||
}
|
||||
|
||||
function clearUnavailableFollowingValues(specId: string): void {
|
||||
const specIndex = specList.value.findIndex(spec => spec.id === specId);
|
||||
if (specIndex < 0) {
|
||||
return;
|
||||
}
|
||||
for (const spec of specList.value.slice(specIndex + 1)) {
|
||||
if (!spec.id) {
|
||||
continue;
|
||||
}
|
||||
const availableValueList = enabledValues(spec);
|
||||
const availableValueIdSet = new Set(availableValueList.map(value => value.id));
|
||||
if (isMultiple.value) {
|
||||
selectedSpecValueIdMap[spec.id] = (selectedSpecValueIdMap[spec.id] || []).filter(id => availableValueIdSet.has(id));
|
||||
} else if (!availableValueIdSet.has(selectedSpecValueMap[spec.id])) {
|
||||
const firstValueId = availableValueList[0]?.id;
|
||||
if (firstValueId) {
|
||||
selectedSpecValueMap[spec.id] = firstValueId;
|
||||
} else {
|
||||
delete selectedSpecValueMap[spec.id];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function saleableUnits(sku: ProductSku): ProductSkuUnit[] {
|
||||
return (sku.unitList || []).filter(unit => unit.allowSale !== false && unit.id);
|
||||
}
|
||||
|
||||
function isSelectedSpecValue(specId: string, valueId: string): boolean {
|
||||
return isMultiple.value
|
||||
? !!valueId && !!selectedSpecValueIdMap[specId]?.includes(valueId)
|
||||
: selectedSpecValueMap[specId] === valueId;
|
||||
}
|
||||
|
||||
function selectSpecValue(specId: string, valueId: string): void {
|
||||
if (!specId || !valueId) {
|
||||
return;
|
||||
}
|
||||
if (!isMultiple.value) {
|
||||
selectedSpecValueMap[specId] = valueId;
|
||||
clearUnavailableFollowingValues(specId);
|
||||
return;
|
||||
}
|
||||
const selectedValueIdList = selectedSpecValueIdMap[specId] || [];
|
||||
selectedSpecValueIdMap[specId] = selectedValueIdList.includes(valueId)
|
||||
? selectedValueIdList.filter(id => id !== valueId)
|
||||
: [...selectedValueIdList, valueId];
|
||||
clearUnavailableFollowingValues(specId);
|
||||
const matchedSkuIdSet = new Set(matchedSkuList.value.map(sku => sku.id));
|
||||
const selectedSkuIdSet = new Set(props.selectedSkuIdList);
|
||||
for (const sku of selectableSkuList.value) {
|
||||
if (sku.id && selectedSkuIdSet.has(sku.id) !== matchedSkuIdSet.has(sku.id)) {
|
||||
emit("toggle", sku);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function isSelectedUnit(sku: ProductSku, unit: ProductSkuUnit): boolean {
|
||||
return !!sku.id && !!unit.id && props.selectedSkuIdList.includes(sku.id) && props.selectedUnitId === unit.id;
|
||||
}
|
||||
|
||||
function selectUnit(sku: ProductSku, unit: ProductSkuUnit): void {
|
||||
if (!isMultiple.value && sku.id && unit.id) {
|
||||
emit("select", { product: props.product, sku, unit });
|
||||
}
|
||||
}
|
||||
|
||||
watch([() => props.product, () => props.skuList], ([product]) => {
|
||||
Object.keys(selectedSpecValueMap).forEach(key => delete selectedSpecValueMap[key]);
|
||||
Object.keys(selectedSpecValueIdMap).forEach(key => delete selectedSpecValueIdMap[key]);
|
||||
if (isMultiple.value) {
|
||||
const selectedSkuList = selectableSkuList.value.filter(isSelectedSku);
|
||||
const selectedValueIdSet = new Set(selectedSkuList.flatMap(sku => sku.specValueIdList || []));
|
||||
for (const spec of product.specList || []) {
|
||||
if (spec.id) {
|
||||
selectedSpecValueIdMap[spec.id] = enabledValues(spec)
|
||||
.map(value => value.id || "")
|
||||
.filter(id => selectedValueIdSet.has(id));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
const selectedSku = selectableSkuList.value.find(sku => sku.id && props.selectedSkuIdList.includes(sku.id));
|
||||
for (const spec of product.specList || []) {
|
||||
const valueId = selectedSku?.specValueIdList?.find(id => spec.valueList?.some(value => value.id === id))
|
||||
|| enabledValues(spec)[0]?.id;
|
||||
if (spec.id && valueId) {
|
||||
selectedSpecValueMap[spec.id] = valueId;
|
||||
}
|
||||
}
|
||||
}, { immediate: true });
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.product-sku-selector {
|
||||
.specs {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.spec {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.values {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.sku-card {
|
||||
border: .0625rem dashed var(--td-brand-color);
|
||||
padding: .5rem;
|
||||
margin-top: .5rem;
|
||||
border-radius: .875rem;
|
||||
|
||||
.units {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.price {
|
||||
font-size: .75rem;
|
||||
margin-left: .25rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.sku-list {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.empty {
|
||||
color: var(--td-text-color-secondary);
|
||||
padding: 2rem 1rem;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,183 @@
|
||||
<template>
|
||||
<t-collapse
|
||||
v-model="expandedProductKeyList"
|
||||
class="product-sku-selector"
|
||||
theme="card"
|
||||
:expand-mutex="true"
|
||||
@change="handleChange"
|
||||
>
|
||||
<t-collapse-panel
|
||||
v-for="item in props.items"
|
||||
:key="item.key"
|
||||
:value="item.key"
|
||||
class="item"
|
||||
:class="{ direct: isDirectSelect(item) }"
|
||||
:disabled="isDirectSelect(item)"
|
||||
:expand-icon="isDirectSelect(item) ? false : undefined"
|
||||
v-entrance-transition="{ step: 30 }"
|
||||
placement="bottom"
|
||||
@click.capture="handlePanelClick($event, item)"
|
||||
>
|
||||
<template #header>
|
||||
<div class="header">
|
||||
<t-checkbox
|
||||
v-if="props.selectionMode === 'multiple'"
|
||||
class="check"
|
||||
icon="line"
|
||||
:model-value="isProductChecked(item) || isProductPartiallyChecked(item)"
|
||||
:indeterminate="isProductPartiallyChecked(item)"
|
||||
:disabled="item.checkLoading || !getSkuCount(item)"
|
||||
:aria-label="`选择${item.name}`"
|
||||
:aria-checked="isProductPartiallyChecked(item) ? 'mixed' : isProductChecked(item)"
|
||||
borderless
|
||||
@change="toggleProduct(item)"
|
||||
/>
|
||||
<t-image
|
||||
v-if="item.photoUrl"
|
||||
:src="item.photoUrl"
|
||||
:alt="item.name || '产品图片'"
|
||||
fit="cover"
|
||||
class="avatar"
|
||||
/>
|
||||
<div v-else class="avatar fallback" v-text="(item.name || '产').slice(0, 1)" />
|
||||
<strong class="clip-text" v-text="item.name || '未命名产品'" />
|
||||
</div>
|
||||
</template>
|
||||
<div v-if="item.message" class="message" v-text="item.message" />
|
||||
<product-sku-options
|
||||
v-else-if="item.product && openedProductKeySet.has(item.key)"
|
||||
:product="item.product"
|
||||
:sku-list="item.skuList"
|
||||
:selected-sku-id-list="props.selectedSkuIdList"
|
||||
:selected-unit-id="props.selectedUnitId"
|
||||
:selection-mode="props.selectionMode"
|
||||
@select="emit('select', $event)"
|
||||
@toggle="emit('toggle', item.key, $event)"
|
||||
/>
|
||||
</t-collapse-panel>
|
||||
</t-collapse>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { ProductSelection, ProductSku } from "@/types/Product";
|
||||
import type { ProductSkuSelectionMode, ProductSkuSelectorItem } from "@/types/ProductSkuSelection";
|
||||
import ProductSkuOptions from "./ProductSkuOptions.vue";
|
||||
|
||||
interface Props {
|
||||
items: ProductSkuSelectorItem[];
|
||||
selectedSkuIdList: string[];
|
||||
selectedUnitId?: string;
|
||||
selectionMode?: ProductSkuSelectionMode;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), { selectionMode: "single" });
|
||||
const expandedProductKeyList = defineModel<Array<string | number>>("expandedProductKeyList", { default: () => [] });
|
||||
// 首次展开后保留选项内容,供面板收起时计算动画高度。
|
||||
const openedProductKeySet = reactive(new Set<string>());
|
||||
const emit = defineEmits<{
|
||||
change: [value: Array<string | number>];
|
||||
select: [selection: ProductSelection];
|
||||
toggle: [productId: string, sku: ProductSku];
|
||||
check: [productId: string];
|
||||
}>();
|
||||
|
||||
function isDirectSelect(item: ProductSkuSelectorItem): boolean {
|
||||
return props.selectionMode === "multiple" && !!item.singleSkuId;
|
||||
}
|
||||
|
||||
function getSkuCount(item: ProductSkuSelectorItem): number {
|
||||
return item.skuList?.length ?? item.skuCount ?? 0;
|
||||
}
|
||||
|
||||
function getSelectedSkuCount(item: ProductSkuSelectorItem): number {
|
||||
if (!item.skuList) {
|
||||
return item.selectedSkuCount || 0;
|
||||
}
|
||||
return item.skuList.filter(sku => !!sku.id && props.selectedSkuIdList.includes(sku.id)).length;
|
||||
}
|
||||
|
||||
function isProductChecked(item: ProductSkuSelectorItem): boolean {
|
||||
const skuCount = getSkuCount(item);
|
||||
return 0 < skuCount && getSelectedSkuCount(item) === skuCount;
|
||||
}
|
||||
|
||||
function isProductPartiallyChecked(item: ProductSkuSelectorItem): boolean {
|
||||
const selectedCount = getSelectedSkuCount(item);
|
||||
return 0 < selectedCount && selectedCount < getSkuCount(item);
|
||||
}
|
||||
|
||||
function toggleProduct(item: ProductSkuSelectorItem): void {
|
||||
if (props.selectionMode === "multiple" && !item.checkLoading && getSkuCount(item)) {
|
||||
emit("check", item.key);
|
||||
}
|
||||
}
|
||||
|
||||
function handlePanelClick(event: MouseEvent, item: ProductSkuSelectorItem): void {
|
||||
const target = event.target as Element | null;
|
||||
if (!isDirectSelect(item) || !target?.closest(".t-collapse-panel__header") || target.closest(".check")) {
|
||||
return;
|
||||
}
|
||||
event.stopPropagation();
|
||||
toggleProduct(item);
|
||||
}
|
||||
|
||||
function handleChange(value: Array<string | number>): void {
|
||||
emit("change", value);
|
||||
}
|
||||
|
||||
watch(expandedProductKeyList, (keyList) => {
|
||||
for (const key of keyList) {
|
||||
openedProductKeySet.add(String(key));
|
||||
}
|
||||
}, { immediate: true });
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.product-sku-selector {
|
||||
margin: 0;
|
||||
|
||||
.item {
|
||||
--td-collapse-content-padding: .25rem 1rem .75rem 1rem;
|
||||
|
||||
&.direct {
|
||||
pointer-events: auto;
|
||||
--td-collapse-header-text-disabled-color: var(--td-text-color-primary);
|
||||
}
|
||||
|
||||
.header {
|
||||
gap: .75rem;
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
align-items: center;
|
||||
|
||||
.check {
|
||||
flex: 0 0 auto;
|
||||
|
||||
:deep(.t-checkbox__icon) {
|
||||
margin-right: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.avatar {
|
||||
flex: 0 0 auto;
|
||||
width: 2.5rem;
|
||||
height: 2.5rem;
|
||||
border-radius: .75rem !important;
|
||||
}
|
||||
}
|
||||
|
||||
.message {
|
||||
color: var(--td-text-color-secondary);
|
||||
padding: 2rem 1rem;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
:deep(.avatar .t-image__img) {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
border-radius: inherit;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user