马宇豪
2023-08-07 7ed4982b8f2a345bfad95a96070143c32142bc61
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<template>
    <div class="system-menu-dialog-container">
        <el-dialog title="管理实验现实风险" v-model="assessApplyDialogState.assessApplyDialogVisible" width="60%">
          <div>
            <el-button @click="openUnitDialog('新增','', assessApplyDialogState.id)" type="primary" style="margin-bottom: 20px" size="default">增加风险分析单元</el-button>
          </div>
          <el-table ref="multipleTableRef" :data="assessApplyDialogState.riskUnitData" style="width: 100%" :header-cell-style="{ background: '#fafafa' }">
            <el-table-column prop="riskCode" label="风险单元编号"/>
            <el-table-column prop="riskName" label="风险单元名称"/>
            <el-table-column prop="riskType" label="风险类型">
              <template #default="scope">
                <span>{{`${assessApplyDialogState.riskList.find(item =>item.id === scope.row.riskType)?.name || ''}`}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="riskUnitType" label="风险单元类型"/>
            <el-table-column prop="riskUnitType" label="负责人">
              <template #default="scope">
                <span>{{`${assessApplyDialogState.allPersonList.find(item =>item.id === scope.row.liabilityUserId)?.personName || ''}`}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="evaluateStatus" label="是否评价">
              <template #default="scope">
                <span>{{scope.row.evaluateStatus == 1?'未评价':scope.row.evaluateStatus == 2?'已评价':'--'}}</span>
              </template>
            </el-table-column>
            <el-table-column label="操作" width="150" align="center">
              <template #default="scope">
                <el-button size="default" text  type="primary" @click="openUnitDialog('查看', scope.row, assessApplyDialogState.id)">查看</el-button>
                <el-button size="default" text  type="primary" @click="openUnitDialog('编辑', scope.row, assessApplyDialogState.id)">编辑</el-button>
                <el-button size="default" text type="danger" @click="deleteUnit(scope.$index, scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <template #footer>
            <span class="dialog-footer">
              <el-button @click="assessApplyDialogState.assessApplyDialogVisible = !assessApplyDialogState.assessApplyDialogVisible" type="primary" size="default">确定</el-button>
            </span>
          </template>
          <risk-unit-dialog ref="riskUnitDialogRef" @refresh="getRiskData"></risk-unit-dialog>
        </el-dialog>
    </div>
</template>
 
<script setup lang="ts">
import {defineAsyncComponent, onMounted, reactive, ref} from "vue";
import {ElMessage} from "element-plus";
import {projectApi} from "/@/api/experiment/project";
import {personApi} from "/@/api/basic/person";
import {riskUnitApi} from "/@/api/analyse/riskUnit";
import {unitApi} from "/@/api/basic/unit";
import {userApi} from "/@/api/systemManage/user";
import {ElMessageBox} from "element-plus/es";
import {identifyApi} from "/@/api/analyse/identify";
const RiskUnitDialog = defineAsyncComponent(() => import('./riskUnitDialog.vue'));
 
const assessApplyDialogState = reactive<AssessApplyDialogStateType>({
    title: '',
    riskUnitData: [],
    assessApplyDialogVisible: false,
    id: null,
    liabilityUserId: null,
    riskList: [
      {id: 1, name: '固有风险'},
      {id:2, name: '实验风险'}
    ],
    basicUnitList: [],
    allPersonList: [],
    allRiskTypeList: []
})
 
const riskUnitDialogRef = ref()
 
const showRiskDialog = (value: ProjectType) => {
    assessApplyDialogState.assessApplyDialogVisible = true;
    assessApplyDialogState.id = <number>value.id
    assessApplyDialogState.liabilityUserId = <number>value.liabilityUserId
    getRiskData()
};
 
const openUnitDialog = (title: string, val, id: number) => {
  riskUnitDialogRef.value.showRiskUnitDialog(title, val, id, assessApplyDialogState.basicUnitList, assessApplyDialogState.allPersonList, assessApplyDialogState.allRiskTypeList);
};
 
const getRiskData = async () => {
  let res = await riskUnitApi().getRiskUnitByList({pageIndex: 1,pageSize: 9999,riskCode: '',riskName: '',experimentId: assessApplyDialogState.id});
  if(res.data.code === 100){
    assessApplyDialogState.riskUnitData = JSON.parse(JSON.stringify(res.data.data));
  }else{
    ElMessage({
      type: 'warning',
      message: res.data.msg
    })
  }
};
 
const getAllBasicUnitList = async () => {
  let res = await unitApi().getAllUnit();
  if(res.data.code === 100){
    assessApplyDialogState.basicUnitList = JSON.parse(JSON.stringify(res.data.data));
  }else{
    ElMessage({
      type: 'warning',
      message: res.data.msg
    })
  }
};
 
const getAllPersonList = async () => {
  let res = await personApi().getAllPerson();
  if(res.data.code === 100){
    assessApplyDialogState.allPersonList = JSON.parse(JSON.stringify(res.data.data));
  }else{
    ElMessage({
      type: 'warning',
      message: res.data.msg
    })
  }
};
 
const getAllTypeList = async () =>{
  let res = await unitApi().getAllUnitType()
  if(res.data.code === 100){
    assessApplyDialogState.allRiskTypeList = JSON.parse(JSON.stringify(res.data.data));
  }else{
    ElMessage({
      type: 'warning',
      message: res.data.msg
    })
  }
}
 
const deleteUnit = (index: number, val: IdentifyType) => {
  ElMessageBox.confirm(`此操作将永久删除该风险单元,是否继续?`, '提示', {
    confirmButtonText: '确认',
    cancelButtonText: '取消',
    type: 'warning'
  })
      .then(async () => {
        let data = { id: val.id }
        let res = await unitApi().deleteRiskUnitById(data);
        if (res.data.code === 100) {
          (<Array<IdentifyType>>assessApplyDialogState.riskUnitData).splice(index, 1)
          ElMessage({
            type: 'success',
            duration: 2000,
            message: '删除成功'
          });
        } else {
          ElMessage({
            type: 'warning',
            message: res.data.msg
          });
        }
      })
      .catch((error) => {
        console.log(error);
      });
};
 
const emit = defineEmits(['refresh'])
 
defineExpose({
    showRiskDialog
})
 
onMounted(() => {
  getAllBasicUnitList()
  getAllPersonList()
  getAllTypeList()
})
</script>
 
<style scoped>
 
</style>