Commit 35ccd9f3 by Sweet Zhang

下载出账清单

parent 0aa2dfe3
......@@ -62,7 +62,8 @@ export function downloadPolicyFortuneAccount(data) {
return request({
url: '/csf/api/fortune/download/account',
method: 'post',
data: data
data: data,
responseType: 'blob'
})
}
......
......@@ -198,6 +198,7 @@ import { ref, reactive, onMounted } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
// 引入API
import { getPolicyFortuneList, downloadPolicyFortune ,downloadPolicyFortuneAccount} from "@/api/financial/commission"
import { download } from '@/utils/request' // 直接导入下载函数
// 查询参数
const queryParams = reactive({
......@@ -332,14 +333,11 @@ const handleView = (row) => {
}
// 生成出账清单
const generateBillingList = () => {
if (selectedRows.value.length === 0) {
ElMessage.warning('请先选择要生成清单的记录')
return
}
ElMessageBox.confirm(
`确认生成 ${selectedRows.value.length} 条记录的出账清单吗?`,
'提示',
......@@ -347,75 +345,39 @@ const generateBillingList = () => {
type: 'warning'
}
).then(() => {
// 调用生成清单的API
console.log('开始生成出账清单')
// 调用下载API
downloadPolicyFortuneAccount({
fortuneBizIdList: selectedRows.value.map(item => item.fortuneBizId)
}).then((response) => {
// 创建 Blob
const blob = new Blob([response.data], {
type: 'application/vnd.ms-excel;charset=utf-8'
});
// 检查 Blob 是否有效
if (!(blob instanceof Blob)) {
throw new Error('创建的 Blob 对象无效');
}
if (blob.size === 0) {
throw new Error('Blob 大小为 0');
}
// 创建下载链接
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
// 从响应头获取文件名,或使用默认名
const fileName = getFileName(response) || 'export.xls';
link.download = fileName;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
// 清理 URL
setTimeout(() => {
URL.revokeObjectURL(url);
}, 100);
}).then((res)=>{
console.log(res)
if(res){
// 处理下载响应
const blob = res instanceof Blob ? res : new Blob([res], { type: 'application/vnd.ms-excel;charset=utf-8' })
// 创建Blob对象,指定正确的MIME类型
const url = window.URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = url
// 不需要指定文件名,浏览器会自动使用默认文件名
link.download = `出账清单_${new Date().getTime()}.xlsx`
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
window.URL.revokeObjectURL(url)
}else{
ElMessage.error('下载失败')
}
})
ElMessage.success('出账清单生成成功')
selectedRows.value = []
}).catch(() => {})
}
// getFileName 方法
const getFileName = (response) =>{
// 安全地访问 headers
const headers = response.headers || {};
const contentDisposition = headers['content-disposition'] || headers['Content-Disposition'];
if (!contentDisposition) {
console.warn('未找到 Content-Disposition 头');
return 'export.xls'; // 返回默认文件名
}
try {
const fileNameMatch = contentDisposition.match(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/);
if (fileNameMatch && fileNameMatch[1]) {
let fileName = fileNameMatch[1].replace(/['"]/g, '');
// 处理 URL 编码
try {
fileName = decodeURIComponent(fileName);
} catch (e) {
console.warn('文件名解码失败,使用原始文件名');
}
return fileName;
}).catch((error) => {
if (error !== 'cancel') {
console.log('生成出账清单出错:', error)
}
} catch (error) {
console.error('解析文件名时出错:', error);
}
return 'export.xls'; // 默认文件名
})
}
// 提交表单
const submitForm = async () => {
try {
......
<template>
<div class="data-management-page">
<!-- 页面标题 -->
<el-page-header
@back="handleBack"
content="新单跟进"
class="page-header"
/>
<!-- 查询区域 -->
<el-card class="search-card">
<!-- 第一行筛选条件 -->
......@@ -53,18 +46,6 @@
<el-row :gutter="20" class="search-row">
<el-col :span="8">
<div class="form-item">
<label class="form-label">客户编号</label>
<el-input
v-model="searchForm.customerNo"
placeholder="请输入"
clearable
size="medium"
@keyup.enter="handleSearch"
/>
</div>
</el-col>
<el-col :span="8">
<div class="form-item">
<label class="form-label">签单时间</label>
<el-date-picker
v-model="searchForm.signDateRange"
......@@ -110,14 +91,14 @@
>
重置
</el-button>
<el-button
<!-- <el-button
type="info"
@click="toggleAdvancedSearch"
size="medium"
:icon="expandSearch ? ArrowUp : ArrowDown"
>
{{ expandSearch ? '收起筛选' : '更多筛选' }}
</el-button>
</el-button> -->
</el-col>
</el-row>
......@@ -260,7 +241,7 @@
<!-- 新单状态需要通过policyFollowStatusList和value匹配,显示label -->
<el-table-column prop="status" label="新单状态" min-width="100" align="center" sortable>
<template #default="scope">
<span>{{ policyFollowStatusList.value?.find(item => item.itemValue == scope.row.status)?.itemLabel || '-' }}</span>
<span>{{ convertStatusToDict(scope.row.status) }}</span>
</template>
</el-table-column>
<el-table-column prop="policyNo" label="保单号" min-width="100" align="center" sortable/>
......@@ -382,8 +363,13 @@ const getLists = ()=>{
policyFollowStatusList.value = [];
})
}
// const uploadUrl = ref(import.meta.env.VITE_APP_BASE_API + '/csf/api/policy_follow/upload/excel')
const uploadUrl = ref('http://139.224.145.34:9002/csf/api/policy_follow/upload/excel')
// 返回数据中状态需要转换为字典值
const convertStatusToDict = (status) => {
const dictItem = policyFollowStatusList.value.find(item => item.status === status)
return dictItem?.itemLabel ?? status
}
const uploadUrl = ref(import.meta.env.VITE_APP_BASE_API + '/csf/api/policy_follow/upload/excel')
// 搜索表单数据
const searchForm = reactive({
policyBizId: '', // 新单编号(对应接口的policyBizId)
......@@ -673,11 +659,7 @@ const downloadTemplate = () => {
// // 实际项目中这里会打开查看数据详情的对话框
// }
// 处理返回
const handleBack = () => {
ElMessage.info('返回上一页')
// 实际项目中这里会进行路由跳转
}
// 格式化文件大小
const formatFileSize = (bytes) => {
if (bytes === 0) return '0 B'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment