style: 代码统一风格格式化

Former-commit-id: 5d0a75e41127c57c663eb2617b1ce66d039f4c29
This commit is contained in:
郝先瑞
2022-05-08 13:06:12 +08:00
parent 77a71db326
commit eab11687aa
137 changed files with 10635 additions and 10635 deletions

View File

@@ -1,7 +1,7 @@
<!-- setup 无法设置组件名称组件名称keepAlive必须 -->
<script lang="ts">
export default {
name: 'brand'
name: 'brand'
};
</script>
@@ -11,11 +11,11 @@ import { ElForm, ElTable, ElMessage, ElMessageBox } from 'element-plus';
import { Search, Plus, Edit, Refresh, Delete } from '@element-plus/icons-vue';
import { BrandFormData, BrandItem, BrandQueryParam, Dialog } from '@/types';
import {
listBrandPages,
getBrandFormDetail,
updateBrand,
addBrand,
deleteBrands
listBrandPages,
getBrandFormDetail,
updateBrand,
addBrand,
deleteBrands
} from '@/api/pms/brand';
import SingleUpload from '@/components/Upload/SingleUpload.vue';
@@ -23,253 +23,253 @@ const queryFormRef = ref(ElForm); // 属性名必须和元素的ref属性值一
const dataFormRef = ref(ElForm); // 属性名必须和元素的ref属性值一致
const state = reactive({
loading: true,
// 选中ID数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
queryParams: {
pageNum: 1,
pageSize: 10
} as BrandQueryParam,
brandList: [] as BrandItem[],
total: 0,
dialog: {} as Dialog,
formData: { sort: 1 } as BrandFormData,
rules: {
name: [
{
required: true,
message: '请输入品牌名称',
trigger: 'blur'
}
]
}
loading: true,
// 选中ID数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
queryParams: {
pageNum: 1,
pageSize: 10
} as BrandQueryParam,
brandList: [] as BrandItem[],
total: 0,
dialog: {} as Dialog,
formData: { sort: 1 } as BrandFormData,
rules: {
name: [
{
required: true,
message: '请输入品牌名称',
trigger: 'blur'
}
]
}
});
const {
loading,
multiple,
queryParams,
brandList,
total,
dialog,
formData,
rules
loading,
multiple,
queryParams,
brandList,
total,
dialog,
formData,
rules
} = toRefs(state);
function handleQuery() {
state.loading = true;
listBrandPages(state.queryParams).then(({ data }) => {
state.brandList = data.list;
state.total = data.total;
state.loading = false;
});
state.loading = true;
listBrandPages(state.queryParams).then(({ data }) => {
state.brandList = data.list;
state.total = data.total;
state.loading = false;
});
}
function resetQuery() {
queryFormRef.value.resetFields();
handleQuery();
queryFormRef.value.resetFields();
handleQuery();
}
function handleSelectionChange(selection: any) {
state.ids = selection.map((item: any) => item.id);
state.single = selection.length !== 1;
state.multiple = !selection.length;
state.ids = selection.map((item: any) => item.id);
state.single = selection.length !== 1;
state.multiple = !selection.length;
}
function handleAdd() {
state.dialog = {
title: '添加品牌',
visible: true
};
state.dialog = {
title: '添加品牌',
visible: true
};
}
function handleUpdate(row: any) {
state.dialog = {
title: '修改品牌',
visible: true
};
const brandId = row.id || state.ids;
getBrandFormDetail(brandId).then(({ data }) => {
state.formData = data;
});
state.dialog = {
title: '修改品牌',
visible: true
};
const brandId = row.id || state.ids;
getBrandFormDetail(brandId).then(({ data }) => {
state.formData = data;
});
}
/**
* 表单提交
*/
function submitForm() {
dataFormRef.value.validate((isValid: boolean) => {
if (isValid) {
if (state.formData.id) {
updateBrand(state.formData.id, state.formData).then(() => {
ElMessage.success('修改成功');
cancel();
handleQuery();
});
} else {
addBrand(state.formData).then(() => {
ElMessage.success('新增成功');
cancel();
handleQuery();
});
}
}
});
dataFormRef.value.validate((isValid: boolean) => {
if (isValid) {
if (state.formData.id) {
updateBrand(state.formData.id, state.formData).then(() => {
ElMessage.success('修改成功');
cancel();
handleQuery();
});
} else {
addBrand(state.formData).then(() => {
ElMessage.success('新增成功');
cancel();
handleQuery();
});
}
}
});
}
/**
* 取消
*/
function cancel() {
state.dialog.visible = false;
dataFormRef.value.resetFields();
state.dialog.visible = false;
dataFormRef.value.resetFields();
}
/**
* 删除
*/
function handleDelete(row: any) {
const ids = [row.id || state.ids].join(',');
ElMessageBox.confirm('确认删除已选中的数据项?', '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
})
.then(() => {
deleteBrands(ids).then(() => {
ElMessage.success('删除成功');
handleQuery();
});
})
.catch(() => ElMessage.info('已取消删除'));
const ids = [row.id || state.ids].join(',');
ElMessageBox.confirm('确认删除已选中的数据项?', '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
})
.then(() => {
deleteBrands(ids).then(() => {
ElMessage.success('删除成功');
handleQuery();
});
})
.catch(() => ElMessage.info('已取消删除'));
}
onMounted(() => {
handleQuery();
handleQuery();
});
</script>
<template>
<div class="app-container">
<!-- 搜索表单 -->
<el-form ref="queryFormRef" :model="queryParams" :inline="true">
<el-form-item>
<el-button type="success" :icon="Plus" @click="handleAdd"
>新增</el-button
>
<el-button
type="danger"
:icon="Delete"
click="handleDelete"
:disabled="multiple"
>删除</el-button
>
</el-form-item>
<div class="app-container">
<!-- 搜索表单 -->
<el-form ref="queryFormRef" :model="queryParams" :inline="true">
<el-form-item>
<el-button type="success" :icon="Plus" @click="handleAdd"
>新增</el-button
>
<el-button
type="danger"
:icon="Delete"
click="handleDelete"
:disabled="multiple"
>删除</el-button
>
</el-form-item>
<el-form-item prop="name">
<el-input v-model="queryParams.name" placeholder="品牌名称" />
</el-form-item>
<el-form-item prop="name">
<el-input v-model="queryParams.name" placeholder="品牌名称" />
</el-form-item>
<el-form-item>
<el-button type="primary" :icon="Search" @click="handleQuery"
>搜索</el-button
>
<el-button :icon="Refresh" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-form-item>
<el-button type="primary" :icon="Search" @click="handleQuery"
>搜索</el-button
>
<el-button :icon="Refresh" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<!-- 数据表格 -->
<el-table
v-loading="loading"
:data="brandList"
@selection-change="handleSelectionChange"
border
>
<el-table-column type="selection" min-width="5%" />
<el-table-column prop="name" label="品牌名称" min-width="10" />
<el-table-column prop="logoUrl" label="LOGO" min-width="10">
<template #default="scope">
<el-popover placement="right" :width="400" trigger="hover">
<img :src="scope.row.logoUrl" width="400" height="400" />
<template #reference>
<img
:src="scope.row.logoUrl"
style="max-height: 60px; max-width: 60px"
/>
</template>
</el-popover>
</template>
</el-table-column>
<!-- 数据表格 -->
<el-table
v-loading="loading"
:data="brandList"
@selection-change="handleSelectionChange"
border
>
<el-table-column type="selection" min-width="5%" />
<el-table-column prop="name" label="品牌名称" min-width="10" />
<el-table-column prop="logoUrl" label="LOGO" min-width="10">
<template #default="scope">
<el-popover placement="right" :width="400" trigger="hover">
<img :src="scope.row.logoUrl" width="400" height="400" />
<template #reference>
<img
:src="scope.row.logoUrl"
style="max-height: 60px; max-width: 60px"
/>
</template>
</el-popover>
</template>
</el-table-column>
<el-table-column prop="sort" label="排序" min-width="10" />
<el-table-column prop="sort" label="排序" min-width="10" />
<el-table-column label="操作" width="150">
<template #default="scope">
<el-button
@click="handleUpdate(scope.row)"
type="primary"
:icon="Edit"
circle
plain
/>
<el-button
type="danger"
:icon="Delete"
circle
plain
@click="handleDelete(scope.row)"
/>
</template>
</el-table-column>
</el-table>
<el-table-column label="操作" width="150">
<template #default="scope">
<el-button
@click="handleUpdate(scope.row)"
type="primary"
:icon="Edit"
circle
plain
/>
<el-button
type="danger"
:icon="Delete"
circle
plain
@click="handleDelete(scope.row)"
/>
</template>
</el-table-column>
</el-table>
<!-- 分页工具条 -->
<pagination
v-if="total > 0"
:total="total"
v-model:page="queryParams.pageNum"
v-model:limit="queryParams.pageSize"
@pagination="handleQuery"
/>
<!-- 分页工具条 -->
<pagination
v-if="total > 0"
:total="total"
v-model:page="queryParams.pageNum"
v-model:limit="queryParams.pageSize"
@pagination="handleQuery"
/>
<!-- 表单弹窗 -->
<el-dialog
:title="dialog.title"
v-model="dialog.visible"
top="5vh"
width="600px"
>
<el-form
ref="dataFormRef"
:model="formData"
:rules="rules"
label-width="100px"
>
<el-form-item label="品牌名称" prop="name">
<el-input v-model="formData.name" auto-complete="off" />
</el-form-item>
<!-- 表单弹窗 -->
<el-dialog
:title="dialog.title"
v-model="dialog.visible"
top="5vh"
width="600px"
>
<el-form
ref="dataFormRef"
:model="formData"
:rules="rules"
label-width="100px"
>
<el-form-item label="品牌名称" prop="name">
<el-input v-model="formData.name" auto-complete="off" />
</el-form-item>
<el-form-item label="LOGO" prop="logoUrl">
<single-upload v-model="formData.logoUrl" />
</el-form-item>
<el-form-item label="LOGO" prop="logoUrl">
<single-upload v-model="formData.logoUrl" />
</el-form-item>
<el-form-item label="排序" prop="sort">
<el-input v-model="formData.sort" />
</el-form-item>
</el-form>
<el-form-item label="排序" prop="sort">
<el-input v-model="formData.sort" />
</el-form-item>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</template>
</el-dialog>
</div>
<template #footer>
<div class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</template>
</el-dialog>
</div>
</template>
<style scoped></style>

