DrillPlanExecuteItem.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <div v-if="drillData">
  3. <div class="drill-activity-container">
  4. <div class="drill-container__title">
  5. <div class="drill-container--line"></div>
  6. <span>演练活动</span>
  7. </div>
  8. <div class="drill-container__content">
  9. <el-row :gutter="20">
  10. <el-col :span="8">
  11. <div class="drill-container__content--item">
  12. <span class="label">演练规模:</span>
  13. <span class="value">{{ getDrillScope(drillData.drillScope) }}</span>
  14. </div>
  15. </el-col>
  16. <el-col :span="8">
  17. <div class="drill-container__content--item">
  18. <span class="label">演练内容:</span>
  19. <span class="value">{{ drillData.drillContent }}</span>
  20. </div>
  21. </el-col>
  22. <el-col :span="8">
  23. <div class="drill-container__content--item">
  24. <span class="label">计划完成时间:</span>
  25. <span class="value">{{ drillData.dueCompleteTime }}</span>
  26. </div>
  27. </el-col>
  28. </el-row>
  29. <el-row :gutter="20">
  30. <el-col :span="8">
  31. <div class="drill-container__content--item">
  32. <div>
  33. <span class="label">责任部门:</span>
  34. <template v-for="(dept, index) in safatyJsonParse(drillData.responsibleDeptNameList)" :key="index">
  35. <span class="value">
  36. {{ dept }}
  37. <span v-if="index !== safatyJsonParse(drillData.responsibleDeptNameList).length - 1">、</span>
  38. </span>
  39. </template>
  40. </div>
  41. </div>
  42. </el-col>
  43. <el-col :span="8">
  44. <div class="drill-container__content--item">
  45. <div>
  46. <span class="label">配合部门:</span>
  47. <template
  48. v-if="drillData.coordinateDeptNameList"
  49. v-for="(dept, index) in safatyJsonParse(drillData.coordinateDeptNameList)"
  50. :key="index"
  51. >
  52. <span class="value">
  53. {{ dept }}
  54. <span v-if="index !== safatyJsonParse(drillData.coordinateDeptNameList).length - 1">、</span>
  55. </span>
  56. </template>
  57. </div>
  58. </div>
  59. </el-col>
  60. <el-col :span="8">
  61. <div class="drill-container__content--item">
  62. <span class="label">关联应急预案:</span>
  63. <a v-if="emergencyPlanDetail" class="value font-primary" :href="emergencyPlanDetail.appendix">{{
  64. emergencyPlanDetail.planName
  65. }}</a>
  66. </div>
  67. </el-col>
  68. </el-row>
  69. <el-row :gutter="20">
  70. <el-col>
  71. <div class="drill-container__content--item">
  72. <span class="label">审批流程:</span>
  73. <span class="value">{{ getApprovalName(drillData.approvalTemplateId) }}</span>
  74. </div>
  75. </el-col>
  76. </el-row>
  77. </div>
  78. </div>
  79. <div class="drill-execute-form">
  80. <div class="drill-container__title">
  81. <div class="drill-container--line"></div>
  82. <span>演练实施</span>
  83. </div>
  84. <DrillPlanExecuteForm
  85. v-if="drillData"
  86. ref="drillPlanExecuteFormRef"
  87. :ins-name="drillScopeDice[0].itemCode"
  88. :drill-data="drillData"
  89. style="margin-top: 20px"
  90. />
  91. </div>
  92. </div>
  93. </template>
  94. <script setup lang="ts">
  95. import { ref, onMounted } from 'vue';
  96. import { ElMessage } from 'element-plus';
  97. import { useRoute } from 'vue-router';
  98. import { DrillPlanItemDetail } from '../types';
  99. import DrillPlanExecuteForm from './DrillPlanExecuteForm.vue';
  100. import {
  101. queryEmergencyDrillPlanDetail,
  102. queryEmergencyPlanDetail,
  103. saveEmergencyDrillExecute,
  104. submitEmergencyDrillExecute,
  105. } from '@/api/emergency-drill/emergency-drill';
  106. import { getAllApproval } from '@/api/approval/approval';
  107. import type { FileItem } from '@/views/disaster/types';
  108. import { uploadFileApi, UPLOAD_BIZ_TYPE } from '@/api/minio';
  109. import { useEmergencyDrillHook } from '../hook';
  110. const route = useRoute();
  111. const id = route.query.id;
  112. const approvalList = ref();
  113. const emergencyPlanDetail = ref();
  114. const drillData = ref<DrillPlanItemDetail>();
  115. const { drillScopeDice, getDrillScopeDict, getDrillScope } = useEmergencyDrillHook();
  116. const getApprovalList = async () => {
  117. approvalList.value = await getAllApproval();
  118. };
  119. async function getDrillData() {
  120. try {
  121. drillData.value = await queryEmergencyDrillPlanDetail(id);
  122. // 获取应急预案名
  123. if (drillData.value.emergencyPlanId) {
  124. emergencyPlanDetail.value = await queryEmergencyPlanDetail(id);
  125. }
  126. } catch (e) {
  127. console.log(e);
  128. }
  129. }
  130. onMounted(async () => {
  131. await getApprovalList();
  132. await getDrillScopeDict();
  133. getDrillData();
  134. });
  135. const getApprovalName = (id: number) => {
  136. return approvalList.value.find((item) => item.id === id)?.templateName;
  137. };
  138. const safatyJsonParse = (str: string) => {
  139. return str.slice(1, -1).split(',');
  140. };
  141. const drillPlanExecuteFormRef = ref();
  142. const formatAttachmentList = async (data: FileItem[]) => {
  143. if (!data || data.length === 0) return null;
  144. const file = data[0];
  145. if (!file.file) return file;
  146. const fileName = file.fileName;
  147. const res = await uploadFileApi({ bizType: UPLOAD_BIZ_TYPE.ATTACHMENT, fileName, file: file.file });
  148. const fileType = file.fileType;
  149. const fileSize = file.fileSize;
  150. const fileId = file.fileId;
  151. const fileUrl = res.url;
  152. return {
  153. fileName,
  154. fileType,
  155. fileSize,
  156. fileUrl,
  157. fileId,
  158. };
  159. };
  160. async function executeSaveOrSubmit(mode: string) {
  161. if (!drillPlanExecuteFormRef.value) return;
  162. // drillPlanExecuteFormRef.value.handleClearValidate();
  163. if (mode === 'submit') {
  164. const res = await drillPlanExecuteFormRef.value.formValidate();
  165. if (!res) return;
  166. }
  167. const formData = drillPlanExecuteFormRef.value.getFormData();
  168. let attachmentListRes;
  169. if (typeof formData.drillScript === 'string') {
  170. attachmentListRes = formData.drillScript;
  171. } else if (!formData.drillScript || formData.drillScript.length === 0) {
  172. attachmentListRes = '';
  173. } else {
  174. attachmentListRes = JSON.stringify(await formatAttachmentList(formData.drillScript));
  175. }
  176. const executeParams = {
  177. drillPlanId: formData.drillPlanId,
  178. drillTime: formData.drillTime,
  179. drillLocation: formData.drillLocation,
  180. personInChargeId: formData.personInChargeId,
  181. drillDeptIdList: formData.drillDeptIdList,
  182. drillScript: attachmentListRes,
  183. };
  184. if (mode === 'save') {
  185. try {
  186. await saveEmergencyDrillExecute(executeParams);
  187. ElMessage.success('保存成功');
  188. drillPlanExecuteFormRef.value.formClearValidate();
  189. drillData.value = undefined;
  190. getDrillData();
  191. } catch (e) {
  192. console.log(e);
  193. ElMessage.error('保存失败');
  194. }
  195. } else {
  196. try {
  197. await submitEmergencyDrillExecute(executeParams);
  198. ElMessage.success('提交成功');
  199. drillPlanExecuteFormRef.value.formClearValidate();
  200. drillData.value = undefined;
  201. getDrillData();
  202. } catch (e) {
  203. console.log(e);
  204. ElMessage.error('提交失败');
  205. }
  206. }
  207. }
  208. defineExpose({
  209. executeSaveOrSubmit,
  210. });
  211. </script>
  212. <style scoped lang="scss">
  213. @use '../style/common.scss' as *;
  214. </style>