2022-07-22 17:32:45 +08:00
|
|
|
<template>
|
|
|
|
|
<el-form
|
2022-07-26 17:31:19 +08:00
|
|
|
ref="formRef"
|
2022-07-27 16:56:23 +08:00
|
|
|
:model="modelValue"
|
2022-07-22 17:32:45 +08:00
|
|
|
:rules="rules"
|
|
|
|
|
:label-width="labelWidth + 'px'"
|
|
|
|
|
:disabled="disabled"
|
|
|
|
|
>
|
|
|
|
|
<el-row>
|
|
|
|
|
<el-col :span="24">
|
2022-07-27 16:56:23 +08:00
|
|
|
<el-form-item label="所属领域:" required :show-message="false">
|
2022-07-22 17:32:45 +08:00
|
|
|
<el-row type="flex" justify="space-between">
|
|
|
|
|
<el-col :span="6">
|
|
|
|
|
<el-form-item prop="industrys">
|
|
|
|
|
<el-select
|
|
|
|
|
v-model="fields[0]"
|
|
|
|
|
value-key="id"
|
|
|
|
|
placeholder="请选择"
|
|
|
|
|
@change="levelIChange"
|
|
|
|
|
>
|
|
|
|
|
<el-option
|
|
|
|
|
v-for="item in levelI"
|
|
|
|
|
:key="item.id"
|
|
|
|
|
:label="item.name"
|
2022-07-27 16:56:23 +08:00
|
|
|
:value="item.id"
|
2022-07-22 17:32:45 +08:00
|
|
|
>
|
|
|
|
|
</el-option>
|
|
|
|
|
</el-select>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-col>
|
|
|
|
|
<el-col :span="6">
|
|
|
|
|
<el-select
|
|
|
|
|
v-model="fields[1]"
|
|
|
|
|
value-key="id"
|
|
|
|
|
placeholder="请选择"
|
2022-07-27 16:56:23 +08:00
|
|
|
:disabled="levelII.length === 0"
|
2022-07-22 17:32:45 +08:00
|
|
|
@change="levelIIChange"
|
|
|
|
|
>
|
|
|
|
|
<el-option
|
|
|
|
|
v-for="item in levelII"
|
|
|
|
|
:key="item.id"
|
|
|
|
|
:label="item.name"
|
2022-07-27 16:56:23 +08:00
|
|
|
:value="item.id"
|
2022-07-22 17:32:45 +08:00
|
|
|
>
|
|
|
|
|
</el-option>
|
|
|
|
|
</el-select>
|
|
|
|
|
</el-col>
|
|
|
|
|
<el-col :span="6">
|
|
|
|
|
<el-select
|
|
|
|
|
v-model="fields[2]"
|
|
|
|
|
value-key="id"
|
2022-07-27 16:56:23 +08:00
|
|
|
:disabled="levelIII.length === 0"
|
2022-07-22 17:32:45 +08:00
|
|
|
placeholder="请选择"
|
|
|
|
|
>
|
|
|
|
|
<el-option
|
|
|
|
|
v-for="item in levelIII"
|
|
|
|
|
:key="item.id"
|
|
|
|
|
:label="item.name"
|
2022-07-27 16:56:23 +08:00
|
|
|
:value="item.id"
|
2022-07-22 17:32:45 +08:00
|
|
|
>
|
|
|
|
|
</el-option>
|
|
|
|
|
</el-select>
|
|
|
|
|
</el-col>
|
|
|
|
|
<el-col :span="3">
|
|
|
|
|
<el-button type="primary" @click="fieldAdd">添加</el-button>
|
2022-07-27 16:56:23 +08:00
|
|
|
<!-- <el-button type="primary" @click="check">验证</el-button> -->
|
2022-07-22 17:32:45 +08:00
|
|
|
</el-col>
|
|
|
|
|
</el-row>
|
|
|
|
|
<div class="e_tag">
|
|
|
|
|
<el-tag
|
|
|
|
|
v-for="(tag, index) in industrysTags"
|
|
|
|
|
:key="index"
|
|
|
|
|
closable
|
|
|
|
|
@close="handleFieldClose(index)"
|
|
|
|
|
>
|
2022-07-27 16:56:23 +08:00
|
|
|
{{ getFieldNameById(tag) }}
|
|
|
|
|
<!-- <template v-if="Array.isArray(tag)">
|
|
|
|
|
<span v-for="(item, i) in tag" :key="item">
|
2022-07-22 17:32:45 +08:00
|
|
|
{{ item.name }}
|
|
|
|
|
<span v-if="tag.length != i + 1">></span>
|
|
|
|
|
</span>
|
|
|
|
|
</template>
|
|
|
|
|
<template v-else>
|
|
|
|
|
<span>{{ tag }}</span>
|
2022-07-27 16:56:23 +08:00
|
|
|
</template> -->
|
2022-07-22 17:32:45 +08:00
|
|
|
</el-tag>
|
|
|
|
|
</div>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-col>
|
|
|
|
|
</el-row>
|
|
|
|
|
</el-form>
|
|
|
|
|
</template>
|
2022-07-26 17:31:19 +08:00
|
|
|
<script setup name="FieldOptions">
|
2022-07-27 16:56:23 +08:00
|
|
|
// import { industry } from "@/api/config";
|
|
|
|
|
import { listSysIndustry } from "@/api/platform/industry";
|
2022-07-26 17:31:19 +08:00
|
|
|
import { ElMessage } from "element-plus";
|
|
|
|
|
import { toRefs, watch } from "vue";
|
|
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
|
modelValue: Object,
|
|
|
|
|
labelWidth: {
|
|
|
|
|
type: Number,
|
|
|
|
|
default: 120,
|
|
|
|
|
},
|
|
|
|
|
disabled: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false,
|
2022-07-22 17:32:45 +08:00
|
|
|
},
|
2022-07-26 17:31:19 +08:00
|
|
|
});
|
|
|
|
|
const { modelValue, labelWidth, disabled } = toRefs(props);
|
|
|
|
|
const formRef = ref(null);
|
|
|
|
|
const levelI = ref([]); // I级数据
|
|
|
|
|
const levelII = ref([]); // II级数据
|
|
|
|
|
const levelIII = ref([]); // III级数据
|
|
|
|
|
const fields = ref([]); // 当前下拉框选中的集合
|
|
|
|
|
const industrysTags = ref([]); // 点击添加按钮后临时存储的数据集合
|
|
|
|
|
const data = reactive({
|
|
|
|
|
rules: {
|
|
|
|
|
industrys: [
|
|
|
|
|
{
|
|
|
|
|
type: "array",
|
|
|
|
|
required: true,
|
|
|
|
|
message: "请选择并添加",
|
|
|
|
|
trigger: "change",
|
2022-07-22 17:32:45 +08:00
|
|
|
},
|
2022-07-26 17:31:19 +08:00
|
|
|
],
|
2022-07-22 17:32:45 +08:00
|
|
|
},
|
2022-07-26 17:31:19 +08:00
|
|
|
});
|
|
|
|
|
const { rules } = toRefs(data);
|
|
|
|
|
|
2022-07-27 16:56:23 +08:00
|
|
|
// 获取领域树形列表
|
|
|
|
|
const getIndustryTreeData = async () => {
|
|
|
|
|
const { data } = await listSysIndustry();
|
|
|
|
|
levelI.value = data;
|
2022-07-26 17:31:19 +08:00
|
|
|
};
|
2022-07-27 16:56:23 +08:00
|
|
|
|
2022-07-26 17:31:19 +08:00
|
|
|
const levelIChange = async (item) => {
|
|
|
|
|
delete fields.value[1];
|
|
|
|
|
delete fields.value[2];
|
2022-07-27 16:56:23 +08:00
|
|
|
levelII.value = levelI.value.find((el) => {
|
|
|
|
|
return el.id === item;
|
|
|
|
|
}).children;
|
2022-07-26 17:31:19 +08:00
|
|
|
};
|
2022-07-27 16:56:23 +08:00
|
|
|
|
2022-07-26 17:31:19 +08:00
|
|
|
const levelIIChange = async (item) => {
|
|
|
|
|
delete fields.value[2];
|
2022-07-27 16:56:23 +08:00
|
|
|
levelIII.value = levelII.value.find((el) => el.id === item).children;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 根据id获取领域名称
|
|
|
|
|
// TODO:如果领域已经被删除,则显示未知领域
|
|
|
|
|
const getFieldNameById = (ids) => {
|
|
|
|
|
if (levelI.value.length === 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let fieldNameList = [];
|
|
|
|
|
let subFieldList = [];
|
|
|
|
|
for (let i = 0; i < ids.length; i++) {
|
|
|
|
|
const id = ids[i];
|
|
|
|
|
if (fieldNameList.length === 0) {
|
|
|
|
|
subFieldList = levelI.value.find((el) => el.id == id)?.children;
|
|
|
|
|
fieldNameList.push(levelI.value.find((el) => id === el.id)?.name);
|
|
|
|
|
} else {
|
|
|
|
|
fieldNameList.push(subFieldList.find((el) => id === el.id)?.name);
|
|
|
|
|
subFieldList = subFieldList.find((el) => el.id == id)?.children;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return fieldNameList.join(">");
|
2022-07-26 17:31:19 +08:00
|
|
|
};
|
2022-07-27 16:56:23 +08:00
|
|
|
|
2022-07-26 17:31:19 +08:00
|
|
|
// 所属领域添加按钮
|
|
|
|
|
const fieldAdd = () => {
|
|
|
|
|
if (!fields.value.length) return ElMessage.error("请选择领域类型");
|
|
|
|
|
industrysTags.value.push(fields.value);
|
2022-07-27 16:56:23 +08:00
|
|
|
modelValue.value.industrys.push(fields.value.join("-"));
|
2022-07-26 17:31:19 +08:00
|
|
|
fields.value = [];
|
|
|
|
|
levelII.value = [];
|
|
|
|
|
levelIII.value = [];
|
2022-07-27 16:56:23 +08:00
|
|
|
// for (let i = 0; i < industrysTags.value.length; i++) {
|
|
|
|
|
// modelValue.value.industrys.push("");
|
|
|
|
|
// const item = industrysTags.value[i];
|
|
|
|
|
// for (let j = 0; j < item.length; j++) {
|
|
|
|
|
// const item2 = item[j];
|
|
|
|
|
// if (modelValue.value.industrys[i] == "") {
|
|
|
|
|
// modelValue.value.industrys[i] = item2.id;
|
|
|
|
|
// } else {
|
|
|
|
|
// modelValue.value.industrys[i] =
|
|
|
|
|
// modelValue.value.industrys[i] + "-" + item2.id;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// fields.value = [];
|
|
|
|
|
// levelII.value = [];
|
|
|
|
|
// levelIII.value = [];
|
2022-07-26 17:31:19 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleFieldClose = (index) => {
|
|
|
|
|
industrysTags.value.splice(index, 1);
|
|
|
|
|
modelValue.value.industrys.splice(index, 1);
|
2022-07-27 16:56:23 +08:00
|
|
|
formRef.value.validate();
|
2022-07-26 17:31:19 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const validateForm = async () => {
|
|
|
|
|
try {
|
2022-07-27 16:56:23 +08:00
|
|
|
return await formRef.value.validate();
|
2022-07-26 17:31:19 +08:00
|
|
|
} catch (error) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2022-07-27 16:56:23 +08:00
|
|
|
getIndustryTreeData();
|
2022-07-26 17:31:19 +08:00
|
|
|
|
|
|
|
|
watch(modelValue, (newVal) => {
|
2022-07-27 16:56:23 +08:00
|
|
|
modelValue.value.industrys = [];
|
|
|
|
|
modelValue.value.industrys.push(...modelValue.value.industry.split(","));
|
|
|
|
|
for (const field of modelValue.value.industry.split(",")) {
|
|
|
|
|
industrysTags.value.push(field.split("-").map((el) => parseInt(el)));
|
2022-07-26 17:31:19 +08:00
|
|
|
}
|
2022-07-27 16:56:23 +08:00
|
|
|
// let _key = [];
|
|
|
|
|
// let _value = [];
|
|
|
|
|
// for (let i = 0; i < newVal.industrys.length; i++) {
|
|
|
|
|
// const item = newVal.industrys[i];
|
|
|
|
|
// _key.push(item.key);
|
|
|
|
|
// _value.push(item.value);
|
|
|
|
|
// }
|
|
|
|
|
// newVal.industrys = _key;
|
|
|
|
|
// let keyObj = [];
|
|
|
|
|
// for (let i = 0; i < _key.length; i++) {
|
|
|
|
|
// keyObj.push([]);
|
|
|
|
|
// let array = _key[i].split("-");
|
|
|
|
|
// for (let j = 0; j < array.length; j++) {
|
|
|
|
|
// keyObj[i].push({
|
|
|
|
|
// id: array[j],
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// for (let i = 0; i < _value.length; i++) {
|
|
|
|
|
// let array = _value[i].split(">");
|
|
|
|
|
// for (let j = 0; j < array.length; j++) {
|
|
|
|
|
// keyObj[i][j]["name"] = array[j];
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// industrysTags.value = keyObj;
|
2022-07-26 17:31:19 +08:00
|
|
|
});
|
2022-07-27 16:56:23 +08:00
|
|
|
|
2022-07-26 17:31:19 +08:00
|
|
|
defineExpose({
|
|
|
|
|
validateForm,
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<!-- <script>
|
|
|
|
|
export default {
|
2022-07-22 17:32:45 +08:00
|
|
|
watch: {
|
|
|
|
|
value(newVal, oldVal) {
|
|
|
|
|
let _key = [];
|
|
|
|
|
let _value = [];
|
|
|
|
|
for (let i = 0; i < newVal.industrys.length; i++) {
|
|
|
|
|
const item = newVal.industrys[i];
|
|
|
|
|
_key.push(item.key);
|
|
|
|
|
_value.push(item.value);
|
|
|
|
|
}
|
|
|
|
|
newVal.industrys = _key;
|
|
|
|
|
|
|
|
|
|
let keyObj = [];
|
|
|
|
|
for (let i = 0; i < _key.length; i++) {
|
|
|
|
|
keyObj.push([]);
|
|
|
|
|
let array = _key[i].split("-");
|
|
|
|
|
for (let j = 0; j < array.length; j++) {
|
|
|
|
|
keyObj[i].push({
|
|
|
|
|
id: array[j],
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (let i = 0; i < _value.length; i++) {
|
|
|
|
|
let array = _value[i].split(">");
|
|
|
|
|
for (let j = 0; j < array.length; j++) {
|
|
|
|
|
keyObj[i][j]["name"] = array[j];
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-26 17:31:19 +08:00
|
|
|
industrysTags.value = keyObj;
|
2022-07-22 17:32:45 +08:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
2022-07-26 17:31:19 +08:00
|
|
|
</script> -->
|
2022-07-22 17:32:45 +08:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
.e_tag {
|
|
|
|
|
.el-tag {
|
|
|
|
|
margin-right: 10px;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-26 17:31:19 +08:00
|
|
|
</style>
|