View File

@@ -1,61 +1,61 @@
<template>
<div class="component-container">
<el-card class="box-card" shadow="always">
<el-row>
<el-col :span="12">
<el-tag type="success" v-if="category && category.name"
>{{ category.name }} {{ attributeTypeName }}
</el-tag>
<el-tag v-else type="info"
><i class="el-icon-info"></i> 请选择商品分类</el-tag
>
</el-col>
<el-col :span="12" style="text-align: right">
<el-button type="primary" :icon="Check" @click="submitForm"
>提交</el-button
>
</el-col>
</el-row>
<div class="component-container">
<el-card class="box-card" shadow="always">
<el-row>
<el-col :span="12">
<el-tag type="success" v-if="category && category.name"
>{{ category.name }} {{ attributeTypeName }}
</el-tag>
<el-tag v-else type="info"
><i class="el-icon-info"></i> 请选择商品分类</el-tag
>
</el-col>
<el-col :span="12" style="text-align: right">
<el-button type="primary" :icon="Check" @click="submitForm"
>提交</el-button
>
</el-col>
</el-row>
<el-row style="margin-top: 10px">
<el-form
ref="form"
:model="formData"
:disabled="category?.childrenLen > 0"
label-width="100"
>
<el-form-item
v-for="(item, index) in formData.attributes"
:key="index"
:label="attributeTypeName + (index + 1)"
:prop="'attributes.' + index + '.name'"
:rules="rules.attribute.name"
>
<el-input v-model="item.name" style="width: 300px" />
<el-row style="margin-top: 10px">
<el-form
ref="form"
:model="formData"
:disabled="category?.childrenLen > 0"
label-width="100"
>
<el-form-item
v-for="(item, index) in formData.attributes"
:key="index"
:label="attributeTypeName + (index + 1)"
:prop="'attributes.' + index + '.name'"
:rules="rules.attribute.name"
>
<el-input v-model="item.name" style="width: 300px" />
<el-button
v-if="index === 0"
type="success"
:icon="Plus"
circle
plain
@click.prevent="handleAdd()"
style="margin-left: 15px"
/>
<el-button
v-if="index === 0"
type="success"
:icon="Plus"
circle
plain
@click.prevent="handleAdd()"
style="margin-left: 15px"
/>
<el-button
type="danger"
:icon="Delete"
plain
circle
@click.prevent="handleDelete(index)"
style="margin-left: 15px"
/>
</el-form-item>
</el-form>
</el-row>
</el-card>
</div>
<el-button
type="danger"
:icon="Delete"
plain
circle
@click.prevent="handleDelete(index)"
style="margin-left: 15px"
/>
</el-form-item>
</el-form>
</el-row>
</el-card>
</div>
</template>
<script setup lang="ts">
@@ -65,119 +65,119 @@ import { Plus, Check, Delete } from '@element-plus/icons-vue';
import { ElMessage } from 'element-plus';
const props = defineProps({
attributeType: {
type: Number,
default: 1
},
category: {
type: Object,
default: () => {
return {
id: undefined,
name: '',
childrenLen: 0
};
}
}
attributeType: {
type: Number,
default: 1
},
category: {
type: Object,
default: () => {
return {
id: undefined,
name: '',
childrenLen: 0
};
}
}
});
const attributeTypeName = computed(() =>
props.attributeType === 1 ? '规格' : '属性'
props.attributeType === 1 ? '规格' : '属性'
);
const attributeNameValidator = (rule: any, value: any, callback: any) => {
if (!value) {
return callback(new Error('请输入' + attributeTypeName.value + '名称'));
} else {
callback();
}
if (!value) {
return callback(new Error('请输入' + attributeTypeName.value + '名称'));
} else {
callback();
}
};
const state = reactive({
formData: {
categoryId: undefined,
type: 1,
attributes: [
{
id: undefined,
name: ''
}
]
},
rules: {
attribute: {
name: [
{ required: true, validator: attributeNameValidator, trigger: 'blur' }
]
}
}
formData: {
categoryId: undefined,
type: 1,
attributes: [
{
id: undefined,
name: ''
}
]
},
rules: {
attribute: {
name: [
{ required: true, validator: attributeNameValidator, trigger: 'blur' }
]
}
}
});
const { formData, rules } = toRefs(state);
watch(
() => props.category.id as any,
() => {
const categoryId = props.category.id;
if (categoryId) {
listAttributes({
categoryId: categoryId,
type: props.attributeType
}).then(response => {
const { data } = response;
if (data && data.length > 0) {
state.formData.attributes = response.data;
} else {
state.formData.attributes = [
{
id: undefined,
name: ''
}
];
}
});
} else {
state.formData.attributes = [
{
id: undefined,
name: ''
}
];
}
}
() => props.category.id as any,
() => {
const categoryId = props.category.id;
if (categoryId) {
listAttributes({
categoryId: categoryId,
type: props.attributeType
}).then(response => {
const { data } = response;
if (data && data.length > 0) {
state.formData.attributes = response.data;
} else {
state.formData.attributes = [
{
id: undefined,
name: ''
}
];
}
});
} else {
state.formData.attributes = [
{
id: undefined,
name: ''
}
];
}
}
);
function handleAdd() {
state.formData.attributes.push({
id: undefined,
name: ''
});
state.formData.attributes.push({
id: undefined,
name: ''
});
}
function handleDelete(index: number) {
if (state.formData.attributes.length == 1) {
state.formData.attributes = [
{
id: undefined,
name: ''
}
];
return;
}
state.formData.attributes.splice(index, 1);
if (state.formData.attributes.length == 1) {
state.formData.attributes = [
{
id: undefined,
name: ''
}
];
return;
}
state.formData.attributes.splice(index, 1);
}
function submitForm() {
state.formData.categoryId = props.category.id;
state.formData.type = props.attributeType;
saveAttributeBatch(state.formData).then(() => {
ElMessage.success('提交成功');
});
state.formData.categoryId = props.category.id;
state.formData.type = props.attributeType;
saveAttributeBatch(state.formData).then(() => {
ElMessage.success('提交成功');
});
}
</script>
<style scoped>
.component-container {
margin-bottom: 20px;
margin-bottom: 20px;
}
</style>

