库存资产excel文件导出
This commit is contained in:
@ -9,9 +9,7 @@ export function listMaterialBase(params: any) {
|
||||
})
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// 1.1 获取基础信息筛选选项 (所有类别/类型) [新增]
|
||||
// ==========================================
|
||||
// 1.1 获取选项
|
||||
export function getMaterialBaseOptions() {
|
||||
return request({
|
||||
url: '/inbound/base/options',
|
||||
@ -19,7 +17,17 @@ export function getMaterialBaseOptions() {
|
||||
})
|
||||
}
|
||||
|
||||
// 2. 新增基础信息
|
||||
// 1.2 [新增] 导出全口径资产统计表
|
||||
export function exportAssetStatistics(params: any) {
|
||||
return request({
|
||||
url: '/inbound/base/export',
|
||||
method: 'get',
|
||||
params,
|
||||
responseType: 'blob' // 关键:必须声明为 blob 处理文件流
|
||||
})
|
||||
}
|
||||
|
||||
// 2. 新增
|
||||
export function addMaterialBase(data: any) {
|
||||
return request({
|
||||
url: '/inbound/base/',
|
||||
@ -28,7 +36,7 @@ export function addMaterialBase(data: any) {
|
||||
})
|
||||
}
|
||||
|
||||
// 3. 修改基础信息 (包含状态启用/禁用)
|
||||
// 3. 修改
|
||||
export function updateMaterialBase(data: any) {
|
||||
return request({
|
||||
url: `/inbound/base/${data.id}`,
|
||||
@ -37,18 +45,10 @@ export function updateMaterialBase(data: any) {
|
||||
})
|
||||
}
|
||||
|
||||
// 4. 删除基础信息
|
||||
// 4. 删除
|
||||
export function delMaterialBase(id: number) {
|
||||
return request({
|
||||
url: `/inbound/base/${id}`,
|
||||
method: 'delete'
|
||||
})
|
||||
}
|
||||
|
||||
// 5. 获取详情 (可选,用于编辑回显)
|
||||
export function getMaterialBase(id: number) {
|
||||
return request({
|
||||
url: `/inbound/base/${id}`,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
@ -67,6 +67,10 @@
|
||||
</div>
|
||||
|
||||
<div class="right-toolbar">
|
||||
<el-button type="success" plain @click="handleExport" :loading="exportLoading" style="margin-right: 10px">
|
||||
<el-icon style="margin-right: 5px"><Download /></el-icon>导出库存统计
|
||||
</el-button>
|
||||
|
||||
<el-button type="primary" @click="handleAdd" style="margin-right: 10px">
|
||||
<el-icon style="margin-right: 5px"><Plus /></el-icon>新增
|
||||
</el-button>
|
||||
@ -412,8 +416,8 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, onMounted, nextTick, computed } from 'vue';
|
||||
import { Plus, Picture, Document, Refresh, Setting, Rank, Camera, Link } from '@element-plus/icons-vue';
|
||||
import { ref, reactive, onMounted, nextTick } from 'vue';
|
||||
import { Plus, Document, Refresh, Setting, Rank, Camera, Link, Download } from '@element-plus/icons-vue';
|
||||
import { ElMessage, ElMessageBox, ElLoading } from 'element-plus';
|
||||
import type { FormInstance, FormRules } from 'element-plus';
|
||||
|
||||
@ -422,7 +426,8 @@ import {
|
||||
addMaterialBase,
|
||||
updateMaterialBase,
|
||||
delMaterialBase,
|
||||
getMaterialBaseOptions
|
||||
getMaterialBaseOptions,
|
||||
exportAssetStatistics // 导入导出API
|
||||
} from '@/api/material_base';
|
||||
import { uploadFile, deleteFile } from '@/api/common/upload';
|
||||
import WebRtcCamera from '@/components/Camera/WebRtcCamera.vue';
|
||||
@ -464,6 +469,7 @@ interface CascaderOption {
|
||||
|
||||
// --- 响应式数据 ---
|
||||
const loading = ref(false);
|
||||
const exportLoading = ref(false); // 导出加载状态
|
||||
const total = ref(0);
|
||||
const tableData = ref<MaterialBaseVO[]>([]);
|
||||
const submitLoading = ref(false);
|
||||
@ -481,7 +487,6 @@ const cameraRef = ref<InstanceType<typeof WebRtcCamera> | null>(null);
|
||||
const currentCameraField = ref<'generalImage' | 'generalManual'>('generalImage');
|
||||
|
||||
const columns = reactive({
|
||||
// [修改] 默认隐藏 ID
|
||||
id: { visible: false },
|
||||
companyName: { visible: true },
|
||||
name: { visible: true },
|
||||
@ -646,7 +651,51 @@ const getList = () => {
|
||||
});
|
||||
};
|
||||
|
||||
let searchTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
// [修改] 导出处理函数:修正文件名格式
|
||||
const handleExport = () => {
|
||||
exportLoading.value = true;
|
||||
const params = {
|
||||
keyword: queryParams.keyword,
|
||||
company: queryParams.company,
|
||||
category: queryParams.category,
|
||||
type: queryParams.type,
|
||||
isEnabled: queryParams.isEnabled
|
||||
};
|
||||
|
||||
exportAssetStatistics(params)
|
||||
.then((response: any) => {
|
||||
const blob = new Blob([response], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
|
||||
// 构造文件名:库存统计_YYYYMMDD_HHMMSS
|
||||
const now = new Date();
|
||||
const year = now.getFullYear();
|
||||
const month = String(now.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(now.getDate()).padStart(2, '0');
|
||||
const hour = String(now.getHours()).padStart(2, '0');
|
||||
const minute = String(now.getMinutes()).padStart(2, '0');
|
||||
const second = String(now.getSeconds()).padStart(2, '0');
|
||||
const filename = `库存统计_${year}${month}${day}_${hour}${minute}${second}.xlsx`;
|
||||
|
||||
link.setAttribute('download', filename);
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
window.URL.revokeObjectURL(url);
|
||||
ElMessage.success('导出成功');
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("导出失败", err);
|
||||
ElMessage.error('导出失败');
|
||||
})
|
||||
.finally(() => {
|
||||
exportLoading.value = false;
|
||||
});
|
||||
};
|
||||
|
||||
let searchTimer: any = null;
|
||||
const handleInputSearch = () => {
|
||||
if (searchTimer) clearTimeout(searchTimer);
|
||||
searchTimer = setTimeout(() => {
|
||||
|
||||
Reference in New Issue
Block a user