完善父子组件传值的问题,

并且在父组件调用子组件方法,来进行置空,更新父级品类选中列表的操作
master
20300 2024-03-11 20:55:08 +08:00
parent ed06a40cea
commit 561000160e
9 changed files with 195 additions and 42 deletions

View File

@ -16,3 +16,24 @@ export function insertCategory(insertCategoryReq) {
})
}
export function getAllCategoryAttribute(categoryId) {
return request({
url: '/product/category/getAllCategoryAttribute?categoryId='+categoryId,
method: 'get'
})
}
export function getAllCategoryAttributeGroup(categoryId) {
return request({
url: '/product/category/getAllCategoryAttributeGroup?categoryId='+categoryId,
method: 'get'
})
}
export function getAllCategoryBrand(categoryId) {
return request({
url: '/product/category/getAllCategoryBrand?categoryId='+categoryId,
method: 'get'
})
}

View File

@ -3,11 +3,11 @@
<el-row>
<el-card class="box-card">
<div>
<span>选择品牌关联关系</span>
<span>选择属性关联关系</span>
</div>
<el-card class="box-card" style="height: 150px;">
<div>
<span>已选品牌</span>
<span>已选属性</span>
</div>
<el-col>
<el-tag
@ -22,7 +22,7 @@
</el-card>
<el-card class="box-card" style="height: 150px;">
<div>
<span>可选品牌</span>
<span>可选属性</span>
</div>
<el-col>
<el-checkbox
@ -42,12 +42,14 @@
//jsjsjson,
//import from ',
import {list} from "@/api/product/attribute";
import {getAllCategoryAttribute} from "@/api/product/category";
export default {
name: 'CheckAttribute',
//import使"
components: {},
props: {},
props: {
},
data() {
//"
@ -58,7 +60,8 @@ export default {
selectAttributeList: [
],
//brand
parentSelectAttributeList: []
parentSelectAttributeList: [],
parentId: null
};
},
// data",
@ -73,6 +76,31 @@ export default {
},
//",
methods: {
updateParentId(newParentId) {
if (newParentId == undefined){
newParentId = 0;
}
getAllCategoryAttribute(newParentId).then(
res => {
console.log("属性已选中:",res)
this.selectAttributeList = []
this.parentSelectAttributeList = res.data
this.attributeList.forEach(
attr => {
this.parentSelectAttributeList.forEach(
parentSelect => {
if (attr.id == parentSelect.id){
console.log("添加了吗?")
this.selectAttributeList.push(attr)
}
}
)
}
)
console.log("属性:",res)
}
)
},
setAttributeListToParent(newVal) {
this.$emit("setCheckAttributeList", newVal)
},

View File

@ -23,6 +23,7 @@
<el-card class="box-card" style="height: 150px;">
<div>
<span>可选属性组</span>
<el-input type="text" v-model="parentId"></el-input>
</div>
<el-col>
<el-checkbox
@ -43,12 +44,15 @@
//import from ',
import {getBrandList} from "@/api/product/brand";
import {getAttributeGroupList} from "@/api/product/attribute";
import {getAllCategoryAttributeGroup} from "@/api/product/category";
export default {
name: 'CheckAttributeGroup',
//import使"
components: {},
props: {},
//props
props: {
},
data() {
//"
@ -59,7 +63,8 @@ export default {
selectAttributeGroupList: [
],
//brand
parentSelectAttributeGroupList: []
parentSelectAttributeGroupList: [],
parentId: null
};
},
// data",
@ -74,8 +79,31 @@ export default {
},
//",
methods: {
updateParentId(newParentId) {
if (newParentId == undefined){
newParentId = 0;
}
getAllCategoryAttributeGroup(newParentId).then(
res => {
this.parentSelectAttributeGroupList = res.data
this.selectAttributeGroupList = []
this.attributeGroupList.forEach(
attrGroup => {
this.parentSelectAttributeGroupList.forEach(
parentSelect => {
if (attrGroup.id == parentSelect.id){
this.selectAttributeGroupList.push(attrGroup)
}
}
)
}
)
console.log("属性组",res)
}
)
},
setAttributeGroupListToParent(newVal) {
this.$emit("setCheckAttributeList", newVal)
this.$emit("setCheckAttributeGroupList", newVal)
},
handleClose(tag) {
this.selectAttributeGroupList.splice(this.selectAttributeGroupList.indexOf(tag), 1);

View File

@ -23,6 +23,7 @@
<el-card class="box-card" style="height: 150px;">
<div>
<span>可选品牌</span>
<el-input v-model="parentId"></el-input>
</div>
<el-col>
<el-checkbox
@ -42,12 +43,15 @@
//jsjsjson,
//import from ',
import {getBrandList} from "@/api/product/brand";
import {getAllCategoryBrand} from "@/api/product/category";
import brand from "@/views/product/brand/index.vue";
export default {
name: 'CheckBrand',
//import使"
components: {},
props: {},
props: {
},
data() {
//"
@ -55,10 +59,10 @@ export default {
//brandList
brandList: [],
//brand
selectBrandList: [
],
selectBrandList: [],
//brand
parentSelectBrandList: []
parentSelectBrandList: [],
parentId: null
};
},
// data",
@ -73,6 +77,26 @@ export default {
},
//",
methods: {
updateParentId(newParentId) {
if (newParentId == undefined){
newParentId = 0;
}
getAllCategoryBrand(newParentId).then(
res => {
this.parentSelectBrandList = res.data
this.selectBrandList = []
if (this.parentSelectBrandList.length > 0){
this.parentSelectBrandList.forEach(parentSelect => this.brandList.forEach(
brand => {
if (brand.id == parentSelect.id){
this.selectBrandList.push(brand)
}
}
))
}
}
)
},
//
setBrandListToParent(newVal) {
this.$emit("setCheckBrandList",newVal)

View File

@ -120,7 +120,9 @@ export default {
name: "attributeGroup",
//import使"
components: {},
props: {},
props: {
},
data() {
//"
@ -138,7 +140,6 @@ export default {
//
attributeList: [],
attr:{}
};
},
// data",
@ -147,6 +148,7 @@ export default {
watch: {},
//",
methods: {
//
handleDelete(index, row) {
this.isOpenAddAttributeGroup = true
@ -215,7 +217,7 @@ export default {
},
//
getAttributeGroupList(){
getAttributeGroupList(this.attributeName).then(
getAttributeGroupList(0).then(
res => {
console.log(res);
this.attributeGroupList = res.data
@ -233,7 +235,7 @@ export default {
},
queryAttributeList(){
this.isOpenAddAttributeGroup = true
list(this.attributeQueryName).then(
list(0).then(
res => {
this.attributeList = res.data
}

View File

@ -76,6 +76,7 @@
<el-input v-model="addAttribute.remark" autocomplete="off"></el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="cancelInsert"> </el-button>
<el-button type="primary" @click="insertAttribute"> </el-button>
@ -94,7 +95,8 @@ export default {
name: 'attribute',
//import使"
components: {},
props: {},
props: {
},
data() {
//"
@ -110,7 +112,7 @@ export default {
remark: ''
},
//
openAdd: false
openAdd: false,
};
},
// data",
@ -119,6 +121,7 @@ export default {
watch: {},
//",
methods: {
//
//
handleEdit(index, row) {
console.log(index, row);
@ -140,7 +143,7 @@ export default {
},
//
getAttributeList(){
list(this.attributeName).then(
list(0).then(
res => {
this.attributeList = res.data
console.log(res)

View File

@ -86,7 +86,8 @@ import {deleteBrandInfo, getBrandList, insertBrand} from "@/api/product/brand";
components: {
UploadPic,
},
props: {},
props: {
},
data() {
//"
@ -95,7 +96,7 @@ import {deleteBrandInfo, getBrandList, insertBrand} from "@/api/product/brand";
insertBrandReg:{},
isInsertBrandOpen: false,
brandList: [],
brandName: ""
brandName: "",
};
},
// data",
@ -104,6 +105,8 @@ import {deleteBrandInfo, getBrandList, insertBrand} from "@/api/product/brand";
watch: {},
//",
methods: {
//
handleEdit(index, row) {
this.isInsertBrandOpen = true
this.insertBrandReg = row
@ -119,7 +122,7 @@ import {deleteBrandInfo, getBrandList, insertBrand} from "@/api/product/brand";
console.log(index, row);
},
getBrandList() {
getBrandList(this.brandName).then(
getBrandList(0).then(
res =>{
this.brandList = res.data
}

View File

@ -1,14 +1,44 @@
<template>
<div>
<el-table
:data="categoryOptions"
style="width: 100%;margin-bottom: 20px;"
row-key="id"
border
default-expand-all
:tree-props="{children: 'children', hasChildren: 'hasChildren'}">
<el-table-column
prop="id"
label="编号"
sortable
width="180">
</el-table-column>
<el-table-column
prop="name"
label="品类名称"
sortable
width="180">
</el-table-column>
<el-table-column
prop="introduction"
label="介绍">
</el-table-column>
<el-table-column label="图像">
<template slot-scope="scope">
<img :src="scope.row.image" alt="图片损坏">
</template>
</el-table-column>
</el-table>
<el-button size="mini" type="primary" @click="isInsertCategory=true"></el-button>
<el-dialog title="新增品类" :visible.sync="isInsertCategory" width="80%" append-to-body>
<el-form :model="insertCategoryReq">
<el-row>
<el-col :span="12" >
{{insertCategoryReq.parentId}}
<el-form-item label="父级品类" prop="parentId">
<treeselect v-model="insertCategoryReq.parentId" :options="categoryOptions" :normalizer="normalizer"/>
<treeselect v-model="insertCategoryReq.parentId" :options="categoryOptions" :normalizer="normalizer"/>
</el-form-item>
</el-col>
<el-col :span="12">
@ -20,7 +50,7 @@
<el-row>
<el-col :span="12">
<el-form-item label="图片上传" :label-width=formLabelWidth>
<upload-pic ref="uploadPic" @handle-image-url="handleImageUrl"></upload-pic>
<upload-pic ref="uploadPic" @handle-image-url="handleImageUrl"></upload-pic>
</el-form-item>
</el-col>
<el-col :span="12">
@ -33,13 +63,13 @@
<el-col :span="24">
<el-tabs v-model="activeName" @tab-click="handleClick">
<el-tab-pane label="品牌管理" name="first">
<check-brand @setCheckBrandList="getCheckBrandList"></check-brand>
<check-brand @setCheckBrandList="getCheckBrandList" ref="checkBrand"></check-brand>
</el-tab-pane>
<el-tab-pane label="属性组管理" name="second">
<check-attribute-group @setCheckAttributeList="getCheckAttributeGroupList"></check-attribute-group>
<check-attribute-group @setCheckAttributeGroupList="getCheckAttributeGroupList" ref="checkAttributeGroup"></check-attribute-group>
</el-tab-pane>
<el-tab-pane label="属性管理" name="third">
<check-attribute @setCheckAttributeList="getCheckAttributeList"></check-attribute>
<check-attribute @setCheckAttributeList="getCheckAttributeList" ref="checkAttribute" ></check-attribute>
</el-tab-pane>
</el-tabs>
</el-col>
@ -55,6 +85,7 @@
</template>
<script>
//
//jsjsjson,
//import from ',
import {getCategoryList, insertCategory} from "@/api/product/category";
@ -62,7 +93,7 @@ import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import UploadPic from "@/views/product/upload/uploadPic.vue";
import CheckBrand from "@/components/CheckBrand/index.vue";
import CheckAttributeGroup from "@/components/CheckAttributeGroup/index.vue";
import CheckAttributeGroup from "@/components/CheckAttributeGroup/index.vue"; //
import CheckAttribute from "@/components/CheckAttribute/index.vue";
@ -113,9 +144,27 @@ export default {
// data",
computed: {},
//data",
watch: {},
watch: {
'insertCategoryReq.parentId': function (newVal,oldVal){
this.$refs.checkAttribute.updateParentId(newVal)
this.$refs.checkAttributeGroup.updateParentId(newVal)
this.$refs.checkBrand.updateParentId(newVal)
},
'insertCategoryReq.image': function (newVal) {
this.$refs.uploadPic.deleteImage(newVal)
}
},
//",likeName
methods: {
deleteImage() {
},
handleEdit(index, row) {
console.log(index, row);
},
handleDelete(index, row) {
console.log(index, row);
},
//
insertCategory() {
insertCategory(this.insertCategoryReq).then(
@ -132,10 +181,9 @@ export default {
attributeList: [],
attributeGroupList: []
}
this.getTreeSelect();
}
)
console.log(this.insertCategoryReq)
},
//
getCheckAttributeGroupList(checkAttributeGroupList) {
@ -172,18 +220,11 @@ export default {
/** 查询品类信息下拉树结构 */
getTreeSelect() {
getCategoryList(this.likeName).then(response => {
console.log("获得的返回值是:",response)
this.categoryOptions = [];
const data = { id: 0, name: '顶级节点', children: [] };
data.children = this.handleTree(response.data, "id", "parentId");
this.categoryOptions.push(data);
this.categoryOptions = this.handleTree(response.data, "id", "parentId");
});
},
getCategoryList() {
getCategoryList(this.likeName).then(
res => {
this.categoryList = res.data
}
)
}
},
// - 访this",

View File

@ -35,6 +35,9 @@
watch: {},
//",
methods: {
deleteImage(newVal){
this.imageUrl = newVal
},
handleAvatarSuccess(res, file) {
console.log(res,file)