DocRecord.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <div class="ya_bar">
  3. <h3>预案内容</h3>
  4. <div>
  5. <el-button type="primary" @click="importDoc()"> 导入预案 </el-button>
  6. <el-button type="info" plain icon="Download" @click="handleTemplate">下载导入模板</el-button>
  7. </div>
  8. </div>
  9. <el-card v-show="doc_items.length > 0" shadow="hover">
  10. <el-tabs v-model="activeName" type="border-card" class="demo-tabs" @tab-click="handleClick2">
  11. <el-tab-pane v-for="(item, index) in doc_items" :key="index" :label="item.title" :name="item.id">
  12. <div>
  13. <el-row>
  14. <el-col :span="4">
  15. <el-anchor :container="'#content' + index" direction="vertical" type="default" :offset="1" @click="handleClick1">
  16. <el-anchor-link
  17. v-for="(sub_item, index2) in item.items"
  18. :key="index2"
  19. :href="sub_item.href"
  20. :title="sub_item.title"
  21. :name="sub_item.id"
  22. />
  23. </el-anchor>
  24. </el-col>
  25. <el-col :span="20">
  26. <div :id="'content' + index" style="height: 400px; overflow-y: auto">
  27. <div v-for="(sub_item, index3) in item.items" :id="sub_item.id" :key="index3" style="height: auto; margin-top: 15px; font-size: 14px">
  28. <h3 style="font-weight: 600">{{ sub_item.title }}</h3>
  29. <span v-html="sub_item.value"></span>
  30. </div>
  31. </div>
  32. </el-col>
  33. </el-row>
  34. </div>
  35. </el-tab-pane>
  36. </el-tabs>
  37. </el-card>
  38. <el-dialog ref="formDialogRef" v-model="showImportDlg" title="导入结构化文档" width="500px" append-to-body>
  39. <el-form ref="formRef" :model="form" :rules="rules">
  40. <FileUpload v-model="form.filename" :file-type="['xls', 'xlsx']" :limit="1" />
  41. </el-form>
  42. <template #footer>
  43. <div class="dialog-footer">
  44. <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
  45. <el-button @click="cancel">取 消</el-button>
  46. </div>
  47. </template>
  48. </el-dialog>
  49. </template>
  50. <script setup lang="ts">
  51. import { ref } from 'vue';
  52. import type { TabsPaneContext } from 'element-plus';
  53. import { getDoc, importDocXls } from '@/api/riskPrevention/planManage';
  54. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  55. // const containerRef = ref<HTMLElement | null>(null);
  56. const doc_items = ref([]);
  57. const props = defineProps({
  58. id: String
  59. });
  60. watch(
  61. () => props.id,
  62. () => {
  63. if (props.id) {
  64. getData();
  65. }
  66. },
  67. {
  68. immediate: true
  69. }
  70. );
  71. const handleClick1 = (e: MouseEvent) => {
  72. e.preventDefault();
  73. };
  74. const activeName = ref('first');
  75. const handleClick2 = (tab: TabsPaneContext, event: Event) => {
  76. // console.log(tab, event);
  77. };
  78. const getData = () => {
  79. getDoc({ plan_id: props.id }).then((res) => {
  80. doc_items.value = res.data;
  81. if (doc_items.value.length > 0) {
  82. activeName.value = doc_items.value[0].id;
  83. }
  84. });
  85. };
  86. const baseUrl = import.meta.env.VITE_APP_BASE_API;
  87. const downLoadApi = import.meta.env.VITE_APP_BASE_DOWNLOAD_API;
  88. const showImportDlg = ref(false);
  89. const formDialogRef = ref(null);
  90. const formRef = ref<ElFormInstance>();
  91. const buttonLoading = ref(false);
  92. const form = ref({
  93. filename: ''
  94. });
  95. const rules = reactive({
  96. filename: [{ required: true, message: '导入文件不能为空', trigger: 'blur' }]
  97. });
  98. const importDoc = () => {
  99. resetForm();
  100. showImportDlg.value = true;
  101. };
  102. const resetForm = () => {
  103. form.value = {
  104. filename: ''
  105. };
  106. formRef.value?.resetFields();
  107. formRef.value?.clearValidate();
  108. };
  109. /**提交按钮 */
  110. const submitForm = () => {
  111. formRef.value?.validate(async (valid) => {
  112. if (valid) {
  113. try {
  114. buttonLoading.value = true;
  115. await importDocXls({ ...form.value, plan_id: props.id });
  116. proxy?.$modal.msgSuccess('导入成功');
  117. showImportDlg.value = false;
  118. getData();
  119. } finally {
  120. buttonLoading.value = false;
  121. }
  122. }
  123. });
  124. };
  125. /** 取消按钮 */
  126. const cancel = () => {
  127. resetForm();
  128. showImportDlg.value = false;
  129. };
  130. const handleTemplate = async () => {
  131. location.href = baseUrl + downLoadApi + 'yjya_doc_import.xlsx';
  132. };
  133. </script>
  134. <style lang="scss" scoped>
  135. .ya_bar {
  136. display: flex;
  137. flex-direction: row;
  138. flex-wrap: nowrap;
  139. justify-content: space-between;
  140. align-items: center;
  141. }
  142. .demo-tabs > .el-tabs__content {
  143. padding: 32px;
  144. color: #6b778c;
  145. font-size: 32px;
  146. font-weight: 600;
  147. }
  148. </style>