View File

@@ -1,117 +1,117 @@
<!-- 商品分类层级最多为三层level字段标识 -->
<template>
<div class="component-container">
<el-tree
v-loading="loading"
ref="categoryTreeRef"
:data="categoryOptions"
:props="{ label: 'name', children: 'children', disabled: '' }"
node-key="id"
:expand-on-click-node="false"
default-expand-all
:accordion="true"
@node-click="handleNodeClick"
>
<template #default="scope">
<div class="custom-tree-node">
<span>
<el-image
v-show="scope.data.level == 3"
:src="scope.data.iconUrl"
style="
width: 20px;
height: 20px;
vertical-align: middle;
margin-top: -5px;
"
>
<template #error>
<div class="image-slot">
<Picture style="width: 20px; height: 20px" />
</div>
</template>
</el-image>
{{ scope.data.name }}
</span>
<span>
<el-button
v-show="scope.data.level != 3"
type="success"
:icon="Plus"
circle
plain
@click.stop="handleAdd(scope.data)"
/>
<el-button
v-show="scope.data.id !== 0"
type="warning"
:icon="Edit"
circle
plain
@click.stop="handleUpdate(scope.data)"
/>
<el-button
v-show="
scope.data.id &&
(!scope.data.children || scope.data.children.length <= 0)
"
type="danger"
:icon="Delete"
circle
plain
@click.stop="handleDelete(scope.data)"
/>
</span>
</div>
</template>
</el-tree>
<div class="component-container">
<el-tree
v-loading="loading"
ref="categoryTreeRef"
:data="categoryOptions"
:props="{ label: 'name', children: 'children', disabled: '' }"
node-key="id"
:expand-on-click-node="false"
default-expand-all
:accordion="true"
@node-click="handleNodeClick"
>
<template #default="scope">
<div class="custom-tree-node">
<span>
<el-image
v-show="scope.data.level == 3"
:src="scope.data.iconUrl"
style="
width: 20px;
height: 20px;
vertical-align: middle;
margin-top: -5px;
"
>
<template #error>
<div class="image-slot">
<Picture style="width: 20px; height: 20px" />
</div>
</template>
</el-image>
{{ scope.data.name }}
</span>
<span>
<el-button
v-show="scope.data.level != 3"
type="success"
:icon="Plus"
circle
plain
@click.stop="handleAdd(scope.data)"
/>
<el-button
v-show="scope.data.id !== 0"
type="warning"
:icon="Edit"
circle
plain
@click.stop="handleUpdate(scope.data)"
/>
<el-button
v-show="
scope.data.id &&
(!scope.data.children || scope.data.children.length <= 0)
"
type="danger"
:icon="Delete"
circle
plain
@click.stop="handleDelete(scope.data)"
/>
</span>
</div>
</template>
</el-tree>
<el-dialog :title="dialog.title" v-model="dialog.visible" width="750px">
<el-form
ref="dataFormRef"
:model="formData"
:rules="rules"
label-width="100px"
>
<el-form-item label="上级分类" prop="parentId">
<el-input v-model="parent.name" readonly />
</el-form-item>
<el-dialog :title="dialog.title" v-model="dialog.visible" width="750px">
<el-form
ref="dataFormRef"
:model="formData"
:rules="rules"
label-width="100px"
>
<el-form-item label="上级分类" prop="parentId">
<el-input v-model="parent.name" readonly />
</el-form-item>
<el-form-item label="分类名称" prop="name">
<el-input v-model="formData.name" />
</el-form-item>
<el-form-item label="分类名称" prop="name">
<el-input v-model="formData.name" />
</el-form-item>
<el-form-item label="分类图标" prop="iconUrl">
<single-upload v-model="formData.iconUrl" />
</el-form-item>
<el-form-item label="分类图标" prop="iconUrl">
<single-upload v-model="formData.iconUrl" />
</el-form-item>
<el-form-item label="显示状态" prop="visible">
<el-radio-group v-model="formData.visible">
<el-radio :label="1">显示</el-radio>
<el-radio :label="0">隐藏</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="显示状态" prop="visible">
<el-radio-group v-model="formData.visible">
<el-radio :label="1">显示</el-radio>
<el-radio :label="0">隐藏</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="排序" prop="sort">
<el-input v-model="formData.sort"></el-input>
</el-form-item>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button type="primary" @click="submitForm">确 定</el-button>
<el-button @click="cancel">取 消</el-button>
</div>
</template>
</el-dialog>
</div>
<el-form-item label="排序" prop="sort">
<el-input v-model="formData.sort"></el-input>
</el-form-item>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button type="primary" @click="submitForm">确 定</el-button>
<el-button @click="cancel">取 消</el-button>
</div>
</template>
</el-dialog>
</div>
</template>
<script setup lang="ts">
import {
listCategories,
addCategory,
updateCategory,
deleteCategories
listCategories,
addCategory,
updateCategory,
deleteCategories
} from '@/api/pms/category';
import { Plus, Edit, Delete, Picture } from '@element-plus/icons-vue';
import SingleUpload from '@/components/Upload/SingleUpload.vue';
@@ -124,168 +124,168 @@ const categoryTreeRef = ref(ElTree);
const dataFormRef = ref(ElForm);
const state = reactive({
// 遮罩层
loading: true,
ids: [],
queryParam: {},
categoryOptions: [] as Array<any>,
formData: {
id: undefined,
name: undefined,
parentId: 0,
level: undefined,
iconUrl: undefined,
visible: 1,
sort: 100
},
rules: {
parentId: [
{
required: true,
message: '请选择上级分类',
trigger: 'blur'
}
],
name: [
{
required: true,
message: '请输入分类名称',
trigger: 'blur'
}
]
},
dialog: {
title: '',
visible: false
},
parent: {} as any,
current: {} as any
// 遮罩层
loading: true,
ids: [],
queryParam: {},
categoryOptions: [] as Array<any>,
formData: {
id: undefined,
name: undefined,
parentId: 0,
level: undefined,
iconUrl: undefined,
visible: 1,
sort: 100
},
rules: {
parentId: [
{
required: true,
message: '请选择上级分类',
trigger: 'blur'
}
],
name: [
{
required: true,
message: '请输入分类名称',
trigger: 'blur'
}
]
},
dialog: {
title: '',
visible: false
},
parent: {} as any,
current: {} as any
});
const { loading, categoryOptions, formData, rules, dialog, parent } =
toRefs(state);
toRefs(state);
function handleQuery() {
state.loading = true;
listCategories(state.queryParam).then(response => {
state.categoryOptions = [
{
id: 0,
name: '全部分类',
parentId: 0,
level: 0,
children: response.data
}
];
state.loading = false;
});
state.loading = true;
listCategories(state.queryParam).then(response => {
state.categoryOptions = [
{
id: 0,
name: '全部分类',
parentId: 0,
level: 0,
children: response.data
}
];
state.loading = false;
});
}
function handleNodeClick(row: any) {
const categoryTree = unref(categoryTreeRef);
const parentNode = categoryTree.getNode(row.parentId);
const categoryTree = unref(categoryTreeRef);
const parentNode = categoryTree.getNode(row.parentId);
state.parent = {
id: parentNode.key,
name: parentNode.label,
level: row.level
};
state.current = JSON.parse(JSON.stringify(row));
emit('categoryClick', row);
state.parent = {
id: parentNode.key,
name: parentNode.label,
level: row.level
};
state.current = JSON.parse(JSON.stringify(row));
emit('categoryClick', row);
}
function handleAdd(row: any) {
state.dialog = {
title: '新增商品分类',
visible: true
};
if (row.id != null) {
// 行点击新增
state.parent = {
id: row.id,
name: row.name,
level: row.level
};
}
state.dialog = {
title: '新增商品分类',
visible: true
};
if (row.id != null) {
// 行点击新增
state.parent = {
id: row.id,
name: row.name,
level: row.level
};
}
}
function handleUpdate(row: any) {
handleNodeClick(row);
state.dialog = {
title: '修改商品分类',
visible: true
};
Object.assign(state.formData, state.current);
handleNodeClick(row);
state.dialog = {
title: '修改商品分类',
visible: true
};
Object.assign(state.formData, state.current);
}
function submitForm() {
dataFormRef.value.validate((valid: any) => {
if (valid) {
if (state.formData.id) {
updateCategory(state.formData.id, state.formData).then(() => {
ElMessage.success('修改成功');
cancel();
handleQuery();
});
} else {
const parentCategory = state.parent as any;
state.formData.parentId = parentCategory.id;
state.formData.level = parentCategory.level + 1;
dataFormRef.value.validate((valid: any) => {
if (valid) {
if (state.formData.id) {
updateCategory(state.formData.id, state.formData).then(() => {
ElMessage.success('修改成功');
cancel();
handleQuery();
});
} else {
const parentCategory = state.parent as any;
state.formData.parentId = parentCategory.id;
state.formData.level = parentCategory.level + 1;
addCategory(state.formData).then(() => {
ElMessage.success('新增成功');
cancel();
handleQuery();
});
}
}
});
addCategory(state.formData).then(() => {
ElMessage.success('新增成功');
cancel();
handleQuery();
});
}
}
});
}
function handleDelete(row: any) {
const ids = [row.id || state.ids].join(',');
ElMessageBox.confirm('确认删除已选中的数据项?', '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
deleteCategories(ids).then(() => {
ElMessage.success('删除成功');
handleQuery();
});
});
const ids = [row.id || state.ids].join(',');
ElMessageBox.confirm('确认删除已选中的数据项?', '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
deleteCategories(ids).then(() => {
ElMessage.success('删除成功');
handleQuery();
});
});
}
function cancel() {
state.dialog.visible = false;
dataFormRef.value.resetFields();
state.dialog.visible = false;
state.dialog.visible = false;
dataFormRef.value.resetFields();
state.dialog.visible = false;
}
onMounted(() => {
handleQuery();
handleQuery();
});
</script>
<style>
.component-container {
height: 100%;
height: 100%;
}
.custom-tree-node {
flex: 1;
display: flex;
align-items: center;
justify-content: space-between;
font-size: 14px;
padding-right: 8px;
flex: 1;
display: flex;
align-items: center;
justify-content: space-between;
font-size: 14px;
padding-right: 8px;
}
.el-tree-node__content {
height: 40px;
height: 40px;
}
.el-divider--horizontal {
margin: 30px 0 15px;
margin: 30px 0 15px;
}
</style>

