gaoluyang
4 天以前 792ad8ef7684685544fbf03cc93d4eb2dc605bfa
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
<template>
  <el-dialog v-model="dialogVisible" title="附件" width="40%" :before-close="handleClose">
    <el-table :data="tableData" border height="40vh" stripe>
      <el-table-column label="附件名称" prop="name" min-width="400" show-overflow-tooltip />
      <el-table-column fixed="right" label="操作" width="150" align="center">
        <template #default="scope">
          <el-button link type="primary" size="small" @click="downLoadFile(scope.row)">下载</el-button>
          <el-button link type="primary" size="small" @click="lookFile(scope.row)">预览</el-button>
          <el-button link type="primary" size="small" @click="delFile(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-dialog>
  <filePreview ref="filePreviewRef" />
</template>
 
<script setup>
import { ref, getCurrentInstance } from 'vue'
import filePreview from '@/components/filePreview/index.vue'
import { ElMessageBox } from 'element-plus'
import {
  delLedgerFile
} from "@/api/salesManagement/salesLedger.js";
 
const emit = defineEmits(['refresh'])
const dialogVisible = ref(false)
const tableData = ref([])
const currentRowId = ref(null)
const { proxy } = getCurrentInstance();
const filePreviewRef = ref()
const handleClose = () => {
  dialogVisible.value = false
}
const open = (list, rowId = null) => {
  dialogVisible.value = true
  tableData.value = list
  currentRowId.value = rowId
}
const downLoadFile = (row) => {
  proxy.$download.name(row.url);
 
}
const lookFile = (row) => {
  filePreviewRef.value.open(row.url)
}
const delFile = (row) => {
  ElMessageBox.confirm('确定要删除该附件吗?', '删除确认', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning',
  }).then(() => {
    let ids = [];
    ids.push(row.id);
    delLedgerFile(ids).then((res) => {
      if (res.code === 200) {
        proxy.$modal.msgSuccess("删除成功");
        // 通知父组件刷新数据
        emit('refresh', currentRowId.value);
      } else {
        proxy.$modal.msgError(res.msg || "删除失败");
      }
    }).catch((error) => {
      console.error("删除附件失败:", error);
      proxy.$modal.msgError("删除失败,请稍后重试");
    });
  }).catch(() => {
    // 用户取消删除
  });
}
defineExpose({
  open
})
</script>
 
<style></style>