忘了写到哪了
This commit is contained in:
174
src/views/components/CityOptions/index.vue
Normal file
174
src/views/components/CityOptions/index.vue
Normal file
@ -0,0 +1,174 @@
|
||||
<template>
|
||||
<el-form
|
||||
ref="formRef"
|
||||
:model="modelValue"
|
||||
:rules="rules"
|
||||
:label-width="`${labelWidth}px`"
|
||||
>
|
||||
<el-row>
|
||||
<el-col :span="24">
|
||||
<el-form-item label="所在地:" required>
|
||||
<el-row type="flex" justify="space-between">
|
||||
<el-col :span="7">
|
||||
<el-form-item prop="province">
|
||||
<el-select
|
||||
v-model="modelValue.province"
|
||||
clearable
|
||||
filterable
|
||||
placeholder="请选择"
|
||||
:disabled="provinceSelectList.length === 0"
|
||||
@change="provinceChanged"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in provinceSelectList"
|
||||
:key="item.provinceCode"
|
||||
:label="item.provinceName"
|
||||
:value="item.provinceCode"
|
||||
>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="7">
|
||||
<el-form-item prop="city">
|
||||
<el-select
|
||||
v-model="modelValue.city"
|
||||
clearable
|
||||
filterable
|
||||
:disabled="citySelectList.length === 0"
|
||||
placeholder="请选择"
|
||||
@change="cityChanged"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in citySelectList"
|
||||
:key="item.cityCode"
|
||||
:label="item.cityName"
|
||||
:value="item.cityCode"
|
||||
>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="7">
|
||||
<el-form-item prop="district">
|
||||
<el-select
|
||||
v-model="modelValue.district"
|
||||
clearable
|
||||
filterable
|
||||
:disabled="districtSelectList.length === 0"
|
||||
placeholder="请选择"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in districtSelectList"
|
||||
:key="item.areaCode"
|
||||
:label="item.areaName"
|
||||
:value="item.areaCode"
|
||||
>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form>
|
||||
</template>
|
||||
<script setup name="CityOptions">
|
||||
import { provinceList, cityList, districtList } from "@/api/config";
|
||||
import { reactive, ref, toRefs } from "vue";
|
||||
|
||||
const props = defineProps({
|
||||
modelValue: Object,
|
||||
labelWidth: {
|
||||
type: Number,
|
||||
default: 120,
|
||||
},
|
||||
});
|
||||
const { modelValue, labelWidth } = toRefs(props);
|
||||
const formRef = ref(null);
|
||||
const provinceSelectList = ref([]); // 省
|
||||
const citySelectList = ref([]); // 市
|
||||
const districtSelectList = ref([]); // 区\
|
||||
const data = reactive({
|
||||
rules: {
|
||||
province: [
|
||||
{ required: true, message: "请选择", trigger: ["change", "blue"] },
|
||||
],
|
||||
city: [{ required: true, message: "请选择", trigger: ["change", "blue"] }],
|
||||
district: [
|
||||
{ required: true, message: "请选择", trigger: ["change", "blue"] },
|
||||
],
|
||||
},
|
||||
});
|
||||
const { rules } = toRefs(data);
|
||||
// 获取 省列表
|
||||
const getProvinceList = async () => {
|
||||
const resp = await provinceList();
|
||||
provinceSelectList.value = resp.data.map((el) => {
|
||||
return { ...el, provinceCode: el.provinceCode.toString() };
|
||||
});
|
||||
};
|
||||
// 获取市列表
|
||||
const getCityListByProvinceId = async (provinceId) => {
|
||||
const { data } = await cityList(provinceId);
|
||||
citySelectList.value = data.map((el) => {
|
||||
return {
|
||||
...el,
|
||||
cityCode: el.cityCode.toString(),
|
||||
};
|
||||
});
|
||||
};
|
||||
// 根据市id获取县区列表
|
||||
const getAreaListByCityId = async (cityId) => {
|
||||
const { data } = await districtList(cityId);
|
||||
districtSelectList.value = data.map((el) => {
|
||||
return {
|
||||
...el,
|
||||
areaCode: el.areaCode.toString(),
|
||||
};
|
||||
});
|
||||
};
|
||||
// 当省改变时
|
||||
const provinceChanged = () => {
|
||||
// 清除市县代码列表
|
||||
modelValue.value.city = undefined;
|
||||
modelValue.value.district = undefined;
|
||||
// 清除市县列表
|
||||
citySelectList.value = [];
|
||||
districtSelectList.value = [];
|
||||
// 重新请求城市列表
|
||||
modelValue.value.province &&
|
||||
getCityListByProvinceId(modelValue.value.province);
|
||||
};
|
||||
// 当市改变时
|
||||
const cityChanged = () => {
|
||||
// 清除县区代码列表
|
||||
modelValue.value.district = undefined;
|
||||
districtSelectList.value = [];
|
||||
modelValue.value.city && getAreaListByCityId(modelValue.value.city);
|
||||
};
|
||||
|
||||
const validateForm = async () => {
|
||||
try {
|
||||
return await formRef.value.validate();
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
watch(modelValue, (val) => {
|
||||
if (val.province) {
|
||||
getCityListByProvinceId(val.province);
|
||||
}
|
||||
if (val.city) {
|
||||
getAreaListByCityId(val.city);
|
||||
}
|
||||
});
|
||||
|
||||
getProvinceList();
|
||||
|
||||
defineExpose({
|
||||
validateForm,
|
||||
});
|
||||
</script>
|
||||
263
src/views/components/EnterpriseForm/index.vue
Normal file
263
src/views/components/EnterpriseForm/index.vue
Normal file
@ -0,0 +1,263 @@
|
||||
<template>
|
||||
<el-form
|
||||
ref="formRef"
|
||||
:model="modelValue"
|
||||
:rules="rules"
|
||||
:label-width="labelWidth + 'px'"
|
||||
>
|
||||
<div class="form_title" v-if="showTitle">基本信息</div>
|
||||
|
||||
<el-row v-if="isAdd">
|
||||
<el-col :span="24">
|
||||
<el-form-item label="企业logo:">
|
||||
<ImageUpload v-model="modelValue.image" :limit="1" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row v-if="isAdd">
|
||||
<el-col :span="24">
|
||||
<el-form-item label="单位名称" prop="name">
|
||||
<el-input v-model="modelValue.name"></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row v-if="isAdd">
|
||||
<el-col :span="24">
|
||||
<el-form-item label="组织机构代码:" prop="code">
|
||||
<el-row type="flex" justify="space-between">
|
||||
<el-col :span="20">
|
||||
<el-input v-model="modelValue.code"></el-input>
|
||||
</el-col>
|
||||
<el-col :span="3">
|
||||
<el-button type="primary" @click="">查找</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="24">
|
||||
<el-form-item label="企业类型:" prop="kind">
|
||||
<el-select v-model="modelValue.kind" placeholder="请选择">
|
||||
<el-option
|
||||
v-for="item in enterpriseOptions"
|
||||
:key="item.key"
|
||||
:label="item.value"
|
||||
:value="item.key"
|
||||
>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="24">
|
||||
<el-form-item label="核心成果核心产品:" prop="product">
|
||||
<el-input v-model="modelValue.product"></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<CityOptions
|
||||
v-model="modelValue"
|
||||
:labelWidth="labelWidth"
|
||||
ref="cityFormRef"
|
||||
/>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="24">
|
||||
<el-form-item label="详细地址:">
|
||||
<el-input v-model="modelValue.address"></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<FieldOptions
|
||||
v-model="modelValue"
|
||||
:labelWidth="labelWidth"
|
||||
ref="fieldFormRef"
|
||||
/>
|
||||
|
||||
<InputBoxAdd
|
||||
:labelWidth="labelWidth"
|
||||
v-model="modelValue"
|
||||
title="关键词"
|
||||
placeholder="应用场景关键词+技术产品关键词"
|
||||
fieldKey="keywords"
|
||||
ref="keywordsFormRef"
|
||||
/>
|
||||
<InputBoxAdd
|
||||
v-if="isAdd"
|
||||
:labelWidth="labelWidth"
|
||||
v-model="modelValue"
|
||||
title="生产方向"
|
||||
placeholder="请输入生产方向"
|
||||
fieldKey="directions"
|
||||
ref="directionsFormRef"
|
||||
/>
|
||||
|
||||
<el-row>
|
||||
<!-- <el-col :span="24">
|
||||
<el-form-item label="邀请码:">
|
||||
<el-input v-model="modelValue.inviter_code"></el-input>
|
||||
</el-form-item>
|
||||
</el-col> -->
|
||||
<el-col :span="24">
|
||||
<el-form-item label="企业网站:">
|
||||
<el-input v-model="modelValue.url"></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row v-if="isAdd">
|
||||
<el-col :span="24">
|
||||
<el-form-item label="营业执照:" prop="license">
|
||||
<ImageUpload
|
||||
v-model="modelValue.license"
|
||||
:isShowTip="false"
|
||||
:limit="1"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="24">
|
||||
<el-form-item label="单位简介" prop="introduce">
|
||||
<WangEditor v-model="modelValue.introduce" :minHeight="300" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form>
|
||||
</template>
|
||||
|
||||
<script setup name="EnterpriseForm">
|
||||
import CityOptions from "../CityOptions";
|
||||
import FieldOptions from "../FieldOptions";
|
||||
import InputBoxAdd from "../InputBoxAdd";
|
||||
// import { researchSelect, laboratorySelect } from "@/api/identity/index";
|
||||
import WangEditor from "@/components/WangEditor";
|
||||
import { enterpriseOptions } from "@/utils/parameter";
|
||||
import { toRefs } from "vue";
|
||||
|
||||
const props = defineProps({
|
||||
modelValue: Object,
|
||||
isAdd: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
showTitle: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
labelWidth: {
|
||||
type: Number,
|
||||
default: 120,
|
||||
},
|
||||
});
|
||||
const { modelValue, isAdd, showTitle, labelWidth } = toRefs(props);
|
||||
const data = reactive({
|
||||
rules: {
|
||||
product: [{ required: true, message: "请输入", trigger: "blur" }],
|
||||
name: [{ required: true, message: "请输入", trigger: "blur" }],
|
||||
kind: [{ required: true, message: "请选择", trigger: "change" }],
|
||||
code: [{ required: true, message: "请输入", trigger: "blur" }],
|
||||
mobile: [
|
||||
{ required: true, message: "请输入", trigger: "blur" },
|
||||
{
|
||||
pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
|
||||
message: "请输入正确的手机号码",
|
||||
trigger: "blur",
|
||||
},
|
||||
],
|
||||
research_id: [{ required: true, message: "请选择", trigger: "change" }],
|
||||
tenant_id: [
|
||||
{
|
||||
required: true,
|
||||
message: "请选择",
|
||||
trigger: ["blur", "change"],
|
||||
},
|
||||
],
|
||||
school: [{ required: true, message: "请输入", trigger: "blur" }],
|
||||
education: [{ required: true, message: "请选择", trigger: "change" }],
|
||||
major: [{ required: true, message: "请输入", trigger: "blur" }],
|
||||
job: [{ required: true, message: "请输入", trigger: "blur" }],
|
||||
title: [{ required: true, message: "请输入", trigger: "blur" }],
|
||||
work_at: [
|
||||
{
|
||||
required: true,
|
||||
message: "从业时间不能为空",
|
||||
trigger: ["change", "blur"],
|
||||
},
|
||||
],
|
||||
license: [
|
||||
{
|
||||
required: true,
|
||||
message: "请上传",
|
||||
trigger: ["blur", "change"],
|
||||
},
|
||||
],
|
||||
introduce: [
|
||||
{
|
||||
required: true,
|
||||
message: "请输入",
|
||||
trigger: ["change", "blur"],
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
const { rules } = toRefs(data);
|
||||
|
||||
const formRef = ref();
|
||||
const cityFormRef = ref();
|
||||
const fieldFormRef = ref();
|
||||
const keywordsFormRef = ref();
|
||||
const directionsFormRef = ref();
|
||||
|
||||
const validateForm = async () => {
|
||||
let formValid;
|
||||
try {
|
||||
formValid = await formRef.value.validate();
|
||||
} catch (error) {
|
||||
formValid = false;
|
||||
}
|
||||
const cityFormValid = await cityFormRef.value.validateForm(); // 城市选择表单验证
|
||||
const fieldFormValid = await fieldFormRef.value.validateForm(); // 领域选择表单验证
|
||||
const keywordsFormValid = await keywordsFormRef.value.validateForm(); // 关键词表单验证
|
||||
console.log(cityFormValid);
|
||||
if (isAdd.value) {
|
||||
const directionsFormValid = await directionsFormRef.value.validateForm();
|
||||
return (
|
||||
formValid &&
|
||||
cityFormValid &&
|
||||
fieldFormValid &&
|
||||
keywordsFormValid &&
|
||||
directionsFormValid
|
||||
);
|
||||
} else {
|
||||
return formValid && cityFormValid && fieldFormValid && keywordsFormValid;
|
||||
}
|
||||
};
|
||||
defineExpose({
|
||||
validateForm,
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.form_title {
|
||||
font-weight: 700;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
// 上传图片框限制
|
||||
// ::v-deep .el-upload--picture-card {
|
||||
// width: 120px;
|
||||
// height: 120px;
|
||||
// line-height: 120px;
|
||||
// }
|
||||
.el-select,
|
||||
.el-date-editor {
|
||||
display: block;
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
218
src/views/components/FieldOptions/index.vue
Normal file
218
src/views/components/FieldOptions/index.vue
Normal file
@ -0,0 +1,218 @@
|
||||
<template>
|
||||
<el-form
|
||||
ref="formRef"
|
||||
:model="modelValue"
|
||||
:rules="rules"
|
||||
:label-width="labelWidth + 'px'"
|
||||
:disabled="disabled"
|
||||
>
|
||||
<el-row>
|
||||
<el-col :span="24">
|
||||
<el-form-item label="所属领域:" required :show-message="false">
|
||||
<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"
|
||||
:value="item.id"
|
||||
>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-select
|
||||
v-model="fields[1]"
|
||||
value-key="id"
|
||||
placeholder="请选择"
|
||||
:disabled="levelII.length === 0"
|
||||
@change="levelIIChange"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in levelII"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id"
|
||||
>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-select
|
||||
v-model="fields[2]"
|
||||
value-key="id"
|
||||
:disabled="levelIII.length === 0"
|
||||
placeholder="请选择"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in levelIII"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id"
|
||||
>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-col>
|
||||
<el-col :span="3">
|
||||
<el-button type="primary" @click="fieldAdd">添加</el-button>
|
||||
<!-- <el-button type="primary" @click="check">验证</el-button> -->
|
||||
</el-col>
|
||||
</el-row>
|
||||
<div class="e_tag">
|
||||
<el-tag
|
||||
v-for="(tag, index) in industrysTags"
|
||||
:key="index"
|
||||
closable
|
||||
@close="handleFieldClose(index)"
|
||||
>
|
||||
{{ getFieldNameById(tag) }}
|
||||
<!-- <template v-if="Array.isArray(tag)">
|
||||
<span v-for="(item, i) in tag" :key="item">
|
||||
{{ item.name }}
|
||||
<span v-if="tag.length != i + 1">></span>
|
||||
</span>
|
||||
</template>
|
||||
<template v-else>
|
||||
<span>{{ tag }}</span>
|
||||
</template> -->
|
||||
</el-tag>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form>
|
||||
</template>
|
||||
<script setup name="FieldOptions">
|
||||
// import { industry } from "@/api/config";
|
||||
import { listSysIndustry } from "@/api/config";
|
||||
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,
|
||||
},
|
||||
});
|
||||
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",
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
const { rules } = toRefs(data);
|
||||
|
||||
// 获取领域树形列表
|
||||
const getIndustryTreeData = async () => {
|
||||
const { data } = await listSysIndustry();
|
||||
levelI.value = data;
|
||||
};
|
||||
|
||||
const levelIChange = async (item) => {
|
||||
delete fields.value[1];
|
||||
delete fields.value[2];
|
||||
levelII.value = levelI.value.find((el) => {
|
||||
return el.id === item;
|
||||
}).children;
|
||||
};
|
||||
|
||||
const levelIIChange = async (item) => {
|
||||
delete fields.value[2];
|
||||
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(">");
|
||||
};
|
||||
|
||||
// 所属领域添加按钮
|
||||
const fieldAdd = () => {
|
||||
if (!fields.value.length) return ElMessage.error("请选择领域类型");
|
||||
industrysTags.value.push(fields.value);
|
||||
if (!modelValue.value.industrys) modelValue.value.industrys = [];
|
||||
modelValue.value.industrys.push(fields.value.join("-"));
|
||||
fields.value = [];
|
||||
levelII.value = [];
|
||||
levelIII.value = [];
|
||||
};
|
||||
|
||||
const handleFieldClose = (index) => {
|
||||
industrysTags.value.splice(index, 1);
|
||||
modelValue.value.industrys.splice(index, 1);
|
||||
formRef.value.validate();
|
||||
};
|
||||
|
||||
const validateForm = async () => {
|
||||
try {
|
||||
return await formRef.value.validate();
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
getIndustryTreeData();
|
||||
|
||||
watch(modelValue, (newVal) => {
|
||||
modelValue.value.industrys = [];
|
||||
industrysTags.value = [];
|
||||
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)));
|
||||
}
|
||||
});
|
||||
|
||||
defineExpose({
|
||||
validateForm,
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.e_tag {
|
||||
.el-tag {
|
||||
margin-right: 10px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
146
src/views/components/FieldSingle/index.vue
Normal file
146
src/views/components/FieldSingle/index.vue
Normal file
@ -0,0 +1,146 @@
|
||||
<template>
|
||||
<el-form
|
||||
ref="form"
|
||||
:model="modelValue"
|
||||
:rules="rules"
|
||||
:label-width="labelWidth + 'px'"
|
||||
>
|
||||
<el-row>
|
||||
<el-col :span="24">
|
||||
<el-form-item label="所属领域:" required>
|
||||
<el-row type="flex" justify="space-between">
|
||||
<el-col :span="7">
|
||||
<el-form-item prop="industrys">
|
||||
<el-select
|
||||
v-model="modelValue.industrys[0]"
|
||||
value-key="id"
|
||||
placeholder="请选择"
|
||||
@change="levelIChange"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in levelI"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id"
|
||||
>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="7">
|
||||
<el-select
|
||||
v-model="modelValue.industrys[1]"
|
||||
value-key="id"
|
||||
placeholder="请选择"
|
||||
@change="levelIIChange"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in levelII"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id"
|
||||
>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-col>
|
||||
<el-col :span="7">
|
||||
<el-select
|
||||
v-model="modelValue.industrys[2]"
|
||||
value-key="id"
|
||||
placeholder="请选择"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in levelIII"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id"
|
||||
>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form>
|
||||
</template>
|
||||
<script>
|
||||
import { industry } from "@/api/config";
|
||||
export default {
|
||||
props: {
|
||||
modelValue: Object,
|
||||
labelWidth: {
|
||||
type: Number,
|
||||
default: 120,
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
levelI: [], // I级数据
|
||||
levelII: [], // II级数据
|
||||
levelIII: [], // III级数据
|
||||
rules: {
|
||||
industrys: [
|
||||
{
|
||||
type: "array",
|
||||
required: true,
|
||||
message: "请选择",
|
||||
trigger: "change",
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
// modelValue(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;
|
||||
// },
|
||||
},
|
||||
methods: {
|
||||
getFieldByParent(id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
industry({ parent_id: id })
|
||||
.then(({ code, msg, data }) => {
|
||||
if (code == 200) {
|
||||
resolve(data);
|
||||
} else {
|
||||
this.$modal.msgError(msg);
|
||||
reject({ msg, code });
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
},
|
||||
async levelIChange(id) {
|
||||
delete this.modelValue.industrys[1];
|
||||
delete this.modelValue.industrys[2];
|
||||
this.levelII = await this.getFieldByParent(id);
|
||||
},
|
||||
async levelIIChange(id) {
|
||||
delete this.modelValue.industrys[2];
|
||||
this.levelIII = await this.getFieldByParent(id);
|
||||
},
|
||||
submitForm() {
|
||||
let flag = false;
|
||||
this.$refs["form"].validate((valid) => {
|
||||
flag = valid;
|
||||
});
|
||||
return flag;
|
||||
},
|
||||
},
|
||||
created() {
|
||||
industry().then((res) => {
|
||||
this.levelI = res.data;
|
||||
});
|
||||
},
|
||||
};
|
||||
</script>
|
||||
109
src/views/components/InputBoxAdd/index.vue
Normal file
109
src/views/components/InputBoxAdd/index.vue
Normal file
@ -0,0 +1,109 @@
|
||||
<template>
|
||||
<el-form
|
||||
ref="formRef"
|
||||
:model="modelValue"
|
||||
:label-width="`${labelWidth}px`"
|
||||
:disabled="disabled"
|
||||
>
|
||||
<el-row>
|
||||
<el-col :span="24">
|
||||
<el-form-item
|
||||
:label="`${title}:`"
|
||||
:prop="fieldKey"
|
||||
:rules="[
|
||||
{
|
||||
required: true,
|
||||
type: 'array',
|
||||
message: '请输入并添加',
|
||||
trigger: 'change',
|
||||
},
|
||||
]"
|
||||
>
|
||||
<el-row type="flex" justify="space-between">
|
||||
<el-col :span="20">
|
||||
<el-input v-model="dataVal" :placeholder="placeholder"></el-input>
|
||||
</el-col>
|
||||
<el-col :span="3">
|
||||
<el-button type="primary" @click="keyWordAdd">添加</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<div class="e_tag">
|
||||
<el-tag
|
||||
v-for="(tag, index) in modelValue[fieldKey]"
|
||||
:key="index"
|
||||
closable
|
||||
@close="handleFieldClose(fieldKey, index)"
|
||||
>
|
||||
{{ tag }}
|
||||
</el-tag>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form>
|
||||
</template>
|
||||
<script setup name="InputBoxAdd">
|
||||
// import { industry } from "@/api/config";
|
||||
import { ElMessage } from "element-plus";
|
||||
import { ref, toRefs } from "vue";
|
||||
|
||||
const props = defineProps({
|
||||
modelValue: Object,
|
||||
labelWidth: {
|
||||
type: Number,
|
||||
default: 120,
|
||||
},
|
||||
title: {
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
placeholder: {
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
fieldKey: {
|
||||
require: true,
|
||||
type: String,
|
||||
},
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
});
|
||||
|
||||
const { modelValue, title, fieldKey, placeholder, disabled, labelWidth } =
|
||||
toRefs(props);
|
||||
const dataVal = ref("");
|
||||
const formRef = ref(null);
|
||||
const keyWordAdd = () => {
|
||||
if (!dataVal.value.length) return ElMessage.error(`请输入${title.value}`);
|
||||
if (!modelValue.value[fieldKey.value]) modelValue.value[fieldKey.value] = [];
|
||||
modelValue.value[fieldKey.value].push(dataVal.value);
|
||||
dataVal.value = "";
|
||||
};
|
||||
const handleFieldClose = (val, index) => {
|
||||
modelValue.value[val].splice(index, 1);
|
||||
};
|
||||
|
||||
const validateForm = async () => {
|
||||
try {
|
||||
return await formRef.value.validate();
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
defineExpose({
|
||||
validateForm,
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.e_tag {
|
||||
width: 100%;
|
||||
.el-tag {
|
||||
margin-right: 10px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user