View File

@@ -1,7 +1,7 @@
<!-- setup 无法设置组件名称组件名称keepAlive必须 -->
<script lang="ts">
export default {
name: 'category'
name: 'category'
};
</script>
@@ -13,67 +13,67 @@ import SvgIcon from '@/components/SvgIcon/index.vue';
import { reactive, toRefs } from 'vue';
const state = reactive({
category: {
id: undefined,
name: '',
childrenLen: 0
}
category: {
id: undefined,
name: '',
childrenLen: 0
}
});
const { category } = toRefs(state);
function handleCategoryClick(categoryRow: any) {
if (categoryRow) {
state.category = {
id: categoryRow.id,
name: categoryRow.name,
childrenLen: categoryRow.children.length
};
} else {
state.category = {
id: undefined,
name: '',
childrenLen: 0
};
}
if (categoryRow) {
state.category = {
id: categoryRow.id,
name: categoryRow.name,
childrenLen: categoryRow.children.length
};
} else {
state.category = {
id: undefined,
name: '',
childrenLen: 0
};
}
}
</script>
<template>
<div class="app-container">
<el-row :gutter="10">
<el-col :span="14" :xs="24">
<el-card class="box-card" shadow="always">
<template #header>
<svg-icon icon-class="menu" />
商品分类
</template>
<Category ref="categoryRef" @categoryClick="handleCategoryClick" />
</el-card>
</el-col>
<div class="app-container">
<el-row :gutter="10">
<el-col :span="14" :xs="24">
<el-card class="box-card" shadow="always">
<template #header>
<svg-icon icon-class="menu" />
商品分类
</template>
<Category ref="categoryRef" @categoryClick="handleCategoryClick" />
</el-card>
</el-col>
<el-col :span="10" :xs="24">
<el-card class="box-card" shadow="always">
<template #header>
<svg-icon icon-class="menu" />
{{ category.name }} 规格属性
</template>
<!-- 商品规格 -->
<Attribute
ref="specificationRef"
:attributeType="1"
:category="category"
/>
<!-- 商品属性 -->
<Attribute
ref="attributeRef"
:attributeType="2"
:category="category"
/>
</el-card>
</el-col>
</el-row>
</div>
<el-col :span="10" :xs="24">
<el-card class="box-card" shadow="always">
<template #header>
<svg-icon icon-class="menu" />
{{ category.name }} 规格属性
</template>
<!-- 商品规格 -->
<Attribute
ref="specificationRef"
:attributeType="1"
:category="category"
/>
<!-- 商品属性 -->
<Attribute
ref="attributeRef"
:attributeType="2"
:category="category"
/>
</el-card>
</el-col>
</el-row>
</div>
</template>
<style scoped></style>

View File

