Files

141 lines
3.5 KiB
Vue
Raw Normal View History

2022-07-22 17:32:45 +08:00
<template>
<el-form
2023-06-09 17:30:58 +08:00
ref="form"
:label-width="labelWidth + 'px'"
:model="modelValue"
:rules="rules"
2022-07-22 17:32:45 +08:00
>
<el-row>
<el-col :span="24">
2023-06-09 17:30:58 +08:00
<el-form-item label="所属领域:">
<el-row justify="space-between" type="flex">
2022-07-22 17:32:45 +08:00
<el-col :span="7">
<el-form-item prop="industrys">
<el-select
2023-06-09 17:30:58 +08:00
v-model="modelValue.industrys[0]"
placeholder="请选择"
value-key="id"
@change="levelIChange"
2022-07-22 17:32:45 +08:00
>
<el-option
2023-06-09 17:30:58 +08:00
v-for="item in levelI"
:key="item.id"
:label="item.name"
:value="item.id"
2022-07-22 17:32:45 +08:00
>
</el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="7">
<el-select
2023-06-09 17:30:58 +08:00
v-model="modelValue.industrys[1]"
placeholder="请选择"
value-key="id"
@change="levelIIChange"
2022-07-22 17:32:45 +08:00
>
<el-option
2023-06-09 17:30:58 +08:00
v-for="item in levelII"
:key="item.id"
:label="item.name"
:value="item.id"
2022-07-22 17:32:45 +08:00
>
</el-option>
</el-select>
</el-col>
<el-col :span="7">
<el-select
2023-06-09 17:30:58 +08:00
v-model="modelValue.industrys[2]"
placeholder="请选择"
value-key="id"
2022-07-22 17:32:45 +08:00
>
<el-option
2023-06-09 17:30:58 +08:00
v-for="item in levelIII"
:key="item.id"
:label="item.name"
:value="item.id"
2022-07-22 17:32:45 +08:00
>
</el-option>
</el-select>
</el-col>
</el-row>
</el-form-item>
</el-col>
</el-row>
</el-form>
</template>
2023-06-09 17:30:58 +08:00
<script setup>
import {listSysIndustry} from "@/api/platform/industry";
// import { watch } from "fs";
import {reactive, toRefs, watch} from "vue";
const props = defineProps({
modelValue: Object,
labelWidth: {
type: Number,
default: 120,
2022-07-22 17:32:45 +08:00
},
2023-06-09 17:30:58 +08:00
});
const {modelValue, labelWidth} = toRefs(props);
const data = reactive({
rules: {
industrys: [
{
type: "array",
required: true,
message: "请选择",
trigger: "change",
2022-07-22 17:32:45 +08:00
},
2023-06-09 17:30:58 +08:00
],
2022-07-22 17:32:45 +08:00
},
2023-06-09 17:30:58 +08:00
});
const {rules} = toRefs(data);
const levelI = ref([]);
const levelII = ref([]);
const levelIII = ref([]);
// 获取领域树形列表
const getIndustryTreeData = async () => {
const {data} = await listSysIndustry();
levelI.value = data;
};
const levelIChange = async (item) => {
delete modelValue.value.industrys[1];
delete modelValue.value.industrys[2];
// levelII.value = levelI.value.find((el) => {
// return el.id === item;
// }).children;
};
const levelIIChange = async (item) => {
delete modelValue.value.industrys[2];
// levelIII.value = levelII.value.find((el) => el.id === item).children;
2022-07-22 17:32:45 +08:00
};
2023-06-09 17:30:58 +08:00
getIndustryTreeData().then(() => {
watch(
() => modelValue.value.industrys[0],
(val) => {
levelII.value =
levelI.value.find((el) => {
return el.id == val;
})?.children ?? [];
},
{immediate: true}
);
watch(
() => modelValue.value.industrys[1],
(val) => {
levelIII.value =
levelII.value.find((el) => {
return el.id == val;
})?.children ?? [];
},
{immediate: true}
);
});
</script>