DrillPlanExecuteForm.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <div>
  3. <BasicForm ref="basicFormRef" :formData="ruleFormData" :formRules="formRules" :formConfig="ruleFormConfig">
  4. <template #personInChargeName>
  5. <el-select
  6. v-model="ruleFormData.personInChargeName"
  7. placeholder="请输入负责人姓名"
  8. value-key="id"
  9. filterable
  10. remote
  11. :remote-method="remoteMethod"
  12. :loading="loading"
  13. @change="selectKeeper"
  14. >
  15. <el-option
  16. v-for="item in userOptions"
  17. :key="item.id"
  18. :label="`${item.realname}(${item.username})${item.deptName}`"
  19. :value="item"
  20. />
  21. </el-select>
  22. </template>
  23. <template #drillDeptIdList>
  24. <el-cascader
  25. v-model="ruleFormData.drillDeptIdList"
  26. :options="deptTree"
  27. :props="cascaderProp"
  28. clearable
  29. collapse-tags
  30. :show-all-levels="false"
  31. :max-collapse-tags="3"
  32. placeholder="请选择演练部门"
  33. >
  34. </el-cascader>
  35. </template>
  36. <template #drillScript>
  37. <UploadFiles
  38. ref="uploadFilesRef"
  39. label="上传材料"
  40. :fileList="unformatAttachment(props.drillData.drillScript)"
  41. :maxCount="1"
  42. @uploadSuccess="
  43. (files) => {
  44. fileList = files;
  45. ruleFormData.drillScript = files;
  46. }
  47. "
  48. />
  49. </template>
  50. </BasicForm>
  51. </div>
  52. </template>
  53. <script setup lang="ts">
  54. import { onMounted, ref } from 'vue';
  55. import BasicForm from '@/components/BasicForm.vue';
  56. import { useFormConfigHook } from '@/hooks/useFormConfigHook';
  57. import { DrillPlanItemDetail, ExecuteDrillPlanRuleForm } from '../types';
  58. import {
  59. DRILL_EXECUTE_FORM_CONFIG,
  60. INS_DRILL_EXECUTE_FORM_RULES,
  61. DEP_DRILL_EXECUTE_FORM_RULES,
  62. DRILL_EXECUTE_FORM_DATA,
  63. } from '../configs/plan/form';
  64. import { DeptTree } from '@/types/dept/type';
  65. import { getAllDepartments } from '@/api/auth/dept';
  66. import type { QueryUserInfoByUserNameRes } from '@/types/person-group/type';
  67. import { queryUserInfoByUserName } from '@/api/system/person-group';
  68. import UploadFiles from '@/views/disaster/components/UploadFiles.vue';
  69. const props = defineProps<{
  70. insName: string;
  71. drillData: DrillPlanItemDetail;
  72. }>();
  73. const basicFormRef = ref<InstanceType<typeof BasicForm>>();
  74. const { ruleFormConfig, ruleFormData, formRules, cloneRuleFormData, beforeRouteLeave } =
  75. useFormConfigHook<ExecuteDrillPlanRuleForm>(
  76. DRILL_EXECUTE_FORM_CONFIG,
  77. props.drillData
  78. ? {
  79. drillPlanId: props.drillData.id,
  80. drillTime: props.drillData.drillTime,
  81. drillLocation: props.drillData.drillLocation,
  82. personInChargeId: props.drillData.personInChargeId,
  83. personInChargeName: props.drillData.personInChargeName,
  84. drillDeptIdList: stringToArray(props.drillData.drillDeptIdList),
  85. drillScript: props.drillData.drillScript,
  86. }
  87. : DRILL_EXECUTE_FORM_DATA,
  88. props.drillData.drillScope === props.insName ? INS_DRILL_EXECUTE_FORM_RULES : DEP_DRILL_EXECUTE_FORM_RULES,
  89. );
  90. const cascaderProp = {
  91. multiple: true,
  92. expandTrigger: 'hover',
  93. checkStrictly: true,
  94. emitPath: false,
  95. value: 'id',
  96. label: 'deptName',
  97. };
  98. const deptTree = ref<DeptTree[]>();
  99. const loadDeptTreeData = async () => {
  100. const result = await getAllDepartments();
  101. deptTree.value = result[0].children;
  102. };
  103. const userOptions = ref<QueryUserInfoByUserNameRes[]>([]);
  104. const loading = ref<boolean>(false);
  105. const fileList = ref();
  106. fileList.value = unformatAttachment(props.drillData.drillScript);
  107. const remoteMethod = async (query: string) => {
  108. if (!query) {
  109. userOptions.value = [];
  110. return;
  111. }
  112. loading.value = true;
  113. userOptions.value = await queryUserInfoByUserName(query);
  114. loading.value = false;
  115. };
  116. onMounted(() => {
  117. loadDeptTreeData();
  118. });
  119. const formValidate = async () => {
  120. if (!basicFormRef.value) return;
  121. const validateResult = await basicFormRef.value.validateForm();
  122. return validateResult;
  123. };
  124. const formClearValidate = () => {
  125. if (!basicFormRef.value) return;
  126. basicFormRef.value.clearValidate();
  127. };
  128. function getFormData() {
  129. return ruleFormData;
  130. }
  131. defineExpose({
  132. formValidate,
  133. formClearValidate,
  134. getFormData,
  135. });
  136. function selectKeeper(value) {
  137. if (!value) return;
  138. ruleFormData.personInChargeId = value.id;
  139. ruleFormData.personInChargeName = value.realname;
  140. }
  141. function stringToArray(str?: string): number[] | undefined {
  142. if (!str) return undefined;
  143. return JSON.parse(str);
  144. }
  145. function unformatAttachment(file?: string) {
  146. if (!file) return undefined;
  147. const fileData = JSON.parse(file);
  148. return [fileData];
  149. }
  150. </script>
  151. <style scoped></style>