<template>
|
<div class="system-add-user-container">
|
<el-dialog :title="title" v-model="isShowDialog" width="50%">
|
<el-form :model="form" size="default" ref="formRef" :rules="rules" label-width="120px">
|
<el-row :gutter="35">
|
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
|
<el-form-item label="人员" prop="userId">
|
<el-select v-model="form.userId" filterable placeholder="请选择人员" clearable>
|
<el-option v-for="(item,index) in userList" :key="index" :label="item.userName" :value="item.uuid"/>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20" v-if="title == '新增上报'? false : true">
|
<el-form-item label="删除状态" prop="deleted">
|
<el-radio-group v-model="form.deleted">
|
<el-radio :label="0">未删除</el-radio>
|
<el-radio :label="1">已删除</el-radio>
|
</el-radio-group>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
</el-form>
|
<template #footer>
|
<span class="dialog-footer">
|
<el-button @click="isShowDialog = !isShowDialog" size="default">取 消</el-button>
|
<el-button type="primary" v-throttle @click="onSubmit" size="default">确 定</el-button>
|
</span>
|
</template>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script lang="ts">
|
import { reactive, toRefs, onMounted, defineComponent, ref } from 'vue';
|
import { ElMessageBox, ElMessage } from 'element-plus';
|
import axios from "axios";
|
import {workApplyApi} from "/@/api/specialWorkSystem/workApply";
|
import {contractorApi} from "/@/api/dataUpload/contractorManage";
|
|
// 定义接口来定义对象的类型
|
interface DataState {
|
title: string
|
isShowDialog: boolean
|
form: {
|
uuid: string
|
companyCode: string
|
userId: string
|
userName: string
|
contractorId: string
|
contractorName: string
|
deleted: number | null
|
}
|
rules:{}
|
contractorList: []
|
userList: []
|
}
|
|
export default defineComponent({
|
name: 'reportDialog',
|
setup(props, context) {
|
const formRef = ref()
|
const state = reactive<DataState>({
|
title: '',
|
isShowDialog: false,
|
form: {
|
uuid: '',
|
companyCode: '652310082',
|
contractorId: '',
|
contractorName: '',
|
userId: '',
|
userName: '',
|
deleted: 0
|
},
|
rules:{
|
userId: [{ required: true, message: '请选择人员', trigger: 'blur' }]
|
},
|
contractorList: [],
|
userList: []
|
})
|
|
// 页面加载时
|
onMounted(() => {
|
|
})
|
// 打开弹窗
|
const open = (type: string, data: object) => {
|
state.isShowDialog = true
|
getDataList()
|
getUserList()
|
if (type === 'add') {
|
state.title = '新增上报';
|
state.form = {
|
uuid: '',
|
companyCode: '652310082',
|
contractorId: '',
|
contractorName: '',
|
userId: '',
|
userName: '',
|
deleted: 0
|
}
|
}else{
|
state.title = '重新上报'
|
Object.keys(state.form).forEach(key => {
|
if (Object.prototype.hasOwnProperty.call(data,key)) {
|
state.form[key] = JSON.parse(JSON.stringify(data))[key];
|
}
|
})
|
state.form.deleted = Number(data.deleted)
|
// state.form = {
|
// uuid: data.uuid,
|
// companyCode: '652310082',
|
// contractorId: '',
|
// contractorName: '',
|
// userId: '',
|
// userName: '',
|
// deleted: '0'
|
// }
|
}
|
};
|
|
// 新增修改
|
const onSubmit = async () => {
|
formRef.value.validate(async (valid:Boolean) => {
|
if(valid){
|
state.form.contractorId = state.userList.find(i=>i.uuid == state.form.userId)?.contractorId
|
state.form.contractorName = state.contractorList.find(i=>i.uuid == state.form.contractorId)?.contractorName
|
const res = await contractorApi().addContractorEnter([state.form])
|
if(res.data.code == 200){
|
ElMessage({
|
type:'success',
|
message:'数据上报成功'
|
})
|
state.isShowDialog = false
|
}else{
|
ElMessage({
|
type:'warning',
|
message:res.data.msg
|
})
|
}
|
context.emit('refresh');
|
}else{
|
ElMessage({
|
type:'warning',
|
message:'请完善基本信息'
|
})
|
}
|
})
|
}
|
|
const getDataList = async ()=>{
|
const res = await contractorApi().getContractorList({searchParams: {}, pageIndex: 1, pageSize: 999})
|
if(res.data.code == 200){
|
state.contractorList = res.data.data
|
}else{
|
ElMessage({
|
type: 'warning',
|
message: res.data.msg
|
})
|
}
|
}
|
const getUserList = async ()=>{
|
const res = await contractorApi().getContractorUserList({searchParams: {}, pageIndex: 1, pageSize: 999})
|
if(res.data.code == 200){
|
state.userList = res.data.data
|
}else{
|
ElMessage({
|
type: 'warning',
|
message: res.data.msg
|
})
|
}
|
}
|
|
return {
|
formRef,
|
open,
|
onSubmit,
|
...toRefs(state)
|
};
|
}
|
});
|
</script>
|