parent
2c436fffdb
commit
fa6cba311e
@ -1,65 +0,0 @@
|
||||
<template>
|
||||
<treeselect
|
||||
v-model="value1"
|
||||
:options="menuOptions"
|
||||
:show-count="true"
|
||||
placeholder="选择上级菜单"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Treeselect from "@riophae/vue-treeselect";
|
||||
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
|
||||
import {mapGetters} from "vuex";
|
||||
|
||||
export default {
|
||||
name: "ProdCategory",
|
||||
components: {Treeselect},
|
||||
props: ['value', 'root'],
|
||||
computed: {
|
||||
...mapGetters(['productCategories']),
|
||||
value1: {
|
||||
get() {
|
||||
return this.value;
|
||||
},
|
||||
set(v) {
|
||||
this.$emit('input', v);
|
||||
}
|
||||
},
|
||||
menuOptions() {
|
||||
if (!this.productCategories || this.productCategories.length === 0) {
|
||||
return [];
|
||||
}
|
||||
const map = {}
|
||||
this.productCategories.forEach(it => {
|
||||
let list = map[it.parentId]
|
||||
if (!list) {
|
||||
list = [];
|
||||
map[it.parentId] = list;
|
||||
}
|
||||
list.push({id: it.id, label: it.name, parentId: it.parentId});
|
||||
})
|
||||
const stack = [...map['0']];
|
||||
while (stack.length > 0) {
|
||||
const p = stack.shift();
|
||||
if (!map[p.id]) {
|
||||
continue
|
||||
}
|
||||
p.children = map[p.id];
|
||||
stack.push(...map[p.id])
|
||||
}
|
||||
if (this.root) {
|
||||
return [{id: 0, label: '根节点', children: map['0']}];
|
||||
}
|
||||
return map['0'];
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.$store.dispatch('mall/loadProductCategories')
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
@ -0,0 +1,56 @@
|
||||
<template>
|
||||
<el-cascader
|
||||
v-model="value1"
|
||||
:options="menuOptions"
|
||||
:props="{ checkStrictly: true }"
|
||||
placeholder="选择上级类目"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
|
||||
import {mapGetters} from "vuex";
|
||||
|
||||
export default {
|
||||
name: "ProductCategorySelect",
|
||||
props: ['value'],
|
||||
computed: {
|
||||
...mapGetters(['productCategories']),
|
||||
value1: {
|
||||
get() {
|
||||
console.log(this.value)
|
||||
return this.value;
|
||||
},
|
||||
set(v) {
|
||||
console.log(v)
|
||||
this.$emit('input', v);
|
||||
}
|
||||
},
|
||||
menuOptions() {
|
||||
if (!this.productCategories || this.productCategories.length === 0) {
|
||||
return [];
|
||||
}
|
||||
this.recurs(this.productCategories)
|
||||
return this.productCategories
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
recurs(list){
|
||||
list.forEach(it => {
|
||||
it.label = it.name
|
||||
it.value = it.id
|
||||
if(it.children){
|
||||
this.recurs(it.children)
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.$store.dispatch('mall/loadProductCategories')
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
Loading…
Reference in new issue