@@ -1,80 +1,80 @@
<template>
<div class="component-container">
<div class="component-container__main">
<el-card class="box-card">
<template #header>
<span>商品属性</span>
<el-button
style="float: right"
type="success"
:icon="Plus"
size="small"
@click="handleAdd"
>
添加属性
</el-button>
</template>
<el-form
ref="dataFormRef"
:model="goodsInfo"
:rules="rules"
size="small"
:inline="true"
>
<el-table
:data="goodsInfo.attrList"
size="small"
highlight-current-row
border
>
<el-table-column property="name" label="属性名称">
<template #default="scope">
<el-form-item
:prop="'attrList[' + scope.$index + '].name'"
:rules="rules.name"
>
<el-input v-model="scope.row.name" />
</el-form-item>
</template>
</el-table-column>
<div class="component-container">
<div class="component-container__main">
<el-card class="box-card">
<template #header>
<span>商品属性</span>
<el-button
style="float: right"
type="success"
:icon="Plus"
size="small"
@click="handleAdd"
>
添加属性
</el-button>
</template>
<el-form
ref="dataFormRef"
:model="goodsInfo"
:rules="rules"
size="small"
:inline="true"
>
<el-table
:data="goodsInfo.attrList"
size="small"
highlight-current-row
border
>
<el-table-column property="name" label="属性名称">
<template #default="scope">
<el-form-item
:prop="'attrList[' + scope.$index + '].name'"
:rules="rules.name"
>
<el-input v-model="scope.row.name" />
</el-form-item>
</template>
</el-table-column>
<el-table-column property="value" label="属性值">
<template #default="scope">
<el-form-item
:prop="'attrList[' + scope.$index + '].value'"
:rules="rules.value"
>
<el-input v-model="scope.row.value" />
</el-form-item>
</template>
</el-table-column>
<el-table-column property="value" label="属性值">
<template #default="scope">
<el-form-item
:prop="'attrList[' + scope.$index + '].value'"
:rules="rules.value"
>
<el-input v-model="scope.row.value" />
</el-form-item>
</template>
</el-table-column>
<el-table-column label="操作" width="150">
<template #default="scope">
<el-form-item>
<el-button
v-if="scope.$index > 0"
type="danger"
:icon="Minus"
size="small"
circle
plain
@click.stop="handleRemove(scope.$index)"
/>
</el-form-item>
</template>
</el-table-column>
</el-table>
</el-form>
</el-card>
</div>
<div class="component-container__footer">
<el-button @click="handlePrev">上一步填写商品信息</el-button>
<el-button type="primary" @click="handleNext"
>下一步设置商品库存</el-button
>
</div>
</div>
<el-table-column label="操作" width="150">
<template #default="scope">
<el-form-item>
<el-button
v-if="scope.$index > 0"
type="danger"
:icon="Minus"
size="small"
circle
plain
@click.stop="handleRemove(scope.$index)"
/>
</el-form-item>
</template>
</el-table-column>
</el-table>
</el-form>
</el-card>
</div>
<div class="component-container__footer">
<el-button @click="handlePrev">上一步填写商品信息</el-button>
<el-button type="primary" @click="handleNext"
>下一步设置商品库存</el-button
>
</div>
</div>
</template>
<script setup lang="ts">
@@ -87,92 +87,92 @@ const emit = defineEmits(['prev', 'next', 'update:modelValue']);
const dataFormRef = ref(ElForm);
const props = defineProps({
modelValue: {
type: Object,
default: () => {}
}
modelValue: {
type: Object,
default: () => {}
}
});
const goodsInfo: any = computed({
get: () => props.modelValue,
set: value => {
emit('update:modelValue', value);
}
get: () => props.modelValue,
set: value => {
emit('update:modelValue', value);
}
});
watch(
() => goodsInfo.value.categoryId,
newVal => {
// 商品编辑不加载分类下的属性
const goodsId = goodsInfo.value.id;
if (goodsId) {
return false;
}
// 商品新增加载默认分类下的属性
if (newVal) {
// type=2 商品分类下的属性
listAttributes({ categoryId: newVal, type: 2 }).then(response => {
const attrList = response.data;
if (attrList && attrList.length > 0) {
goodsInfo.value.attrList = attrList;
} else {
goodsInfo.value.attrList = [{}];
}
});
} else {
goodsInfo.value.attrList = [{}];
}
},
{
immediate: true,
deep: true
}
() => goodsInfo.value.categoryId,
newVal => {
// 商品编辑不加载分类下的属性
const goodsId = goodsInfo.value.id;
if (goodsId) {
return false;
}
// 商品新增加载默认分类下的属性
if (newVal) {
// type=2 商品分类下的属性
listAttributes({ categoryId: newVal, type: 2 }).then(response => {
const attrList = response.data;
if (attrList && attrList.length > 0) {
goodsInfo.value.attrList = attrList;
} else {
goodsInfo.value.attrList = [{}];
}
});
} else {
goodsInfo.value.attrList = [{}];
}
},
{
immediate: true,
deep: true
}
);
const state = reactive({
rules: {
name: [{ required: true, message: '请填写属性名称', trigger: 'blur' }],
value: [{ required: true, message: '请填写属性值', trigger: 'blur' }]
}
rules: {
name: [{ required: true, message: '请填写属性名称', trigger: 'blur' }],
value: [{ required: true, message: '请填写属性值', trigger: 'blur' }]
}
});
const { rules } = toRefs(state);
function handleAdd() {
goodsInfo.value.attrList.push({});
goodsInfo.value.attrList.push({});
}
function handleRemove(index: number) {
goodsInfo.value.attrList.splice(index, 1);
goodsInfo.value.attrList.splice(index, 1);
}
function handlePrev() {
emit('prev');
emit('prev');
}
function handleNext() {
dataFormRef.value.validate((valid: any) => {
if (valid) {
emit('next');
}
});
dataFormRef.value.validate((valid: any) => {
if (valid) {
emit('next');
}
});
}
</script>
<style lang="scss" scoped>
.component-container {
&__main {
margin: 20px auto;
}
&__main {
margin: 20px auto;
}
&__footer {
position: fixed;
bottom: 20px;
right: 20px;
}
&__footer {
position: fixed;
bottom: 20px;
right: 20px;
}
}
.el-form-item--mini.el-form-item {
margin-top: 18px;
margin-top: 18px;
}
</style>

View File

@@ -1,38 +1,38 @@
<template>
<div class="component-container">
<div class="component-container__main">
<el-cascader-panel
ref="categoryRef"
:options="categoryOptions"
v-model="goodsInfo.categoryId"
:props="{ emitPath: false }"
@change="handleCategoryChange"
/>
<div style="margin-top: 20px">
<el-link type="info" :underline="false" v-show="pathLabels.length > 0"
>您选择的商品分类:</el-link
>
<el-link
type="danger"
:underline="false"
v-for="(item, index) in pathLabels"
:key="index"
style="margin-left: 5px"
>
{{ item }}
<CaretRight
v-show="index < pathLabels.length - 1"
style="width: 1em; height: 1em; margin-left: 5px"
/>
</el-link>
</div>
</div>
<div class="component-container__footer">
<el-button type="primary" @click="handleNext"
>下一步填写商品信息</el-button
>
</div>
</div>
<div class="component-container">
<div class="component-container__main">
<el-cascader-panel
ref="categoryRef"
:options="categoryOptions"
v-model="goodsInfo.categoryId"
:props="{ emitPath: false }"
@change="handleCategoryChange"
/>
<div style="margin-top: 20px">
<el-link type="info" :underline="false" v-show="pathLabels.length > 0"
>您选择的商品分类:</el-link
>
<el-link
type="danger"
:underline="false"
v-for="(item, index) in pathLabels"
:key="index"
style="margin-left: 5px"
>
{{ item }}
<CaretRight
v-show="index < pathLabels.length - 1"
style="width: 1em; height: 1em; margin-left: 5px"
/>
</el-link>
</div>
</div>
<div class="component-container__footer">
<el-button type="primary" @click="handleNext"
>下一步填写商品信息</el-button
>
</div>
</div>
</template>
<script setup lang="ts">
@@ -46,67 +46,67 @@ import { computed } from '@vue/reactivity';
const emit = defineEmits(['next', 'update:modelValue']);
const props = defineProps({
modelValue: {
type: Object,
default: () => {}
}
modelValue: {
type: Object,
default: () => {}
}
});
const goodsInfo: any = computed({
get: () => props.modelValue,
set: value => {
emit('update:modelValue', value);
}
get: () => props.modelValue,
set: value => {
emit('update:modelValue', value);
}
});
const state = reactive({
categoryOptions: [],
pathLabels: []
categoryOptions: [],
pathLabels: []
});
const { categoryOptions, pathLabels } = toRefs(state);
function loadData() {
listCascadeCategories().then(response => {
state.categoryOptions = response.data;
if (goodsInfo.value.id) {
nextTick(() => {
handleCategoryChange();
});
}
});
listCascadeCategories().then(response => {
state.categoryOptions = response.data;
if (goodsInfo.value.id) {
nextTick(() => {
handleCategoryChange();
});
}
});
}
const categoryRef = ref(ElCascaderPanel);
function handleCategoryChange() {
const checkNode = categoryRef.value.getCheckedNodes()[0];
state.pathLabels = checkNode.pathLabels; // 商品分类选择层级提示
goodsInfo.value.categoryId = checkNode.value;
const checkNode = categoryRef.value.getCheckedNodes()[0];
state.pathLabels = checkNode.pathLabels; // 商品分类选择层级提示
goodsInfo.value.categoryId = checkNode.value;
}
function handleNext() {
if (!goodsInfo.value.categoryId) {
ElMessage.warning('请选择商品分类');
return false;
}
emit('next');
if (!goodsInfo.value.categoryId) {
ElMessage.warning('请选择商品分类');
return false;
}
emit('next');
}
onMounted(() => {
loadData();
loadData();
});
</script>
<style lang="scss" scoped>
.component-container {
&__main {
margin: 20px auto;
}
&__main {
margin: 20px auto;
}
&__footer {
position: fixed;
bottom: 20px;
right: 20px;
}
&__footer {
position: fixed;
bottom: 20px;
right: 20px;
}
}
</style>

View File

