|
@@ -33,9 +33,9 @@
|
|
|
</el-form-item>
|
|
|
<el-form-item label="办公电话:" prop="office_phone">
|
|
|
<div class="phone-input-container">
|
|
|
- <el-input v-model="form.office_phone_prefix" placeholder="例如:0668" style="width: 120px;"></el-input>
|
|
|
+ <el-input v-model="form.office_phone_prefix" placeholder="例如:0668" style="width: 120px"></el-input>
|
|
|
<span class="phone-input-separator">-</span>
|
|
|
- <el-input v-model="form.office_phone_number" placeholder="例如:88888888" style="width: 200px;"></el-input>
|
|
|
+ <el-input v-model="form.office_phone_number" placeholder="例如:88888888" style="width: 200px"></el-input>
|
|
|
</div>
|
|
|
</el-form-item>
|
|
|
<el-form-item label="排位顺序:" prop="order_num">
|
|
@@ -45,27 +45,27 @@
|
|
|
<el-form-item label="选择类别:" prop="category">
|
|
|
<div>
|
|
|
<el-checkbox-group v-model="checkboxGroup2" @change="changeChildType">
|
|
|
- <el-checkbox-button v-for="type in category" :key="type" :value="type" @click="deleteOne(type)">
|
|
|
+ <el-checkbox-button v-for="type in category" :key="type" :value="type" @change="deleteOne(type)">
|
|
|
{{ type.label }}
|
|
|
</el-checkbox-button>
|
|
|
</el-checkbox-group>
|
|
|
- <el-tabs v-model="childType" class="demo-tabs" @tab-click="handleClick">
|
|
|
+ <el-tabs v-model="childType" class="demo-tabs">
|
|
|
<el-tab-pane v-for="item in checkboxGroup2" :label="item.label" :name="item.label">
|
|
|
- <el-checkbox-group v-model="item.checked" @change="getSubOption()">
|
|
|
+ <el-checkbox-group v-model="item.checked" @change="handleFormFormat">
|
|
|
<el-checkbox-button v-for="item2 in item.children" :key="item2.id" :value="item2.id">
|
|
|
{{ item2.label }}
|
|
|
</el-checkbox-button>
|
|
|
</el-checkbox-group>
|
|
|
<div v-if="item.label === '成员单位'">
|
|
|
<span>请填写单位名称:</span>
|
|
|
- <el-input v-model="item.dept_name" style="width: 240px" placeholder="如:茂名供电局" @change="memberUnits" />
|
|
|
+ <el-input v-model="item.dept_name" style="width: 240px" placeholder="如:茂名供电局" @change="handleFormFormat" />
|
|
|
</div>
|
|
|
<div v-if="item.label === '重点部门'">
|
|
|
<span>请填写单位名称:</span>
|
|
|
- <el-input v-model="item.dept_name" style="width: 240px" placeholder="如:茂名市中心小学" @change="memberUnits" />
|
|
|
+ <el-input v-model="item.dept_name" style="width: 240px" placeholder="如:茂名市中心小学" @change="handleFormFormat" />
|
|
|
<div style="display: flex">
|
|
|
<span>请选择责任类别:</span>
|
|
|
- <el-checkbox-group v-model="item.other_type_id" @change="getChOption">
|
|
|
+ <el-checkbox-group v-model="item.other_type_id" @change="handleFormFormat">
|
|
|
<el-checkbox-button v-for="item2 in item.children2" v-if="item.id === '5'" :key="item2" :value="item2.id">
|
|
|
{{ item2.label }}
|
|
|
</el-checkbox-button>
|
|
@@ -74,10 +74,10 @@
|
|
|
</div>
|
|
|
<div v-if="item.label === '水利工程'">
|
|
|
<span>请填写单位名称:</span>
|
|
|
- <el-input v-model="item.dept_name" style="width: 240px" placeholder="如:北江大堰" @change="memberUnits" />
|
|
|
+ <el-input v-model="item.dept_name" style="width: 240px" placeholder="如:北江大堰" @change="handleFormFormat" />
|
|
|
<div style="display: flex">
|
|
|
<span v-if="item.label === '水利工程'">请选择责任类别:</span>
|
|
|
- <el-checkbox-group v-model="item.other_type_id" @change="getChOption">
|
|
|
+ <el-checkbox-group v-model="item.other_type_id" @change="handleFormFormat">
|
|
|
<el-checkbox-button v-for="item2 in item.children2" v-if="item.id === '7'" :key="item2" :value="item2.id">
|
|
|
{{ item2.label }}
|
|
|
</el-checkbox-button>
|
|
@@ -86,7 +86,7 @@
|
|
|
</div>
|
|
|
<div v-if="item.label === '抢险队伍'" style="display: flex">
|
|
|
<span>请选择责任类别:</span>
|
|
|
- <el-checkbox-group v-model="item.other_type_id" @change="getChOption">
|
|
|
+ <el-checkbox-group v-model="item.other_type_id" @change="handleFormFormat">
|
|
|
<el-checkbox-button v-for="item2 in item.children2" v-if="item.id === '9'" :key="item2" :value="item2.id">
|
|
|
{{ item2.label }}
|
|
|
</el-checkbox-button>
|
|
@@ -94,7 +94,7 @@
|
|
|
</div>
|
|
|
<div v-if="item.label === '地质灾害'">
|
|
|
<span>请填写隐患点名称:</span>
|
|
|
- <el-input v-model="item.denger_point_name" style="width: 240px" placeholder="" @change="memberUnits" />
|
|
|
+ <el-input v-model="item.denger_point_name" style="width: 240px" placeholder="" @change="handleFormFormat" />
|
|
|
</div>
|
|
|
<div v-if="item.label === '其他'">
|
|
|
<span>请填写具体类型:</span>
|
|
@@ -102,7 +102,7 @@
|
|
|
v-model="item.other_type_2_name"
|
|
|
style="width: 240px"
|
|
|
placeholder="请填写责任类型,如:重点单位等"
|
|
|
- @change="memberUnits"
|
|
|
+ @change="handleFormFormat"
|
|
|
/>
|
|
|
</div>
|
|
|
</el-tab-pane>
|
|
@@ -122,7 +122,8 @@
|
|
|
<script setup lang="ts">
|
|
|
import { ref, toRefs } from 'vue';
|
|
|
import type { TabsPaneContext } from 'element-plus';
|
|
|
-import { createNewPerson, getPersonRespon, getZoning, responsibleDetail } from '@/api/PreventionResponsible';
|
|
|
+import { createNewPerson, getPersonRespon, getZoning, responsibleDetail, updateData } from '@/api/PreventionResponsible';
|
|
|
+import { deepClone } from '@/utils';
|
|
|
|
|
|
const category = ref([]);
|
|
|
const checkboxGroup2 = ref([]);
|
|
@@ -173,6 +174,7 @@ const getOptions2 = () => {
|
|
|
data3.value = '';
|
|
|
form.value.area_code = undefined;
|
|
|
options2.value = undefined;
|
|
|
+ options3.value = undefined;
|
|
|
return;
|
|
|
} else {
|
|
|
getZoning(data1.value).then((res) => {
|
|
@@ -202,15 +204,6 @@ const getAreaContent = () => {
|
|
|
form.value.area_code = data3.value;
|
|
|
}
|
|
|
};
|
|
|
-watch(data1, () => {
|
|
|
- data2.value = '';
|
|
|
- data3.value = '';
|
|
|
- options2.value = undefined;
|
|
|
-});
|
|
|
-watch(data2, () => {
|
|
|
- data3.value = '';
|
|
|
- options3.value = undefined;
|
|
|
-});
|
|
|
const getCategory = () => {
|
|
|
getPersonRespon().then((res) => {
|
|
|
category.value = res.rows;
|
|
@@ -223,151 +216,90 @@ const changeChildType = () => {
|
|
|
let index = checkboxGroup2.value.findIndex((item2) => item2.id === item.id);
|
|
|
if (index === -1) {
|
|
|
delete item.checked;
|
|
|
+ delete item.other_type_id;
|
|
|
+ handleDeleteAttribute(item);
|
|
|
}
|
|
|
});
|
|
|
- childType.value = checkboxGroup2.value[checkboxGroup2.value.length - 1].label;
|
|
|
-};
|
|
|
-
|
|
|
-const getSubOption = () => {
|
|
|
- const obj = {
|
|
|
- type_parent_id: '',
|
|
|
- children: ''
|
|
|
- };
|
|
|
- for (let i = 0; i < checkboxGroup2.value.length; i++) {
|
|
|
- obj.type_parent_id = checkboxGroup2.value[i].id;
|
|
|
- obj.children = checkboxGroup2.value[i].checked;
|
|
|
- form.value.type_list[i] = obj;
|
|
|
- }
|
|
|
-};
|
|
|
-const memberUnits = () => {
|
|
|
- let datatemp = [];
|
|
|
- for (let i = 0; i < checkboxGroup2.value.length; i++) {
|
|
|
- if (!!checkboxGroup2.value[i] && checkboxGroup2.value[i].children.length > 0) {
|
|
|
- const obj = {
|
|
|
- type_parent_id: checkboxGroup2.value[i].id,
|
|
|
- children: checkboxGroup2.value[i].checked
|
|
|
- };
|
|
|
- if (['4', '5', '7'].includes(checkboxGroup2.value[i].id) && checkboxGroup2.value[i].dept_name) {
|
|
|
- //成员单位
|
|
|
- obj.dept_name = checkboxGroup2.value[i].dept_name;
|
|
|
- } else if (checkboxGroup2.value[i].id === '10' && checkboxGroup2.value[i].denger_point_name) {
|
|
|
- //地质灾害
|
|
|
- obj.denger_point_name = checkboxGroup2.value[i].denger_point_name;
|
|
|
- } else if (checkboxGroup2.value[i].id === '11' && checkboxGroup2.value[i].other_type_2_name) {
|
|
|
- //其他
|
|
|
- obj.other_type_2_name = checkboxGroup2.value[i].other_type_2_name;
|
|
|
- }
|
|
|
- datatemp.push(obj);
|
|
|
- }
|
|
|
- }
|
|
|
- form.value.type_list = datatemp;
|
|
|
+ childType.value = checkboxGroup2.value.length ? checkboxGroup2.value[checkboxGroup2.value.length - 1].label : '';
|
|
|
};
|
|
|
|
|
|
const deleteOne = (type) => {
|
|
|
- const index = form.value.type_list.findIndex((item) => item.type_parent_id === type.id);
|
|
|
+ const index = form.value.type_list.findIndex((item) => item.id === type.id);
|
|
|
if (index !== -1) {
|
|
|
form.value.type_list.splice(index, 1);
|
|
|
+ if (!!type.dept_name) {
|
|
|
+ delete type.dept_name;
|
|
|
+ }
|
|
|
+ if (!!type.denger_point_name) {
|
|
|
+ delete type.denger_point_name;
|
|
|
+ }
|
|
|
+ if (!!type.other_type_2_name) {
|
|
|
+ delete type.other_type_2_name;
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
-const getChOption = () => {
|
|
|
- debugger;
|
|
|
- let datatemp = [];
|
|
|
+const handleFormFormat = () => {
|
|
|
+ const data = [];
|
|
|
for (let i = 0; i < checkboxGroup2.value.length; i++) {
|
|
|
- if (!!checkboxGroup2.value[i] && checkboxGroup2.value[i].other_type_id.length > 0) {
|
|
|
- const obj = {
|
|
|
- type_parent_id: checkboxGroup2.value[i].id,
|
|
|
- other_type_id: checkboxGroup2.value[i].other_type_id
|
|
|
- };
|
|
|
- datatemp.push(obj);
|
|
|
+ if (!checkboxGroup2.value[i].checked || checkboxGroup2.value[i].checked.length === 0) {
|
|
|
+ continue;
|
|
|
}
|
|
|
+ let obj = deepClone(checkboxGroup2.value[i]);
|
|
|
+ obj.type_parent_id = obj.id;
|
|
|
+ delete obj.id;
|
|
|
+ if (obj.checked && obj.checked.length > 0) {
|
|
|
+ obj.children = obj.checked;
|
|
|
+ delete obj.checked;
|
|
|
+ } else {
|
|
|
+ delete obj.children;
|
|
|
+ }
|
|
|
+ if (obj.other_type_id && obj.other_type_id.length > 0) {
|
|
|
+ obj.children2 = obj.other_type_id;
|
|
|
+ delete obj.other_type_id;
|
|
|
+ } else {
|
|
|
+ delete obj.children2;
|
|
|
+ }
|
|
|
+ data.push(obj);
|
|
|
}
|
|
|
- form.value.type_list = datatemp;
|
|
|
-};
|
|
|
-const handleClick = (tab: TabsPaneContext, event: Event) => {
|
|
|
- console.log(tab, event);
|
|
|
+ form.value.type_list = data;
|
|
|
};
|
|
|
+
|
|
|
const personType = ref([]);
|
|
|
for (const i in category.value) {
|
|
|
personType.value.push(category.value[i].label);
|
|
|
}
|
|
|
|
|
|
-const submitNewPerson = async () => {
|
|
|
- // 打印当前表单值用于调试
|
|
|
- console.log('Form values before submit:', form.value);
|
|
|
-
|
|
|
- // 验证表单
|
|
|
- try {
|
|
|
- if (!formRef.value) {
|
|
|
- throw new Error('Form reference is not set');
|
|
|
- }
|
|
|
+const handleDeleteAttribute = (obj) => {
|
|
|
+ if (!['4', '5', '7'].includes(obj.id)) {
|
|
|
+ delete obj.dept_name;
|
|
|
+ }
|
|
|
+ if (obj.id !== '10') {
|
|
|
+ delete obj.denger_point_name;
|
|
|
+ }
|
|
|
+ if (obj.id !== '11') {
|
|
|
+ delete obj.other_type_2_name;
|
|
|
+ }
|
|
|
+};
|
|
|
|
|
|
- const valid = await formRef.value.validate((valid, invalidFields) => {
|
|
|
- if (!valid) {
|
|
|
- console.error('Validation failed:', invalidFields); // 输出未通过验证的字段
|
|
|
+const submitNewPerson = async () => {
|
|
|
+ await formRef.value.validate((valid) => {
|
|
|
+ if (valid) {
|
|
|
+ buttonLoading.value = true; // 开始加载状态
|
|
|
+ const data = deepClone(form.value);
|
|
|
+ if (!data.order_num) {
|
|
|
+ data.order_num = -1;
|
|
|
}
|
|
|
- return valid;
|
|
|
- });
|
|
|
-
|
|
|
- if (!valid) {
|
|
|
- proxy.$modal.msgError('请检查输入信息');
|
|
|
- return;
|
|
|
+ createNewPerson(data).then((res) => {
|
|
|
+ proxy.$modal.msgSuccess('新增成功');
|
|
|
+ emits('close');
|
|
|
+ }).finally(() => {
|
|
|
+ buttonLoading.value = false; // 结束加载状态
|
|
|
+ });
|
|
|
}
|
|
|
- } catch (error) {
|
|
|
- console.error('Validation error:', error);
|
|
|
- proxy.$modal.msgError('请检查输入信息');
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // 构建请求体
|
|
|
- const requestBody = {
|
|
|
- unit_name: form.value.unit_name,
|
|
|
- name: form.value.name,
|
|
|
- area_code: form.value.area_code,
|
|
|
- position: form.value.position,
|
|
|
- phone: form.value.phone,
|
|
|
- order_num: form.value.order_num,
|
|
|
- telephone: `${form.value.office_phone_prefix}-${form.value.office_phone_number}`,
|
|
|
- type_list: checkboxGroup2.value
|
|
|
- .map((item) => ({
|
|
|
- type_parent_id: item.id,
|
|
|
- children: item.checked || [],
|
|
|
- dept_name: item.dept_name || null,
|
|
|
- other_type_2_name: item.other_type_2_name || null,
|
|
|
- denger_point_name: item.denger_point_name || null
|
|
|
- }))
|
|
|
- .filter((item) => Object.values(item).some((val) => val !== null && val !== undefined))
|
|
|
- };
|
|
|
-
|
|
|
- buttonLoading.value = true; // 开始加载状态
|
|
|
-
|
|
|
- try {
|
|
|
- // 发送请求
|
|
|
- await createNewPerson(requestBody);
|
|
|
- proxy.$modal.msgSuccess('新增成功');
|
|
|
- emits('close', true); // 关闭对话框并通知父组件
|
|
|
- emits('refresh');
|
|
|
- } catch (error) {
|
|
|
- console.error('Error creating new person:', error);
|
|
|
- proxy.$modal.msgError('新增失败,请稍后再试或联系管理员');
|
|
|
- } finally {
|
|
|
- buttonLoading.value = false; // 结束加载状态
|
|
|
- }
|
|
|
+ });
|
|
|
};
|
|
|
|
|
|
onMounted(() => {
|
|
|
- if (props.id) {
|
|
|
- responsibleDetail(props.id).then((res) => {
|
|
|
- Object.assign(form.value, res.data);
|
|
|
- // 如果有特殊情况处理,如将API返回的类型列表转换为checkboxGroup2的格式
|
|
|
- checkboxGroup2.value = res.data.type_list.map((item) => ({
|
|
|
- id: item.type_parent_id,
|
|
|
- checked: item.children || [],
|
|
|
- dept_name: item.dept_name,
|
|
|
- other_type_2_name: item.other_type_2_name,
|
|
|
- denger_point_name: item.denger_point_name
|
|
|
- }));
|
|
|
- });
|
|
|
- }
|
|
|
getOptions1(2);
|
|
|
getCategory();
|
|
|
});
|