|
|
@ -1,15 +1,19 @@
|
|
|
|
<template>
|
|
|
|
<template>
|
|
|
|
|
|
|
|
<!-- 分类详情表单,使用 Element UI -->
|
|
|
|
<el-card class="form-container" shadow="never">
|
|
|
|
<el-card class="form-container" shadow="never">
|
|
|
|
<el-form :model="productCate"
|
|
|
|
<el-form :model="productCate"
|
|
|
|
:rules="rules"
|
|
|
|
:rules="rules"
|
|
|
|
ref="productCateFrom"
|
|
|
|
ref="productCateFrom"
|
|
|
|
label-width="150px">
|
|
|
|
label-width="150px">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 分类名称输入框 -->
|
|
|
|
<el-form-item label="分类名称:" prop="name">
|
|
|
|
<el-form-item label="分类名称:" prop="name">
|
|
|
|
<el-input v-model="productCate.name"></el-input>
|
|
|
|
<el-input v-model="productCate.name"></el-input>
|
|
|
|
</el-form-item>
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 上级分类选择框 -->
|
|
|
|
<el-form-item label="上级分类:">
|
|
|
|
<el-form-item label="上级分类:">
|
|
|
|
<el-select v-model="productCate.parentId"
|
|
|
|
<el-select v-model="productCate.parentId" placeholder="请选择分类">
|
|
|
|
placeholder="请选择分类">
|
|
|
|
|
|
|
|
<el-option
|
|
|
|
<el-option
|
|
|
|
v-for="item in selectProductCateList"
|
|
|
|
v-for="item in selectProductCateList"
|
|
|
|
:key="item.id"
|
|
|
|
:key="item.id"
|
|
|
@ -18,47 +22,67 @@
|
|
|
|
</el-option>
|
|
|
|
</el-option>
|
|
|
|
</el-select>
|
|
|
|
</el-select>
|
|
|
|
</el-form-item>
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 数量单位输入框 -->
|
|
|
|
<el-form-item label="数量单位:">
|
|
|
|
<el-form-item label="数量单位:">
|
|
|
|
<el-input v-model="productCate.productUnit"></el-input>
|
|
|
|
<el-input v-model="productCate.productUnit"></el-input>
|
|
|
|
</el-form-item>
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 排序输入框 -->
|
|
|
|
<el-form-item label="排序:">
|
|
|
|
<el-form-item label="排序:">
|
|
|
|
<el-input v-model="productCate.sort"></el-input>
|
|
|
|
<el-input v-model="productCate.sort"></el-input>
|
|
|
|
</el-form-item>
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 是否显示单选按钮 -->
|
|
|
|
<el-form-item label="是否显示:">
|
|
|
|
<el-form-item label="是否显示:">
|
|
|
|
<el-radio-group v-model="productCate.showStatus">
|
|
|
|
<el-radio-group v-model="productCate.showStatus">
|
|
|
|
<el-radio :label="1">是</el-radio>
|
|
|
|
<el-radio :label="1">是</el-radio>
|
|
|
|
<el-radio :label="0">否</el-radio>
|
|
|
|
<el-radio :label="0">否</el-radio>
|
|
|
|
</el-radio-group>
|
|
|
|
</el-radio-group>
|
|
|
|
</el-form-item>
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 是否显示在导航栏 -->
|
|
|
|
<el-form-item label="是否显示在导航栏:">
|
|
|
|
<el-form-item label="是否显示在导航栏:">
|
|
|
|
<el-radio-group v-model="productCate.navStatus">
|
|
|
|
<el-radio-group v-model="productCate.navStatus">
|
|
|
|
<el-radio :label="1">是</el-radio>
|
|
|
|
<el-radio :label="1">是</el-radio>
|
|
|
|
<el-radio :label="0">否</el-radio>
|
|
|
|
<el-radio :label="0">否</el-radio>
|
|
|
|
</el-radio-group>
|
|
|
|
</el-radio-group>
|
|
|
|
</el-form-item>
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 分类图标上传组件 -->
|
|
|
|
<el-form-item label="分类图标:">
|
|
|
|
<el-form-item label="分类图标:">
|
|
|
|
<single-upload v-model="productCate.icon"></single-upload>
|
|
|
|
<single-upload v-model="productCate.icon"></single-upload>
|
|
|
|
</el-form-item>
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 筛选属性列表 -->
|
|
|
|
<el-form-item v-for="(filterProductAttr, index) in filterProductAttrList"
|
|
|
|
<el-form-item v-for="(filterProductAttr, index) in filterProductAttrList"
|
|
|
|
:label="index | filterLabelFilter"
|
|
|
|
:label="index | filterLabelFilter"
|
|
|
|
:key="filterProductAttr.key"
|
|
|
|
:key="filterProductAttr.key">
|
|
|
|
>
|
|
|
|
|
|
|
|
<el-cascader
|
|
|
|
<el-cascader
|
|
|
|
clearable
|
|
|
|
clearable
|
|
|
|
v-model="filterProductAttr.value"
|
|
|
|
v-model="filterProductAttr.value"
|
|
|
|
:options="filterAttrs">
|
|
|
|
:options="filterAttrs">
|
|
|
|
</el-cascader>
|
|
|
|
</el-cascader>
|
|
|
|
|
|
|
|
<!-- 删除按钮 -->
|
|
|
|
<el-button style="margin-left: 20px" @click.prevent="removeFilterAttr(filterProductAttr)">删除</el-button>
|
|
|
|
<el-button style="margin-left: 20px" @click.prevent="removeFilterAttr(filterProductAttr)">删除</el-button>
|
|
|
|
</el-form-item>
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 新增筛选属性按钮 -->
|
|
|
|
<el-form-item>
|
|
|
|
<el-form-item>
|
|
|
|
<el-button size="small" type="primary" @click="handleAddFilterAttr()">新增</el-button>
|
|
|
|
<el-button size="small" type="primary" @click="handleAddFilterAttr()">新增</el-button>
|
|
|
|
</el-form-item>
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 关键词输入框 -->
|
|
|
|
<el-form-item label="关键词:">
|
|
|
|
<el-form-item label="关键词:">
|
|
|
|
<el-input v-model="productCate.keywords"></el-input>
|
|
|
|
<el-input v-model="productCate.keywords"></el-input>
|
|
|
|
</el-form-item>
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 分类描述输入框 -->
|
|
|
|
<el-form-item label="分类描述:">
|
|
|
|
<el-form-item label="分类描述:">
|
|
|
|
<el-input type="textarea" :autosize="true" v-model="productCate.description"></el-input>
|
|
|
|
<el-input type="textarea" :autosize="true" v-model="productCate.description"></el-input>
|
|
|
|
</el-form-item>
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 提交和重置按钮 -->
|
|
|
|
<el-form-item>
|
|
|
|
<el-form-item>
|
|
|
|
<el-button type="primary" @click="onSubmit('productCateFrom')">提交</el-button>
|
|
|
|
<el-button type="primary" @click="onSubmit('productCateFrom')">提交</el-button>
|
|
|
|
<el-button v-if="!isEdit" @click="resetForm('productCateFrom')">重置</el-button>
|
|
|
|
<el-button v-if="!isEdit" @click="resetForm('productCateFrom')">重置</el-button>
|
|
|
@ -68,6 +92,7 @@
|
|
|
|
</template>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
<script>
|
|
|
|
|
|
|
|
// API 引入
|
|
|
|
import {fetchList, createProductCate, updateProductCate, getProductCate} from '@/api/productCate';
|
|
|
|
import {fetchList, createProductCate, updateProductCate, getProductCate} from '@/api/productCate';
|
|
|
|
import {fetchListWithAttr} from '@/api/productAttrCate';
|
|
|
|
import {fetchListWithAttr} from '@/api/productAttrCate';
|
|
|
|
import {getProductAttrInfo} from '@/api/productAttr';
|
|
|
|
import {getProductAttrInfo} from '@/api/productAttr';
|
|
|
@ -85,9 +110,10 @@
|
|
|
|
sort: 0,
|
|
|
|
sort: 0,
|
|
|
|
productAttributeIdList: []
|
|
|
|
productAttributeIdList: []
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
export default {
|
|
|
|
name: "ProductCateDetail",
|
|
|
|
name: "ProductCateDetail",
|
|
|
|
components: {SingleUpload},
|
|
|
|
components: { SingleUpload },
|
|
|
|
props: {
|
|
|
|
props: {
|
|
|
|
isEdit: {
|
|
|
|
isEdit: {
|
|
|
|
type: Boolean,
|
|
|
|
type: Boolean,
|
|
|
@ -97,168 +123,114 @@
|
|
|
|
data() {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
productCate: Object.assign({}, defaultProductCate),
|
|
|
|
productCate: Object.assign({}, defaultProductCate),
|
|
|
|
selectProductCateList: [],
|
|
|
|
selectProductCateList: [], // 上级分类列表
|
|
|
|
rules: {
|
|
|
|
rules: {
|
|
|
|
name: [
|
|
|
|
name: [
|
|
|
|
{required: true, message: '请输入品牌名称', trigger: 'blur'},
|
|
|
|
{ required: true, message: '请输入品牌名称', trigger: 'blur' },
|
|
|
|
{min: 2, max: 140, message: '长度在 2 到 140 个字符', trigger: 'blur'}
|
|
|
|
{ min: 2, max: 140, message: '长度在 2 到 140 个字符', trigger: 'blur' }
|
|
|
|
]
|
|
|
|
]
|
|
|
|
},
|
|
|
|
},
|
|
|
|
filterAttrs: [],
|
|
|
|
filterAttrs: [], // 筛选属性列表
|
|
|
|
filterProductAttrList: [{
|
|
|
|
filterProductAttrList: [{ value: [] }] // 已选筛选属性
|
|
|
|
value: []
|
|
|
|
};
|
|
|
|
}]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
created() {
|
|
|
|
if (this.isEdit) {
|
|
|
|
if (this.isEdit) {
|
|
|
|
|
|
|
|
// 编辑模式下,获取分类详情数据
|
|
|
|
getProductCate(this.$route.query.id).then(response => {
|
|
|
|
getProductCate(this.$route.query.id).then(response => {
|
|
|
|
this.productCate = response.data;
|
|
|
|
this.productCate = response.data;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// 获取筛选属性数据
|
|
|
|
getProductAttrInfo(this.$route.query.id).then(response => {
|
|
|
|
getProductAttrInfo(this.$route.query.id).then(response => {
|
|
|
|
if (response.data != null && response.data.length > 0) {
|
|
|
|
if (response.data != null && response.data.length > 0) {
|
|
|
|
this.filterProductAttrList = [];
|
|
|
|
this.filterProductAttrList = response.data.map((item, index) => ({
|
|
|
|
for (let i = 0; i < response.data.length; i++) {
|
|
|
|
key: Date.now() + index,
|
|
|
|
this.filterProductAttrList.push({
|
|
|
|
value: [item.attributeCategoryId, item.attributeId]
|
|
|
|
key: Date.now() + i,
|
|
|
|
}));
|
|
|
|
value: [response.data[i].attributeCategoryId, response.data[i].attributeId]
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
|
|
|
|
this.productCate = Object.assign({}, defaultProductCate);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.getSelectProductCateList();
|
|
|
|
this.getSelectProductCateList();
|
|
|
|
this.getProductAttrCateList();
|
|
|
|
this.getProductAttrCateList();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
methods: {
|
|
|
|
|
|
|
|
// 获取上级分类列表
|
|
|
|
getSelectProductCateList() {
|
|
|
|
getSelectProductCateList() {
|
|
|
|
fetchList(0, {pageSize: 100, pageNum: 1}).then(response => {
|
|
|
|
fetchList(0, { pageSize: 100, pageNum: 1 }).then(response => {
|
|
|
|
this.selectProductCateList = response.data.list;
|
|
|
|
this.selectProductCateList = response.data.list;
|
|
|
|
this.selectProductCateList.unshift({id: 0, name: '无上级分类'});
|
|
|
|
this.selectProductCateList.unshift({ id: 0, name: '无上级分类' });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// 获取筛选属性分类及其属性
|
|
|
|
getProductAttrCateList() {
|
|
|
|
getProductAttrCateList() {
|
|
|
|
fetchListWithAttr().then(response => {
|
|
|
|
fetchListWithAttr().then(response => {
|
|
|
|
let list = response.data;
|
|
|
|
this.filterAttrs = response.data.map(category => ({
|
|
|
|
for (let i = 0; i < list.length; i++) {
|
|
|
|
label: category.name,
|
|
|
|
let productAttrCate = list[i];
|
|
|
|
value: category.id,
|
|
|
|
let children = [];
|
|
|
|
children: category.productAttributeList.map(attr => ({
|
|
|
|
if (productAttrCate.productAttributeList != null && productAttrCate.productAttributeList.length > 0) {
|
|
|
|
label: attr.name,
|
|
|
|
for (let j = 0; j < productAttrCate.productAttributeList.length; j++) {
|
|
|
|
value: attr.id
|
|
|
|
children.push({
|
|
|
|
}))
|
|
|
|
label: productAttrCate.productAttributeList[j].name,
|
|
|
|
}));
|
|
|
|
value: productAttrCate.productAttributeList[j].id
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
this.filterAttrs.push({label: productAttrCate.name, value: productAttrCate.id, children: children});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
getProductAttributeIdList() {
|
|
|
|
// 提交表单数据
|
|
|
|
//获取选中的筛选商品属性
|
|
|
|
|
|
|
|
let productAttributeIdList = [];
|
|
|
|
|
|
|
|
for (let i = 0; i < this.filterProductAttrList.length; i++) {
|
|
|
|
|
|
|
|
let item = this.filterProductAttrList[i];
|
|
|
|
|
|
|
|
if (item.value !== null && item.value.length === 2) {
|
|
|
|
|
|
|
|
productAttributeIdList.push(item.value[1]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return productAttributeIdList;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
onSubmit(formName) {
|
|
|
|
onSubmit(formName) {
|
|
|
|
this.$refs[formName].validate((valid) => {
|
|
|
|
this.$refs[formName].validate(valid => {
|
|
|
|
if (valid) {
|
|
|
|
if (valid) {
|
|
|
|
this.$confirm('是否提交数据', '提示', {
|
|
|
|
this.$confirm('是否提交数据', '提示', { type: 'warning' }).then(() => {
|
|
|
|
confirmButtonText: '确定',
|
|
|
|
|
|
|
|
cancelButtonText: '取消',
|
|
|
|
|
|
|
|
type: 'warning'
|
|
|
|
|
|
|
|
}).then(() => {
|
|
|
|
|
|
|
|
if (this.isEdit) {
|
|
|
|
|
|
|
|
this.productCate.productAttributeIdList = this.getProductAttributeIdList();
|
|
|
|
this.productCate.productAttributeIdList = this.getProductAttributeIdList();
|
|
|
|
updateProductCate(this.$route.query.id, this.productCate).then(response => {
|
|
|
|
if (this.isEdit) {
|
|
|
|
this.$message({
|
|
|
|
updateProductCate(this.$route.query.id, this.productCate).then(() => {
|
|
|
|
message: '修改成功',
|
|
|
|
this.$message.success('修改成功');
|
|
|
|
type: 'success',
|
|
|
|
|
|
|
|
duration: 1000
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
this.$router.back();
|
|
|
|
this.$router.back();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
this.productCate.productAttributeIdList = this.getProductAttributeIdList();
|
|
|
|
createProductCate(this.productCate).then(() => {
|
|
|
|
createProductCate(this.productCate).then(response => {
|
|
|
|
|
|
|
|
this.$refs[formName].resetFields();
|
|
|
|
|
|
|
|
this.resetForm(formName);
|
|
|
|
this.resetForm(formName);
|
|
|
|
this.$message({
|
|
|
|
this.$message.success('提交成功');
|
|
|
|
message: '提交成功',
|
|
|
|
|
|
|
|
type: 'success',
|
|
|
|
|
|
|
|
duration: 1000
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
this.$message({
|
|
|
|
this.$message.error('验证失败');
|
|
|
|
message: '验证失败',
|
|
|
|
|
|
|
|
type: 'error',
|
|
|
|
|
|
|
|
duration: 1000
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// 重置表单
|
|
|
|
resetForm(formName) {
|
|
|
|
resetForm(formName) {
|
|
|
|
this.$refs[formName].resetFields();
|
|
|
|
this.$refs[formName].resetFields();
|
|
|
|
this.productCate = Object.assign({}, defaultProductCate);
|
|
|
|
this.productCate = Object.assign({}, defaultProductCate);
|
|
|
|
this.getSelectProductCateList();
|
|
|
|
|
|
|
|
this.filterProductAttrList = [{
|
|
|
|
|
|
|
|
value: []
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
removeFilterAttr(productAttributeId) {
|
|
|
|
// 获取选中的筛选属性ID列表
|
|
|
|
if (this.filterProductAttrList.length === 1) {
|
|
|
|
getProductAttributeIdList() {
|
|
|
|
this.$message({
|
|
|
|
return this.filterProductAttrList
|
|
|
|
message: '至少要留一个',
|
|
|
|
.filter(item => item.value.length === 2)
|
|
|
|
type: 'warning',
|
|
|
|
.map(item => item.value[1]);
|
|
|
|
duration: 1000
|
|
|
|
},
|
|
|
|
});
|
|
|
|
// 删除筛选属性
|
|
|
|
return;
|
|
|
|
removeFilterAttr(filterAttr) {
|
|
|
|
}
|
|
|
|
const index = this.filterProductAttrList.indexOf(filterAttr);
|
|
|
|
var index = this.filterProductAttrList.indexOf(productAttributeId);
|
|
|
|
if (index > -1) this.filterProductAttrList.splice(index, 1);
|
|
|
|
if (index !== -1) {
|
|
|
|
|
|
|
|
this.filterProductAttrList.splice(index, 1)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// 添加筛选属性
|
|
|
|
handleAddFilterAttr() {
|
|
|
|
handleAddFilterAttr() {
|
|
|
|
if (this.filterProductAttrList.length === 3) {
|
|
|
|
if (this.filterProductAttrList.length < 3) {
|
|
|
|
this.$message({
|
|
|
|
this.filterProductAttrList.push({ value: [], key: Date.now() });
|
|
|
|
message: '最多添加三个',
|
|
|
|
} else {
|
|
|
|
type: 'warning',
|
|
|
|
this.$message.warning('最多添加三个');
|
|
|
|
duration: 1000
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.filterProductAttrList.push({
|
|
|
|
|
|
|
|
value: null,
|
|
|
|
|
|
|
|
key: Date.now()
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
filters: {
|
|
|
|
filters: {
|
|
|
|
|
|
|
|
// 自定义过滤器,为第一个筛选属性设置标签
|
|
|
|
filterLabelFilter(index) {
|
|
|
|
filterLabelFilter(index) {
|
|
|
|
if (index === 0) {
|
|
|
|
return index === 0 ? '筛选属性:' : '';
|
|
|
|
return '筛选属性:';
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return '';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
<style scoped>
|
|
|
|
|
|
|
|
/* 本地样式,样式只对当前组件生效 */
|
|
|
|
</style>
|
|
|
|
</style>
|
|
|
|