@@ -1,93 +1,93 @@
<template>
<div class="component-container">
<div class="component-container__main">
<el-form
ref="dataFormRef"
:rules="rules"
:model="goodsInfo"
label-width="120px"
>
<el-form-item label="商品品牌" prop="brandId">
<el-select v-model="goodsInfo.brandId" style="width: 400px" clearable>
<el-option
v-for="item in brandOptions"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
<div class="component-container">
<div class="component-container__main">
<el-form
ref="dataFormRef"
:rules="rules"
:model="goodsInfo"
label-width="120px"
>
<el-form-item label="商品品牌" prop="brandId">
<el-select v-model="goodsInfo.brandId" style="width: 400px" clearable>
<el-option
v-for="item in brandOptions"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
<el-form-item label="商品名称" prop="name">
<el-input style="width: 400px" v-model="goodsInfo.name" />
</el-form-item>
<el-form-item label="商品名称" prop="name">
<el-input style="width: 400px" v-model="goodsInfo.name" />
</el-form-item>
<el-form-item label="原价" prop="originPrice">
<el-input style="width: 400px" v-model="goodsInfo.originPrice" />
</el-form-item>
<el-form-item label="原价" prop="originPrice">
<el-input style="width: 400px" v-model="goodsInfo.originPrice" />
</el-form-item>
<el-form-item label="现价" prop="price">
<el-input style="width: 400px" v-model="goodsInfo.price" />
</el-form-item>
<el-form-item label="现价" prop="price">
<el-input style="width: 400px" v-model="goodsInfo.price" />
</el-form-item>
<el-form-item label="商品简介">
<el-input
type="textarea"
:autosize="{ minRows: 3, maxRows: 6 }"
v-model="goodsInfo.description"
/>
</el-form-item>
<el-form-item label="商品简介">
<el-input
type="textarea"
:autosize="{ minRows: 3, maxRows: 6 }"
v-model="goodsInfo.description"
/>
</el-form-item>
<el-form-item label="商品相册">
<el-card
v-for="(item, index) in pictures"
:key="index"
style="
width: 170px;
display: inline-block;
margin-left: 10px;
text-align: center;
"
:body-style="{ padding: '10px' }"
>
<single-upload v-model="item.url" :show-close="true" />
<el-form-item label="商品相册">
<el-card
v-for="(item, index) in pictures"
:key="index"
style="
width: 170px;
display: inline-block;
margin-left: 10px;
text-align: center;
"
:body-style="{ padding: '10px' }"
>
<single-upload v-model="item.url" :show-close="true" />
<div v-if="item.url">
<el-button
type="text"
class="button"
v-if="item.main == true"
style="color: #ff4d51"
>商品主图</el-button
>
<el-button
type="text"
class="button"
v-else
@click="changeMainPicture(index)"
>设为主图</el-button
>
</div>
<div v-if="item.url">
<el-button
type="text"
class="button"
v-if="item.main == true"
style="color: #ff4d51"
>商品主图</el-button
>
<el-button
type="text"
class="button"
v-else
@click="changeMainPicture(index)"
>设为主图</el-button
>
</div>
<div v-else>
<!-- 占位 -->
<el-button type="text" />
</div>
</el-card>
</el-form-item>
<div v-else>
<!-- 占位 -->
<el-button type="text" />
</div>
</el-card>
</el-form-item>
<el-form-item label="商品详情" prop="detail">
<editor v-model="goodsInfo.detail" style="height: 600px" />
</el-form-item>
</el-form>
</div>
<div class="component-container__footer">
<el-button @click="handlePrev">上一步选择商品分类</el-button>
<el-button type="primary" @click="handleNext"
>下一步设置商品属性</el-button
>
</div>
</div>
<el-form-item label="商品详情" prop="detail">
<editor v-model="goodsInfo.detail" style="height: 600px" />
</el-form-item>
</el-form>
</div>
<div class="component-container__footer">
<el-button @click="handlePrev">上一步选择商品分类</el-button>
<el-button type="primary" @click="handleNext"
>下一步设置商品属性</el-button
>
</div>
</div>
</template>
<script setup lang="ts">
@@ -105,115 +105,115 @@ const emit = defineEmits(['prev', 'next', 'update:modelValue']);
const dataFormRef = ref(ElForm);
const props = defineProps({
modelValue: {
type: Object,
default: () => {}
}
modelValue: {
type: Object,
default: () => {}
}
});
const goodsInfo: any = computed({
get: () => props.modelValue,
set: value => {
emit('update:modelValue', value);
}
get: () => props.modelValue,
set: value => {
emit('update:modelValue', value);
}
});
const state = reactive({
brandOptions: [] as Array<any>,
// 商品图册
pictures: [
{ url: undefined, main: true }, // main = true 代表主图,可切换
{ url: undefined, main: false },
{ url: undefined, main: false },
{ url: undefined, main: false },
{ url: undefined, main: false }
] as Array<any>,
rules: {
name: [{ required: true, message: '请填写商品名称', trigger: 'blur' }],
originPrice: [{ required: true, message: '请填写原价', trigger: 'blur' }],
price: [{ required: true, message: '请填写现价', trigger: 'blur' }],
brandId: [{ required: true, message: '请选择商品品牌', trigger: 'blur' }]
}
brandOptions: [] as Array<any>,
// 商品图册
pictures: [
{ url: undefined, main: true }, // main = true 代表主图,可切换
{ url: undefined, main: false },
{ url: undefined, main: false },
{ url: undefined, main: false },
{ url: undefined, main: false }
] as Array<any>,
rules: {
name: [{ required: true, message: '请填写商品名称', trigger: 'blur' }],
originPrice: [{ required: true, message: '请填写原价', trigger: 'blur' }],
price: [{ required: true, message: '请填写现价', trigger: 'blur' }],
brandId: [{ required: true, message: '请选择商品品牌', trigger: 'blur' }]
}
});
const { brandOptions, pictures, rules } = toRefs(state);
function loadData() {
listBrands().then(({ data }) => {
state.brandOptions = data;
});
const goodsId = goodsInfo.value.id;
if (goodsId) {
const mainPicUrl = goodsInfo.value.picUrl;
if (mainPicUrl) {
state.pictures.filter(item => item.main)[0].url = mainPicUrl;
}
const subPicUrls = goodsInfo.value.subPicUrls;
if (subPicUrls && subPicUrls.length > 0) {
for (let i = 1; i <= subPicUrls.length; i++) {
state.pictures[i].url = subPicUrls[i - 1];
}
}
}
listBrands().then(({ data }) => {
state.brandOptions = data;
});
const goodsId = goodsInfo.value.id;
if (goodsId) {
const mainPicUrl = goodsInfo.value.picUrl;
if (mainPicUrl) {
state.pictures.filter(item => item.main)[0].url = mainPicUrl;
}
const subPicUrls = goodsInfo.value.subPicUrls;
if (subPicUrls && subPicUrls.length > 0) {
for (let i = 1; i <= subPicUrls.length; i++) {
state.pictures[i].url = subPicUrls[i - 1];
}
}
}
}
/**
* 切换主图
*/
function changeMainPicture(changeIndex: number) {
const currMainPicture = JSON.parse(JSON.stringify(state.pictures[0]));
const nextMainPicture = JSON.parse(
JSON.stringify(state.pictures[changeIndex])
);
const currMainPicture = JSON.parse(JSON.stringify(state.pictures[0]));
const nextMainPicture = JSON.parse(
JSON.stringify(state.pictures[changeIndex])
);
state.pictures[0].url = nextMainPicture.url;
state.pictures[changeIndex].url = currMainPicture.url;
state.pictures[0].url = nextMainPicture.url;
state.pictures[changeIndex].url = currMainPicture.url;
}
function handlePrev() {
emit('prev');
emit('prev');
}
function handleNext() {
dataFormRef.value.validate((valid: any) => {
if (valid) {
// 商品图片
const mainPicUrl = state.pictures
.filter(item => item.main == true && item.url)
.map(item => item.url);
if (mainPicUrl && mainPicUrl.length > 0) {
goodsInfo.value.picUrl = mainPicUrl[0];
}
const subPicUrl = state.pictures
.filter(item => item.main == false && item.url)
.map(item => item.url);
if (subPicUrl && subPicUrl.length > 0) {
goodsInfo.value.subPicUrls = subPicUrl;
}
emit('next');
}
});
dataFormRef.value.validate((valid: any) => {
if (valid) {
// 商品图片
const mainPicUrl = state.pictures
.filter(item => item.main == true && item.url)
.map(item => item.url);
if (mainPicUrl && mainPicUrl.length > 0) {
goodsInfo.value.picUrl = mainPicUrl[0];
}
const subPicUrl = state.pictures
.filter(item => item.main == false && item.url)
.map(item => item.url);
if (subPicUrl && subPicUrl.length > 0) {
goodsInfo.value.subPicUrls = subPicUrl;
}
emit('next');
}
});
}
onMounted(() => {
loadData();
loadData();
});
</script>
<style lang="scss" scoped>
.component-container {
&__main {
margin: 20px auto;
&__main {
margin: 20px auto;
.button {
margin-left: 10px;
}
}
.button {
margin-left: 10px;
}
}
&__footer {
position: fixed;
bottom: 20px;
right: 20px;
}
&__footer {
position: fixed;
bottom: 20px;
right: 20px;
}
}
</style>

