271 lines
9.2 KiB
Vue
271 lines
9.2 KiB
Vue
<template>
|
|
<div class="edit-popup">
|
|
|
|
<popup ref="popupRef" :title="popupTitle" :async="true" width="550px" @confirm="handleSubmit" @close="handleClose">
|
|
|
|
<el-form ref="formRef" :model="formData" label-width="auto" :rules="formRules">
|
|
<el-row :gutter="10">
|
|
<el-col :span="24">
|
|
<el-form-item label="组织名称" prop="org_id"
|
|
:rules="[{ required: true, message: '不可为空', trigger: 'blur' }]">
|
|
<el-select v-model="formData.org_id" clearable placeholder="请选择组织" @change="deptrmt"
|
|
class="flex-1">
|
|
<el-option v-for="(item, index) in list1" :key="index" :label="item.name"
|
|
:value="item.id" />
|
|
</el-select>
|
|
</el-form-item>
|
|
</el-col>
|
|
|
|
<el-col :span="24">
|
|
<el-form-item label="部门名称" prop="dept_id"
|
|
:rules="[{ required: true, message: '不可为空', trigger: 'blur' }]">
|
|
<el-select v-model="formData.dept_id" clearable placeholder="请选择部门" class="flex-1">
|
|
<el-option v-for="( item, index ) in list2 " :key="index" :label="item.name"
|
|
:value="item.id" />
|
|
</el-select>
|
|
</el-form-item>
|
|
</el-col>
|
|
<el-col :span="24">
|
|
<el-form-item label="项目名称" prop="project_id" @click="showDialog = true">
|
|
<el-input v-model="project_name" clearable placeholder="请输入项目名称" />
|
|
</el-form-item>
|
|
</el-col>
|
|
<el-col :span="24">
|
|
<el-form-item label="项目编码" prop="project_id" @click="showDialog = true">
|
|
<el-input v-model="project_code" clearable placeholder="请输入项目编码" />
|
|
</el-form-item>
|
|
</el-col>
|
|
|
|
<el-col :span="24">
|
|
<el-form-item label="事故名称" prop="name">
|
|
<el-input v-model="formData.name" clearable placeholder="请输入事件名称" />
|
|
</el-form-item>
|
|
</el-col>
|
|
<el-col :span="24">
|
|
<el-form-item label="事故类型" prop="type">
|
|
<el-input v-model="formData.type" clearable placeholder="请输入事故类型" />
|
|
</el-form-item>
|
|
</el-col>
|
|
<el-col :span="24">
|
|
<el-form-item label="发生时间" prop="require">
|
|
<el-date-picker class="flex-1 !flex" v-model="formData.happen_time" clearable type="date"
|
|
value-format="YYYY-MM-DD" placeholder="选择发生时间">
|
|
</el-date-picker>
|
|
</el-form-item>
|
|
</el-col>
|
|
<el-col :span="24">
|
|
<el-form-item label="设备事故" prop="device_accident">
|
|
<el-input v-model="formData.device_accident" clearable placeholder="请输入设备事故" />
|
|
</el-form-item>
|
|
</el-col>
|
|
<el-col :span="24">
|
|
<el-form-item label="承包商人员" prop="contractor_user">
|
|
<el-input v-model="formData.contractor_user_name" @click="userclick('contractor_user')"
|
|
clearable placeholder="请输入承包商人员" />
|
|
</el-form-item>
|
|
</el-col>
|
|
<el-col :span="24">
|
|
<el-form-item label="非本企业人员" prop="our_company_user">
|
|
<el-input v-model="formData.not_our_company_user" clearable placeholder="请输入非本企业人员" />
|
|
</el-form-item>
|
|
</el-col>
|
|
<el-col :span="24">
|
|
<el-form-item label="本企业人员" prop="our_company_user_name">
|
|
<el-input v-model="formData.our_company_user_name" @click="userclick('our_company_user')"
|
|
clearable placeholder="请输入本企业人员" />
|
|
</el-form-item>
|
|
</el-col>
|
|
|
|
<el-col :span="24">
|
|
<el-form-item label="内容" prop="content">
|
|
<el-input v-model="formData.content" type="textarea" clearable placeholder="请输入内容" />
|
|
</el-form-item>
|
|
</el-col>
|
|
|
|
|
|
<el-col :span="24">
|
|
<el-form-item label="备注" prop="remark">
|
|
<el-input v-model="formData.remark" type="textarea" clearable placeholder="请输入备注" />
|
|
</el-form-item>
|
|
</el-col>
|
|
|
|
|
|
<el-col :span="24">
|
|
|
|
<el-form-item label="附件">
|
|
<upload-annex :form-data="formData" value="file"></upload-annex>
|
|
</el-form-item>
|
|
</el-col>
|
|
</el-row>
|
|
|
|
|
|
<el-dialog v-model="showDialog" title="选择项目" width="70%">
|
|
<porjectDialog @customEvent="customEvent"></porjectDialog>
|
|
</el-dialog>
|
|
|
|
<personnelselector ref="personnel" @confirm="submituser" type="1"></personnelselector>
|
|
|
|
</el-form>
|
|
</popup>
|
|
|
|
</div>
|
|
</template>
|
|
|
|
<script lang="ts" setup name="projectEdit">
|
|
import porjectDialog from '@/components/project/index.vue'
|
|
import type { FormInstance } from 'element-plus'
|
|
import Popup from '@/components/popup/index.vue'
|
|
import { safetyaccidentAdd, safetyaccidentEdit, safetyaccidentDetail } from '@/api/safety_accident'
|
|
|
|
import type { PropType } from 'vue'
|
|
import configs from "@/config"
|
|
import useUserStore from "@/stores/modules/user";
|
|
|
|
const userStore = useUserStore();
|
|
const list1 = reactive([])
|
|
const list2 = reactive([])
|
|
const showDialog = ref(false)
|
|
const project_name = ref('')
|
|
const project_code = ref('')
|
|
import { deptAll } from '@/api/org/department'
|
|
import { getAll } from '@/api/org/organization'
|
|
|
|
|
|
defineProps({
|
|
dictData: {
|
|
type: Object as PropType<Record<string, any[]>>,
|
|
default: () => ({})
|
|
}
|
|
})
|
|
const emit = defineEmits(['success', 'close'])
|
|
const formRef = shallowRef<FormInstance>()
|
|
const popupRef = shallowRef<InstanceType<typeof Popup>>()
|
|
const mode = ref('add')
|
|
//获取值
|
|
const customEvent = (e: any) => {
|
|
formData.project_id = e.id;
|
|
project_name.value = e.name;
|
|
project_code.value = e.project_code
|
|
showDialog.value = false;
|
|
};
|
|
|
|
//获取所有组织
|
|
const getlist = () => {
|
|
getAll().then((res) => {
|
|
Object.assign(list1, res)
|
|
|
|
})
|
|
}
|
|
//获取部门
|
|
const deptrmt = (e: any) => {
|
|
formData.dept_id = ''
|
|
getlist1(e)
|
|
|
|
}
|
|
//获取所有部门
|
|
const getlist1 = (id: any) => {
|
|
deptAll({ 'org_id': id }).then((res) => {
|
|
list2.splice(0, list2.length, ...res)
|
|
})
|
|
}
|
|
|
|
// 弹窗标题
|
|
const popupTitle = computed(() => {
|
|
return mode.value == 'edit' ? '编辑安全事故表' : '新增安全事故表'
|
|
})
|
|
|
|
// 表单数据
|
|
const formData = reactive({
|
|
id: '',
|
|
project_id: "",
|
|
name: "",
|
|
happen_time: "",
|
|
type: "",
|
|
file: [],
|
|
remark: "",
|
|
dept_id: '',
|
|
org_id: "",
|
|
device_accident: "",
|
|
contractor_user: "",
|
|
contractor_user_name: "",
|
|
not_our_company_user: "",
|
|
our_company_user: "",
|
|
our_company_user_name: "",
|
|
content: "",
|
|
})
|
|
|
|
const personnel = ref<any>()
|
|
let val = ''
|
|
const userclick = (vals) => {
|
|
val = vals
|
|
personnel.value.open()
|
|
|
|
}
|
|
//确认
|
|
const submituser = (e: any) => {
|
|
formData[val] = e.id;
|
|
formData[val + '_name'] = e.name
|
|
}
|
|
// 表单验证
|
|
const formRules = reactive<any>({
|
|
|
|
})
|
|
|
|
|
|
// 获取详情
|
|
const setFormData = async (data: Record<any, any>) => {
|
|
for (const key in formData) {
|
|
if (data[key] != null && data[key] != undefined) {
|
|
//@ts-ignore
|
|
formData[key] = data[key]
|
|
}
|
|
}
|
|
if (data.dept_id) {
|
|
getlist1(data.dept_id
|
|
)
|
|
}
|
|
project_name.value = data.project_name
|
|
project_code.value = data.project_code
|
|
getlist1(formData.org_id);
|
|
}
|
|
const getDetail = async (row: Record<string, any>) => {
|
|
const data = await safetyaccidentDetail({
|
|
id: row.id
|
|
})
|
|
setFormData(data)
|
|
}
|
|
|
|
|
|
// 提交按钮
|
|
const handleSubmit = async () => {
|
|
await formRef.value?.validate()
|
|
const data = { ...formData }
|
|
mode.value == 'edit'
|
|
? await safetyaccidentEdit(data)
|
|
: await safetyaccidentAdd(data)
|
|
popupRef.value?.close()
|
|
emit('success')
|
|
}
|
|
|
|
//打开弹窗
|
|
const open = (type = 'add') => {
|
|
mode.value = type
|
|
popupRef.value?.open()
|
|
getlist()
|
|
|
|
}
|
|
|
|
// 关闭回调
|
|
const handleClose = () => {
|
|
emit('close')
|
|
}
|
|
|
|
|
|
|
|
defineExpose({
|
|
open,
|
|
setFormData,
|
|
getDetail
|
|
})
|
|
</script>
|