重构商品模块,支持多规格
This commit is contained in:
169
src/components/SelectSpec/components/select-data.vue
Normal file
169
src/components/SelectSpec/components/select-data.vue
Normal file
@@ -0,0 +1,169 @@
|
||||
<template>
|
||||
<ele-modal
|
||||
:width="750"
|
||||
:visible="visible"
|
||||
:maskClosable="false"
|
||||
:title="title"
|
||||
:footer="null"
|
||||
:body-style="{ paddingBottom: '28px' }"
|
||||
@update:visible="updateVisible"
|
||||
>
|
||||
<ele-pro-table
|
||||
ref="tableRef"
|
||||
row-key="specId"
|
||||
:datasource="datasource"
|
||||
:columns="columns"
|
||||
:customRow="customRow"
|
||||
:pagination="false"
|
||||
>
|
||||
<template #toolbar>
|
||||
<a-input-search
|
||||
allow-clear
|
||||
v-model:value="searchText"
|
||||
placeholder="请输入搜索关键词"
|
||||
style="width: 200px"
|
||||
@search="reload"
|
||||
@pressEnter="reload"
|
||||
/>
|
||||
</template>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'image'">
|
||||
<a-image
|
||||
v-if="record.image"
|
||||
:src="record.image"
|
||||
:preview="false"
|
||||
:width="45"
|
||||
/>
|
||||
</template>
|
||||
<template v-if="column.key === 'specValue'">
|
||||
<a-space direction="vertical">
|
||||
<template
|
||||
v-for="(item, index) in JSON.parse(record.specValue)"
|
||||
:key="index"
|
||||
>
|
||||
<div class="text-left">
|
||||
<span class="text-gray-400 mr-2">{{ item.value }} :</span>
|
||||
<ele-tag
|
||||
shape="round"
|
||||
size="small"
|
||||
v-for="(sub, subIndex) in item.detail"
|
||||
:key="subIndex"
|
||||
>
|
||||
{{ sub }}
|
||||
</ele-tag>
|
||||
</div>
|
||||
</template>
|
||||
</a-space>
|
||||
</template>
|
||||
<template v-if="column.key === 'action'">
|
||||
<a-radio @click="onRadio(record)" />
|
||||
</template>
|
||||
</template>
|
||||
</ele-pro-table>
|
||||
</ele-modal>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref } from 'vue';
|
||||
import {
|
||||
ColumnItem,
|
||||
DatasourceFunction
|
||||
} from 'ele-admin-pro/es/ele-pro-table/types';
|
||||
import { pageSpec } from '@/api/shop/spec';
|
||||
import { EleProTable } from 'ele-admin-pro';
|
||||
import { Spec, SpecParam } from '@/api/shop/spec/model';
|
||||
|
||||
const props = defineProps<{
|
||||
// 弹窗是否打开
|
||||
visible: boolean;
|
||||
// 标题
|
||||
title?: string;
|
||||
// 商户类型
|
||||
shopType?: string;
|
||||
// 修改回显的数据
|
||||
data?: Spec | null;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'done', data: Spec): void;
|
||||
(e: 'update:visible', visible: boolean): void;
|
||||
}>();
|
||||
|
||||
/* 更新visible */
|
||||
const updateVisible = (value: boolean) => {
|
||||
emit('update:visible', value);
|
||||
};
|
||||
|
||||
// 搜索内容
|
||||
const searchText = ref(null);
|
||||
|
||||
// 表格实例
|
||||
const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);
|
||||
|
||||
// 表格配置
|
||||
const columns = ref<ColumnItem[]>([
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
align: 'center'
|
||||
},
|
||||
{
|
||||
title: '规格',
|
||||
dataIndex: 'specName',
|
||||
key: 'specName',
|
||||
align: 'center'
|
||||
},
|
||||
{
|
||||
title: '规格值',
|
||||
dataIndex: 'specValue',
|
||||
key: 'specValue'
|
||||
}
|
||||
]);
|
||||
|
||||
// 表格数据源
|
||||
const datasource: DatasourceFunction = ({ page, limit, where, orders }) => {
|
||||
where = {};
|
||||
// 搜索条件
|
||||
if (searchText.value) {
|
||||
where.keywords = searchText.value;
|
||||
}
|
||||
if (props.shopType == 'empty') {
|
||||
where.emptyType = true;
|
||||
} else {
|
||||
where.shopType = props.shopType;
|
||||
}
|
||||
return pageSpec({
|
||||
...where,
|
||||
...orders,
|
||||
page,
|
||||
limit
|
||||
});
|
||||
};
|
||||
|
||||
/* 搜索 */
|
||||
const reload = (where?: SpecParam) => {
|
||||
tableRef?.value?.reload({ page: 1, where });
|
||||
};
|
||||
|
||||
const onRadio = (record: Spec) => {
|
||||
updateVisible(false);
|
||||
emit('done', record);
|
||||
};
|
||||
|
||||
/* 自定义行属性 */
|
||||
const customRow = (record: Spec) => {
|
||||
return {
|
||||
// 行点击事件
|
||||
// onClick: () => {
|
||||
// updateVisible(false);
|
||||
// emit('done', record);
|
||||
// },
|
||||
// 行双击事件
|
||||
onDblclick: () => {
|
||||
updateVisible(false);
|
||||
emit('done', record);
|
||||
}
|
||||
};
|
||||
};
|
||||
</script>
|
||||
<style lang="less"></style>
|
||||
@@ -1,58 +1,61 @@
|
||||
<!-- 选择下拉框 -->
|
||||
<template>
|
||||
<a-select
|
||||
:allow-clear="allowClear"
|
||||
:show-search="showSearch"
|
||||
optionFilterProp="label"
|
||||
:options="specDict"
|
||||
:value="value"
|
||||
:placeholder="placeholder"
|
||||
@update:value="updateValue"
|
||||
:style="`width: ${width}px`"
|
||||
@blur="onBlur"
|
||||
@change="onChange"
|
||||
/>
|
||||
<div>
|
||||
<a-input-group compact>
|
||||
<a-input
|
||||
disabled
|
||||
style="width: calc(100% - 32px)"
|
||||
v-model:value="value"
|
||||
:placeholder="placeholder"
|
||||
/>
|
||||
<a-button @click="openEdit">
|
||||
<template #icon><BulbOutlined class="ele-text-warning" /></template>
|
||||
</a-button>
|
||||
</a-input-group>
|
||||
<!-- 选择弹窗 -->
|
||||
<SelectData
|
||||
v-model:visible="showEdit"
|
||||
:data="current"
|
||||
:title="placeholder"
|
||||
:customer-type="customerType"
|
||||
@done="onChange"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { BulbOutlined } from '@ant-design/icons-vue';
|
||||
import { ref } from 'vue';
|
||||
import SelectData from './components/select-data.vue';
|
||||
import { Spec } from '@/api/shop/spec/model';
|
||||
|
||||
const props = withDefaults(
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
value?: string;
|
||||
value?: any;
|
||||
customerType?: string;
|
||||
placeholder?: string;
|
||||
showSearch?: string;
|
||||
allowClear?: boolean;
|
||||
width?: number;
|
||||
specDict?: Spec[];
|
||||
index?: number;
|
||||
}>(),
|
||||
{
|
||||
placeholder: '请选择服务器厂商'
|
||||
placeholder: '请选择商户'
|
||||
}
|
||||
);
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:value', value: string): void;
|
||||
(e: 'blur'): void;
|
||||
(e: 'done', value: Spec, index: number): void;
|
||||
(e: 'done', Merchant): void;
|
||||
(e: 'clear'): void;
|
||||
}>();
|
||||
|
||||
/* 更新选中数据 */
|
||||
const updateValue = (value: string) => {
|
||||
emit('update:value', value);
|
||||
// 是否显示编辑弹窗
|
||||
const showEdit = ref(false);
|
||||
// 当前编辑数据
|
||||
const current = ref<Spec | null>(null);
|
||||
|
||||
/* 打开编辑弹窗 */
|
||||
const openEdit = (row?: Spec) => {
|
||||
current.value = row ?? null;
|
||||
showEdit.value = true;
|
||||
};
|
||||
|
||||
/* 失去焦点 */
|
||||
const onBlur = () => {
|
||||
emit('blur');
|
||||
};
|
||||
|
||||
const onChange = (value: string) => {
|
||||
props.specDict?.map((d) => {
|
||||
if (d.value == value) {
|
||||
emit('done', d, Number(props.index));
|
||||
}
|
||||
});
|
||||
const onChange = (row) => {
|
||||
emit('done', row);
|
||||
};
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user