File diff suppressed because it is too large Load Diff

View File

@@ -1,46 +1,46 @@
<template>
<div class="app-container">
<el-steps
:active="active"
process-status="finish"
finish-status="success"
simple
>
<el-step title="选择商品分类" />
<el-step title="填写商品信息" />
<el-step title="设置商品属性" />
<el-step title="设置商品库存" />
</el-steps>
<div class="app-container">
<el-steps
:active="active"
process-status="finish"
finish-status="success"
simple
>
<el-step title="选择商品分类" />
<el-step title="填写商品信息" />
<el-step title="设置商品属性" />
<el-step title="设置商品库存" />
</el-steps>
<GoodsCategory
v-show="active == 0"
v-model="goodsInfo"
v-if="loaded == true"
@prev="prev"
@next="next"
/>
<GoodsInfo
v-show="active == 1"
v-model="goodsInfo"
v-if="loaded == true"
@prev="prev"
@next="next"
/>
<GoodsAttribute
v-show="active == 2"
v-model="goodsInfo"
v-if="loaded == true"
@prev="prev"
@next="next"
/>
<GoodsStock
v-show="active == 3"
v-model="goodsInfo"
v-if="loaded == true"
@prev="prev"
@next="next"
/>
</div>
<GoodsCategory
v-show="active == 0"
v-model="goodsInfo"
v-if="loaded == true"
@prev="prev"
@next="next"
/>
<GoodsInfo
v-show="active == 1"
v-model="goodsInfo"
v-if="loaded == true"
@prev="prev"
@next="next"
/>
<GoodsAttribute
v-show="active == 2"
v-model="goodsInfo"
v-if="loaded == true"
@prev="prev"
@next="next"
/>
<GoodsStock
v-show="active == 3"
v-model="goodsInfo"
v-if="loaded == true"
@prev="prev"
@next="next"
/>
</div>
</template>
<script setup lang="ts">
@@ -58,53 +58,53 @@ import { GoodsDetail } from '@/types';
const route = useRoute();
const state = reactive({
loaded: false,
active: 0,
goodsInfo: {
album: [],
attrList: [],
specList: [],
skuList: []
} as GoodsDetail
loaded: false,
active: 0,
goodsInfo: {
album: [],
attrList: [],
specList: [],
skuList: []
} as GoodsDetail
});
const { loaded, active, goodsInfo } = toRefs(state);
function loadData() {
const goodsId = route.query.goodsId as string;
const goodsId = route.query.goodsId as string;
if (goodsId) {
getGoodsDetail(goodsId).then(response => {
state.goodsInfo = response.data;
state.goodsInfo.originPrice = (state.goodsInfo.originPrice as any) / 100;
state.goodsInfo.price = (state.goodsInfo.price as any) / 100;
state.loaded = true;
});
} else {
state.loaded = true;
}
if (goodsId) {
getGoodsDetail(goodsId).then(response => {
state.goodsInfo = response.data;
state.goodsInfo.originPrice = (state.goodsInfo.originPrice as any) / 100;
state.goodsInfo.price = (state.goodsInfo.price as any) / 100;
state.loaded = true;
});
} else {
state.loaded = true;
}
}
function prev() {
if (state.active-- <= 0) {
state.active = 0;
}
if (state.active-- <= 0) {
state.active = 0;
}
}
function next() {
if (state.active++ >= 3) {
state.active = 0;
}
if (state.active++ >= 3) {
state.active = 0;
}
}
onMounted(() => {
loadData();
loadData();
});
</script>
<style lang="scss" scoped>
.app-container {
width: 1200px;
margin: 50px auto;
border: 1px solid #eee;
width: 1200px;
margin: 50px auto;
border: 1px solid #eee;
}
</style>

View File

