Skip to content

Commit

Permalink
分类添加筛选属性
Browse files Browse the repository at this point in the history
  • Loading branch information
zhh committed May 23, 2018
1 parent d93e76c commit 8d6021a
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 8 deletions.
7 changes: 7 additions & 0 deletions src/api/productAttr.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,10 @@ export function getProductAttr(id) {
method:'get'
})
}

export function getProductAttrInfo(productCategoryId) {
return request({
url:'/productAttribute/attrInfo/'+productCategoryId,
method:'get'
})
}
16 changes: 16 additions & 0 deletions src/api/productCate.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,19 @@ export function getProductCate(id) {
method:'get',
})
}

export function updateShowStatus(data) {
return request({
url:'/productCategory/update/showStatus',
method:'post',
data:data
})
}

export function updateNavStatus(data) {
return request({
url:'/productCategory/update/navStatus',
method:'post',
data:data
})
}
2 changes: 1 addition & 1 deletion src/views/pms/productAttr/components/ProductAttrDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<el-radio-group v-model="productAttr.selectType">
<el-radio :label="0">唯一</el-radio>
<el-radio :label="1">单选</el-radio>
<el-radio :label="1">复选</el-radio>
<el-radio :label="2">复选</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="属性值的录入方式:">
Expand Down
106 changes: 102 additions & 4 deletions src/views/pms/productCate/components/ProductCateDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@
<el-form-item label="分类图标:">
<single-upload v-model="productCate.icon"></single-upload>
</el-form-item>
<el-form-item v-for="(filterProductAttr, index) in filterProductAttrList"
:label="index | filterLabelFilter"
:key="filterProductAttr.key"
>
<el-cascader
clearable
v-model="filterProductAttr.value"
:options="filterAttrs"
@active-item-change="handleItemChange">
</el-cascader>
<el-button style="margin-left: 20px" @click.prevent="removeFilterAttr(filterProductAttr)">删除</el-button>
</el-form-item>
<el-form-item>
<el-button size="small" type="primary" @click="handleAddFilterAttr()">新增</el-button>
</el-form-item>
<el-form-item label="关键词:">
<el-input v-model="productCate.keywords"></el-input>
</el-form-item>
Expand All @@ -55,6 +70,8 @@

<script>
import {fetchList, createProductCate, updateProductCate, getProductCate} from '@/api/productCate';
import {fetchList as fetchProductAttrCateList} from '@/api/productAttrCate';
import {fetchList as fetchProductAttrList,getProductAttrInfo} from '@/api/productAttr';
import SingleUpload from '@/components/Upload/singleUpload';
const defaultProductCate = {
Expand All @@ -66,7 +83,8 @@
parentId: 0,
productUnit: '',
showStatus: 0,
sort: 0
sort: 0,
productAttributeIdList: []
};
export default {
name: "ProductCateDetail",
Expand All @@ -86,7 +104,11 @@
{required: true, message: '请输入品牌名称', trigger: 'blur'},
{min: 2, max: 140, message: '长度在 2 到 140 个字符', trigger: 'blur'}
]
}
},
filterAttrs: [],
filterProductAttrList: [{
value: []
}]
}
},
created() {
Expand All @@ -98,6 +120,7 @@
this.productCate = Object.assign({}, defaultProductCate);
}
this.getSelectProductCateList();
this.getProductAttrCateList();
},
methods: {
getSelectProductCateList() {
Expand All @@ -106,6 +129,26 @@
this.selectProductCateList.unshift({id: 0, name: '无上级分类'});
});
},
getProductAttrCateList() {
fetchProductAttrCateList({pageSize: 100, pageNum: 1}).then(response => {
let productAttrCateList = response.data.list;
for (let i = 0; i < productAttrCateList.length; i++) {
let productAttrCate = productAttrCateList[i];
this.filterAttrs.push({label: productAttrCate.name, value: productAttrCate.id, 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) {
this.$refs[formName].validate((valid) => {
if (valid) {
Expand All @@ -116,7 +159,6 @@
}).then(() => {
if (this.isEdit) {
updateProductCate(this.$route.query.id, this.productCate).then(response => {
this.$refs[formName].resetFields();
this.$message({
message: '修改成功',
type: 'success',
Expand All @@ -125,9 +167,10 @@
this.$router.back();
});
} else {
this.productCate.productAttributeIdList = this.getProductAttributeIdList();
createProductCate(this.productCate).then(response => {
this.$refs[formName].resetFields();
this.brand = Object.assign({}, defaultProductCate);
this.resetForm(formName);
this.$message({
message: '提交成功',
type: 'success',
Expand All @@ -151,6 +194,61 @@
this.$refs[formName].resetFields();
this.productCate = Object.assign({}, defaultProductCate);
this.getSelectProductCateList();
this.filterProductAttrList= [{
value: []
}];
},
handleItemChange(val) {
let cateId = Number(val);
fetchProductAttrList(cateId, {pageSize: 100, pageNum: 1, type: 1}).then(response => {
let data = response.data.list;
let children = [];
for (let i = 0; i < data.length; i++) {
children.push({label: data[i].name, value: data[i].id});
}
for (let i = 0; i < this.filterAttrs.length; i++) {
if (cateId === this.filterAttrs[i].value) {
this.filterAttrs[i].children = children;
}
}
});
},
removeFilterAttr(productAttributeId) {
if (this.filterProductAttrList.length === 1) {
this.$message({
message: '至少要留一个',
type: 'warning',
duration: 1000
});
return;
}
var index = this.filterProductAttrList.indexOf(productAttributeId);
if (index !== -1) {
this.filterProductAttrList.splice(index, 1)
}
},
handleAddFilterAttr() {
if (this.filterProductAttrList.length === 3) {
this.$message({
message: '最多添加三个',
type: 'warning',
duration: 1000
});
return;
}
this.filterProductAttrList.push({
value: null,
key: Date.now()
});
}
},
filters: {
filterLabelFilter(index) {
if (index === 0) {
return '筛选属性:';
} else {
return '';
}
}
}
}
Expand Down
28 changes: 25 additions & 3 deletions src/views/pms/productCate/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
</template>

<script>
import {fetchList,deleteProductCate} from '@/api/productCate'
import {fetchList,deleteProductCate,updateShowStatus,updateNavStatus} from '@/api/productCate'
export default {
name: "productCateList",
Expand Down Expand Up @@ -152,10 +152,32 @@
this.getList();
},
handleNavStatusChange(index, row) {
console.log('handleNavStatusChange');
let data = new URLSearchParams();
let ids=[];
ids.push(row.id)
data.append('ids',ids);
data.append('navStatus',row.navStatus);
updateNavStatus(data).then(response=>{
this.$message({
message: '修改成功',
type: 'success',
duration: 1000
});
});
},
handleShowStatusChange(index, row) {
console.log('handleShowStatusChange');
let data = new URLSearchParams();
let ids=[];
ids.push(row.id)
data.append('ids',ids);
data.append('showStatus',row.showStatus);
updateShowStatus(data).then(response=>{
this.$message({
message: '修改成功',
type: 'success',
duration: 1000
});
});
},
handleShowNextLevel(index, row) {
this.$router.push({path: '/pms/productCate', query: {parentId: row.id}})
Expand Down

0 comments on commit 8d6021a

Please sign in to comment.