fileDialog.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <el-dialog v-model="visible" :width="width" append-to-body draggable show-close :close-on-click-modal="false">
  3. <template #header>
  4. <div class="dialog-title-container">
  5. <span class="title-label" style="color: #fff;">
  6. <el-icon>
  7. <Document />
  8. </el-icon> 附件信息</span>
  9. <!-- <el-icon @click="close">
  10. <Close />
  11. </el-icon> -->
  12. </div>
  13. </template>
  14. <div class="dialog-list-container">
  15. <!-- <img style="height: 148px; width: 148px" :src="`${baseUrl}/${form}`" class="avatar"
  16. @click="openEvidience('form')" /> -->
  17. <el-table ref="dbTable" :data="list" size="small" border header-row-class-name="list-header-row"
  18. row-class-name="list-row" @selection-change="handleSelectionChange">
  19. <el-table-column type="selection" width="40" align="center" />
  20. <el-table-column type="index" label="序号" width="46" align="center" />
  21. <el-table-column label="文件名" prop="originalFileName" align="center" show-overflow-tooltip>
  22. <template #default="scope">
  23. <el-button size="small" type="primary" link @click="openFile(scope.row)">{{
  24. scope.row.originalFileName
  25. }}</el-button>
  26. </template>
  27. </el-table-column>
  28. </el-table>
  29. <div style="display: flex; justify-content: space-between; margin-top: 10px;margin-bottom: 10px;">
  30. <div>
  31. 补传文件
  32. </div>
  33. <div>
  34. <el-upload action="#" :http-request="upload" :with-credentials="true" :show-file-list="false"
  35. multiple>
  36. <el-button size="small" type="primary" icon="Upload">点击上传</el-button>
  37. </el-upload>
  38. </div>
  39. </div>
  40. <el-table ref="filesTable" :data="supplementList" size="small" border
  41. header-row-class-name="list-header-row">
  42. <el-table-column type="index" label="序号" width="47" align="center" />
  43. <el-table-column label="文件名" prop="originalFileName" align="center">
  44. <template #default="scope">
  45. <el-link :href="`${baseUrl}${scope.row.fileUrl}`" :underline="false" target="_blank"
  46. type="primary">
  47. {{ scope.row.originalFileName }}
  48. </el-link>
  49. </template>
  50. </el-table-column>
  51. <el-table-column label="操作" width="47" align="center">
  52. <template #default="scope">
  53. <el-button link size="small" type="danger"
  54. @click="handleDelFile(scope.row.id,scope.$index)">删除</el-button>
  55. </template>
  56. </el-table-column>
  57. </el-table>
  58. </div>
  59. <div style="height: 100px;">
  60. </div>
  61. <!-- <pagination v-show="total > 0" :total="total" v-model:page="query.pageNum" v-model:limit="query.pageSize"
  62. @pagination="loadData" style="background-color: rgba(0, 0, 0, 0);" /> -->
  63. </el-dialog>
  64. </template>
  65. <script setup>
  66. import { reactive } from 'vue';
  67. import { listFile } from '@/api/system/file'
  68. import { saveFiles, remove } from "@/api/business/production/deduction";
  69. import { uploadFile } from "@/api/tool/file";
  70. const props = defineProps(
  71. {
  72. width: {
  73. type: String,
  74. default: '800px'
  75. }
  76. }
  77. )
  78. // import api from '@/api/biz/fileStorage'
  79. const data = reactive({
  80. visible: false,
  81. list: [],
  82. total: 0,
  83. query: {
  84. name: '',
  85. total: 0,
  86. pageSize: 15,
  87. pageNum: 1
  88. },
  89. selection: [],
  90. baseUrl: import.meta.env.VITE_APP_BASE_API,
  91. options: {}
  92. })
  93. const form = ref();
  94. const { visible, list, query, selection, baseUrl, options, total } = toRefs(data)
  95. const supplementList = ref([])
  96. function open(arg) {
  97. visible.value = true
  98. options.value = arg
  99. loadData()
  100. }
  101. /**
  102. * 对话框关闭 事件
  103. */
  104. function close() {
  105. visible.value = false
  106. }
  107. /**
  108. * 加载数据
  109. */
  110. const loadData = async () => {
  111. const res = await listFile({ ...query.value, ...options.value })
  112. list.value = res.rows
  113. total.value = res.total
  114. list.value = list.value.filter(item => {
  115. return item.supplement != 1
  116. })
  117. form.value = list.value[0].fileUrl
  118. supplementList.value = res.rows.filter(item => {
  119. return item.supplement === 1
  120. })
  121. }
  122. function upload(param) {
  123. const formData = new FormData();
  124. formData.append("file", param.file);
  125. uploadFile(formData).then((res) => {
  126. if (res.code === 200) {
  127. const file = {};
  128. file.fileName = res.originalFilename;
  129. file.url = res.url;
  130. file.originalFileName = res.originalFilename;
  131. file.fileUrl = res.fileName;
  132. file.masterId = options.value.masterId;
  133. file.supplement = 1;
  134. file.masterTableName = "biz_deduction";
  135. saveFiles(file)
  136. supplementList.value.push(file);
  137. }
  138. });
  139. }
  140. /**
  141. * 列表checkbox列选择 事件
  142. */
  143. function handleSelectionChange(selection) {
  144. selection.value = selection
  145. }
  146. function handleDelFile(id, index) {
  147. console.log(id, index);
  148. if (id == undefined) {
  149. supplementList.value.splice(index, 1);
  150. } else {
  151. let data = { id: id }
  152. remove(data).then(res => {
  153. if (res.code === 200) {
  154. supplementList.value.splice(index, 1);
  155. }
  156. })
  157. }
  158. }
  159. function openEvidience() {
  160. window.open(`${baseUrl.value}/${form.value}`);
  161. }
  162. /**
  163. * 搜索 事件
  164. */
  165. function handleSearch() {
  166. loadData()
  167. }
  168. function openFile(attach) {
  169. window.open(`${baseUrl.value}/${attach.fileUrl}`, attach.fileName)
  170. }
  171. defineExpose({
  172. open
  173. })
  174. </script>