@@ -1,7 +1,7 @@
<!-- setup 无法设置组件名称组件名称keepAlive必须 -->
<script lang="ts">
export default {
name: 'goods'
name: 'goods'
};
</script>
@@ -11,12 +11,12 @@ import { ElTable, ElMessage, ElMessageBox } from 'element-plus';
import { useRouter } from 'vue-router';
import {
Search,
Position,
Edit,
Refresh,
Delete,
View
Search,
Position,
Edit,
Refresh,
Delete,
View
} from '@element-plus/icons-vue';
import { listGoodsPages, deleteGoods } from '@/api/pms/goods';
import { listCascadeCategories } from '@/api/pms/category';
@@ -27,250 +27,250 @@ const dataTableRef = ref(ElTable);
const router = useRouter();
const state = reactive({
// 遮罩层
loading: true,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
total: 0,
queryParams: {
pageNum: 1,
pageSize: 10
} as GoodsQueryParam,
goodsList: [] as GoodsItem[],
categoryOptions: [],
goodDetail: undefined,
dialogVisible: false
// 遮罩层
loading: true,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
total: 0,
queryParams: {
pageNum: 1,
pageSize: 10
} as GoodsQueryParam,
goodsList: [] as GoodsItem[],
categoryOptions: [],
goodDetail: undefined,
dialogVisible: false
});
const {
loading,
multiple,
queryParams,
goodsList,
categoryOptions,
goodDetail,
total,
dialogVisible
loading,
multiple,
queryParams,
goodsList,
categoryOptions,
goodDetail,
total,
dialogVisible
} = toRefs(state);
function handleQuery() {
state.loading = true;
listGoodsPages(state.queryParams).then(({ data }) => {
state.goodsList = data.list;
state.total = data.total;
state.loading = false;
});
state.loading = true;
listGoodsPages(state.queryParams).then(({ data }) => {
state.goodsList = data.list;
state.total = data.total;
state.loading = false;
});
}
function resetQuery() {
state.queryParams = {
pageNum: 1,
pageSize: 10,
name: undefined,
categoryId: undefined
};
handleQuery();
state.queryParams = {
pageNum: 1,
pageSize: 10,
name: undefined,
categoryId: undefined
};
handleQuery();
}
function handleGoodsView(detail: any) {
state.goodDetail = detail;
state.dialogVisible = true;
state.goodDetail = detail;
state.dialogVisible = true;
}
function handleAdd() {
router.push({ path: 'goods-detail' });
router.push({ path: 'goods-detail' });
}
function handleUpdate(row: any) {
router.push({
path: 'goods-detail',
query: { goodsId: row.id, categoryId: row.categoryId }
});
router.push({
path: 'goods-detail',
query: { goodsId: row.id, categoryId: row.categoryId }
});
}
function handleDelete(row: any) {
const ids = row.id || state.ids.join(',');
ElMessageBox.confirm('是否确认删除选中的数据项?', '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
})
.then(function () {
return deleteGoods(ids);
})
.then(() => {
ElMessage.success('删除成功');
handleQuery();
});
const ids = row.id || state.ids.join(',');
ElMessageBox.confirm('是否确认删除选中的数据项?', '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
})
.then(function () {
return deleteGoods(ids);
})
.then(() => {
ElMessage.success('删除成功');
handleQuery();
});
}
function handleRowClick(row: any) {
dataTableRef.value.toggleRowSelection(row);
dataTableRef.value.toggleRowSelection(row);
}
function handleSelectionChange(selection: any) {
state.ids = selection.map((item: { id: any }) => item.id);
state.single = selection.length != 1;
state.multiple = !selection.length;
state.ids = selection.map((item: { id: any }) => item.id);
state.single = selection.length != 1;
state.multiple = !selection.length;
}
onMounted(() => {
listCascadeCategories({}).then(response => {
state.categoryOptions = ref(response.data);
});
handleQuery();
listCascadeCategories({}).then(response => {
state.categoryOptions = ref(response.data);
});
handleQuery();
});
</script>
<template>
<div class="app-container">
<el-form ref="queryForm" :inline="true">
<el-form-item>
<el-button type="success" :icon="Position" @click="handleAdd"
>发布商品</el-button
>
<el-button
type="danger"
:icon="Delete"
@click="handleDelete"
:disabled="multiple"
>删除</el-button
>
</el-form-item>
<el-form-item>
<el-input
v-model="queryParams.name"
placeholder="商品名称"
clearable
></el-input>
</el-form-item>
<el-form-item>
<el-cascader
v-model="queryParams.categoryId"
placeholder="商品分类"
:props="{ emitPath: false }"
:options="categoryOptions"
clearable
style="width: 300px"
/>
</el-form-item>
<el-form-item>
<el-button type="primary" :icon="Search" @click="handleQuery"
>查询</el-button
>
<el-button :icon="Refresh" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<div class="app-container">
<el-form ref="queryForm" :inline="true">
<el-form-item>
<el-button type="success" :icon="Position" @click="handleAdd"
>发布商品</el-button
>
<el-button
type="danger"
:icon="Delete"
@click="handleDelete"
:disabled="multiple"
>删除</el-button
>
</el-form-item>
<el-form-item>
<el-input
v-model="queryParams.name"
placeholder="商品名称"
clearable
></el-input>
</el-form-item>
<el-form-item>
<el-cascader
v-model="queryParams.categoryId"
placeholder="商品分类"
:props="{ emitPath: false }"
:options="categoryOptions"
clearable
style="width: 300px"
/>
</el-form-item>
<el-form-item>
<el-button type="primary" :icon="Search" @click="handleQuery"
>查询</el-button
>
<el-button :icon="Refresh" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-table
ref="dataTableRef"
v-loading="loading"
:data="goodsList"
@selection-change="handleSelectionChange"
@row-click="handleRowClick"
border
>
<el-table-column type="selection" min-width="5%" center />
<el-table-column type="expand" width="120" label="库存信息">
<template #default="props">
<el-table :data="props.row.skuList" border>
<el-table-column align="center" label="商品编码" prop="skuSn" />
<el-table-column align="center" label="商品规格" prop="name" />
<el-table-column label="图片" prop="picUrl">
<template #default="scope">
<img :src="scope.row.picUrl" width="40" />
</template>
</el-table-column>
<el-table-column align="center" label="现价" prop="price">
<template #default="scope">{{
moneyFormatter(scope.row.price)
}}</template>
</el-table-column>
<el-table-column align="center" label="库存" prop="stockNum" />
</el-table>
</template>
</el-table-column>
<el-table-column label="商品名称" prop="name" min-width="140" />
<el-table-column label="商品图片">
<template #default="scope">
<el-popover placement="right" :width="400" trigger="hover">
<img :src="scope.row.picUrl" width="400" height="400" />
<template #reference>
<img
:src="scope.row.picUrl"
style="max-height: 60px; max-width: 60px"
/>
</template>
</el-popover>
</template>
</el-table-column>
<el-table-column label="商品类目" prop="categoryName" min-width="100" />
<el-table-column label="商品品牌" prop="brandName" min-width="100" />
<el-table-column align="center" label="零售价" prop="originalPrice">
<template #default="scope">{{
moneyFormatter(scope.row.originPrice)
}}</template>
</el-table-column>
<el-table-column align="center" label="促销价" prop="price">
<template #default="scope">{{
moneyFormatter(scope.row.price)
}}</template>
</el-table-column>
<el-table-column label="销量" prop="sales" min-width="100" />
<el-table-column label="单位" prop="unit" min-width="100" />
<el-table-column
label="描述"
prop="description"
width="300"
:show-overflow-tooltip="true"
/>
<el-table-column label="详情" prop="detail">
<template #default="scope">
<el-button
type="primary"
:icon="View"
circle
plain
@click.stop="handleGoodsView(scope.row.detail)"
/>
</template>
</el-table-column>
<el-table-column label="操作" width="120">
<template #default="scope">
<el-button
type="primary"
:icon="Edit"
circle
plain
@click.stop="handleUpdate(scope.row)"
/>
<el-button
type="danger"
:icon="Delete"
circle
plain
@click.stop="handleDelete(scope.row)"
/>
</template>
</el-table-column>
</el-table>
<el-table
ref="dataTableRef"
v-loading="loading"
:data="goodsList"
@selection-change="handleSelectionChange"
@row-click="handleRowClick"
border
>
<el-table-column type="selection" min-width="5%" center />
<el-table-column type="expand" width="120" label="库存信息">
<template #default="props">
<el-table :data="props.row.skuList" border>
<el-table-column align="center" label="商品编码" prop="skuSn" />
<el-table-column align="center" label="商品规格" prop="name" />
<el-table-column label="图片" prop="picUrl">
<template #default="scope">
<img :src="scope.row.picUrl" width="40" />
</template>
</el-table-column>
<el-table-column align="center" label="现价" prop="price">
<template #default="scope">{{
moneyFormatter(scope.row.price)
}}</template>
</el-table-column>
<el-table-column align="center" label="库存" prop="stockNum" />
</el-table>
</template>
</el-table-column>
<el-table-column label="商品名称" prop="name" min-width="140" />
<el-table-column label="商品图片">
<template #default="scope">
<el-popover placement="right" :width="400" trigger="hover">
<img :src="scope.row.picUrl" width="400" height="400" />
<template #reference>
<img
:src="scope.row.picUrl"
style="max-height: 60px; max-width: 60px"
/>
</template>
</el-popover>
</template>
</el-table-column>
<el-table-column label="商品类目" prop="categoryName" min-width="100" />
<el-table-column label="商品品牌" prop="brandName" min-width="100" />
<el-table-column align="center" label="零售价" prop="originalPrice">
<template #default="scope">{{
moneyFormatter(scope.row.originPrice)
}}</template>
</el-table-column>
<el-table-column align="center" label="促销价" prop="price">
<template #default="scope">{{
moneyFormatter(scope.row.price)
}}</template>
</el-table-column>
<el-table-column label="销量" prop="sales" min-width="100" />
<el-table-column label="单位" prop="unit" min-width="100" />
<el-table-column
label="描述"
prop="description"
width="300"
:show-overflow-tooltip="true"
/>
<el-table-column label="详情" prop="detail">
<template #default="scope">
<el-button
type="primary"
:icon="View"
circle
plain
@click.stop="handleGoodsView(scope.row.detail)"
/>
</template>
</el-table-column>
<el-table-column label="操作" width="120">
<template #default="scope">
<el-button
type="primary"
:icon="Edit"
circle
plain
@click.stop="handleUpdate(scope.row)"
/>
<el-button
type="danger"
:icon="Delete"
circle
plain
@click.stop="handleDelete(scope.row)"
/>
</template>
</el-table-column>
</el-table>
<!-- 分页工具条 -->
<pagination
v-if="total > 0"
:total="total"
v-model:page="queryParams.pageNum"
v-model:limit="queryParams.pageSize"
@pagination="handleQuery"
/>
<el-dialog v-model="dialogVisible" title="商品详情">
<div class="goods-detail-box" v-html="goodDetail" />
</el-dialog>
</div>
<!-- 分页工具条 -->
<pagination
v-if="total > 0"
:total="total"
v-model:page="queryParams.pageNum"
v-model:limit="queryParams.pageSize"
@pagination="handleQuery"
/>
<el-dialog v-model="dialogVisible" title="商品详情">
<div class="goods-detail-box" v-html="goodDetail" />
</el-dialog>
</div>
</template>
<style scoped></style>