zhouwx
2 天以前 d5bd0e88c1eec6bb2947d2bfa57348d89edbc1c3
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<template>
  <div class="notice">
    <el-dialog
        v-model="dialogVisible"
        title="证书列表"
        width="600px"
        :before-close="handleClose"
        :close-on-press-escape="false"
        :close-on-click-modal="false"
    >
      <el-button
          style="margin-bottom: 15px;float: right"
          type="primary"
          @click="openAddDialog('add',{})"
      >新增</el-button>
      <el-table v-loading="loading" :data="dataList" :border="true"  >
        <el-table-column type="index" label="序号" width="80" align="center"></el-table-column>
        <el-table-column label="证书名称" prop="certifityName" align="center"  />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width"  width="200" >
          <template #default="scope" >
            <el-button link type="primary" @click="openFile(scope.row.filePath)">查看</el-button>
            <el-button link type="primary" @click="downloadFile(scope.row)">下载</el-button>
            <el-button link type="primary"  @click="openAddDialog('edit',scope.row)" >编辑</el-button>
            <el-button link type="danger"  @click="handleDelete(scope.row)" >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
 
      <div class="pag-container">
<!--        <el-pagination-->
<!--            v-model:current-page="data.queryParams.pageNum"-->
<!--            v-model:page-size="data.queryParams.pageSize"-->
<!--            :page-sizes="[10,15,20,25]"-->
<!--            layout="total, sizes, prev, pager, next, jumper"-->
<!--            :total="total"-->
<!--            @size-change="handleSizeChange"-->
<!--            @current-change="handleCurrentChange"-->
<!--        />-->
      </div>
    </el-dialog>
    <addCertDialog ref="certRef" @getList="getCertList"></addCertDialog>
  </div>
</template>
<script setup>
import {reactive, ref, toRefs, defineEmits, nextTick, onMounted} from 'vue'
import {ElMessage, ElMessageBox} from "element-plus";
import addCertDialog from './addCert.vue'
import {addUser, editUser, getUserById, resetPwd} from "@/api/onlineEducation/user"
import {Base64} from "js-base64"
import {getCompany} from "@/api/onlineEducation/company";
import {addIndustryTemp, updateIndustryTemp, updateInfoPlatforms} from "@/api/staffManage/staff";
import {getToken} from "@/utils/auth";
import {delPic} from "@/api/onlineEducation/banner";
import {addFile, editFile} from "@/api/qualityManage/range";
import {addProductFile, editProductFile} from "@/api/selfProblems/productFile";
import {delSupplierById, delSupplierCert, getPerformance, getSupplierCert} from "@/api/supplier/supplierList";
import axios from "axios";
import {renderAsync} from "docx-preview";
 
const emit = defineEmits(["getList"]);
const dialogVisible = ref(false)
const superRef = ref()
const certRef = ref()
const state = reactive({
  title: '',
  supplierSureId: null
})
onMounted(() => {
 
});
const loading = ref(false);
const dataList = ref([]);
const total = ref(0);
const openDialog = async (type, value) => {
  state.supplierSureId = value.id
  await getCertList()
  dialogVisible.value = true
}
const getCertList = async () => {
  const param = {
    supplierSureId: state.supplierSureId
  }
  const res = await getSupplierCert(param)
  if(res.code == 200){
    dataList.value = res.data
 
  }else {
    ElMessage.warning(res.message)
  }
}
 
 
 
const handleClose = () => {
  dialogVisible.value = false;
}
const openAddDialog = (type,value) => {
  value.supplierSureId = state.supplierSureId
  certRef.value.openDialog(type,value)
}
 
const handleDelete = (val) => {
  ElMessageBox.confirm(
      '确定删除此条数据?',
      '提示',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
      .then( async() => {
        const res = await delSupplierCert(val.id);
        if(res.code === 200){
          ElMessage({
            type: 'success',
            message: '删除成功'
          });
          getCertList();
        }else{
          ElMessage.warning(res.message)
        }
      })
}
const downloadFile = (e)=>{
  axios.get(import.meta.env.VITE_APP_BASE_API + '/' +e.filePath,{headers:{'Content-Type': 'application/json','Authorization': `${getToken()}`},responseType: 'blob'}).then(res=>{
    if (res) {
      const link = document.createElement('a')
      let blob = new Blob([res.data],{type: res.data.type})
      link.style.display = "none";
      link.href = URL.createObjectURL(blob); // 创建URL
      link.setAttribute("download", e.certifityName);
      document.body.appendChild(link);
      link.click();
      document.body.removeChild(link);
    } else {
      ElMessage({
        type: 'warning',
        message: '文件读取失败'
      });
    }
  })
}
const openFile = async(path)=>{
 
  const ext = path.split('.').pop().toLowerCase();
  if (ext === 'doc') {
    ElMessageBox.confirm('暂不支持线上预览.doc文件,是否下载查看?', '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning' }).then(() => {
      window.open(`${import.meta.env.VITE_APP_BASE_API}/${path}`, '_blank');
    }).catch(() => {
      console.log('取消预览')
    });
    return
  }else if(ext == 'pdf' || ext == 'jpg' || ext == 'jpeg' || ext == 'png' ){
    window.open(`${import.meta.env.VITE_APP_BASE_API}/${path}`, '_blank');
  }else{
    try {
      // 1. 获取文件
      const response = await fetch(import.meta.env.VITE_APP_BASE_API + '/' + path);
      const arrayBuffer = await response.arrayBuffer()
      // 2. 创建新窗口
      const win = window.open('', '_blank')
      win.document.write(`
      <!DOCTYPE html>
      <html>
        <head>
          <title>预览</title>
          <style>
            body { margin: 20px; font-family: Arial; }
            .docx-container { width: 100%; height: 100%; }
          </style>
        </head>
        <body>
          <div id="container" class="docx-container"></div>
        </body>
      </html>
    `);
      // 3. 渲染 DOCX
      await renderAsync(arrayBuffer, win.document.getElementById('container'));
 
    } catch (error) {
      alert(`预览失败: ${error.message}`);
    }
  }
}
defineExpose({
  openDialog
});
 
</script>
 
<style scoped lang="scss">
.notice{
  :deep(.el-form .el-form-item__label) {
    font-size: 15px;
  }
  .file {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
  }
}
</style>