|
@@ -1,54 +1,86 @@
|
|
|
<template>
|
|
|
- <el-select v-model="value" :clearable="true" placeholder="请选择分类">
|
|
|
- <el-option
|
|
|
- v-for="item in options"
|
|
|
- :key="item.value"
|
|
|
- :label="item.label"
|
|
|
- :value="item.value"
|
|
|
- >
|
|
|
- </el-option>
|
|
|
- </el-select>
|
|
|
+ <el-cascader
|
|
|
+ :value="vModel"
|
|
|
+ :options="options"
|
|
|
+ :clearable="true"
|
|
|
+ :show-all-levels="false"
|
|
|
+ @change="onChange"
|
|
|
+ ></el-cascader>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+import { getList } from '@/api/help/type';
|
|
|
+
|
|
|
+const resetList = (arr = []) => {
|
|
|
+ const reuslt = arr.map(x => ({
|
|
|
+ value: x.id,
|
|
|
+ label: x.name,
|
|
|
+ children: x.children && x.children.length > 0 ? resetList(x.children) : null
|
|
|
+ }));
|
|
|
+ return reuslt;
|
|
|
+};
|
|
|
+
|
|
|
+const checkList = (list = []) => {
|
|
|
+ list = list.reduce((init, item) => {
|
|
|
+ if (item.children) {
|
|
|
+ init.push(item);
|
|
|
+ }
|
|
|
+ return init;
|
|
|
+ }, []);
|
|
|
+ return list;
|
|
|
+};
|
|
|
+
|
|
|
export default {
|
|
|
name: 'IssueTypeSelect',
|
|
|
|
|
|
- model: {
|
|
|
- prop: 'value',
|
|
|
- event: 'change'
|
|
|
- },
|
|
|
-
|
|
|
props: {
|
|
|
value: {
|
|
|
type: String,
|
|
|
default: ''
|
|
|
- },
|
|
|
- params: {
|
|
|
- type: Object,
|
|
|
- default: () => {}
|
|
|
}
|
|
|
},
|
|
|
|
|
|
data() {
|
|
|
return {
|
|
|
+ vModel: this.value,
|
|
|
options: []
|
|
|
};
|
|
|
},
|
|
|
|
|
|
- // mounted() {
|
|
|
- // this.loadData()
|
|
|
- // },
|
|
|
+ watch: {
|
|
|
+ value: {
|
|
|
+ handler(val) {
|
|
|
+ this.vModel = val;
|
|
|
+ },
|
|
|
+ immediate: true
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ mounted() {
|
|
|
+ this.loadData();
|
|
|
+ },
|
|
|
|
|
|
methods: {
|
|
|
- // async loadData() {
|
|
|
- // const { success, data, msg } = await (params)
|
|
|
- // if (success) {
|
|
|
- // this.options = data
|
|
|
- // } else {
|
|
|
- // this.$error(msg)
|
|
|
- // }
|
|
|
- // }
|
|
|
+ onChange(value) {
|
|
|
+ console.log(value);
|
|
|
+ this.$emit('input', value[1] || null);
|
|
|
+ },
|
|
|
+
|
|
|
+ async loadData() {
|
|
|
+ const { success, data, msg } = await getList({
|
|
|
+ data: {
|
|
|
+ isShow: null
|
|
|
+ },
|
|
|
+ limit: 999999,
|
|
|
+ start: 1
|
|
|
+ });
|
|
|
+ if (success) {
|
|
|
+ let result = resetList(data.data);
|
|
|
+ this.options = checkList(result);
|
|
|
+ } else {
|
|
|
+ this.$error(msg);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
</script>
|