添加库存更新记录导出功能
This commit is contained in:
parent
11519bd3f8
commit
1f8d5086be
|
|
@ -32,6 +32,17 @@ const getStockUpdateRecord = (params) => {
|
|||
})
|
||||
}
|
||||
|
||||
const downloadStockUpdateRecordExcel = (data) => {
|
||||
return request({
|
||||
url: '/excel/downloadStockUpdateRecordExcel',
|
||||
method: 'post',
|
||||
responseType: 'blob',
|
||||
data: data,
|
||||
timeout: 600000
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
const handleExceptionStock = (params) => {
|
||||
return request({
|
||||
url: '/stock/handleExceptionStock',
|
||||
|
|
@ -45,5 +56,6 @@ export {
|
|||
updateStockInfo,
|
||||
getStockNumByGoodsId,
|
||||
getStockUpdateRecord,
|
||||
handleExceptionStock
|
||||
handleExceptionStock,
|
||||
downloadStockUpdateRecordExcel
|
||||
}
|
||||
|
|
@ -16,6 +16,9 @@
|
|||
<el-button type="primary" @click="search()">搜索</el-button>
|
||||
<el-button type="warning" @click="reset()">重置</el-button>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-button style="background-color: #32CD32; color: #000;" @click="exportExcel">导出</el-button>
|
||||
</el-row>
|
||||
</div>
|
||||
<br />
|
||||
<el-table :data="recordList" stripe border v-loading="loading" class="table-class" highlight-current-row
|
||||
|
|
@ -52,12 +55,14 @@
|
|||
<script setup>
|
||||
import store from '@/store'
|
||||
import { getStockUpdateRecord } from '@/api/stock.js'
|
||||
import { errorBox } from '@/utils/myMessageBox.js'
|
||||
import { dateFormatter, timeFormatter } from '@/utils/formatter.js'
|
||||
import { Search } from '@element-plus/icons-vue'
|
||||
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
|
||||
</script>
|
||||
<script>
|
||||
import {downloadStockUpdateRecordExcel} from "@/api/stock";
|
||||
import {errorBox} from "@/utils/myMessageBox";
|
||||
|
||||
export default {
|
||||
name: 'stockUpdateRecord',
|
||||
data() {
|
||||
|
|
@ -165,6 +170,43 @@ export default {
|
|||
})
|
||||
this.loading = false
|
||||
},
|
||||
exportExcel() {
|
||||
const request = {
|
||||
pageNo: this.currentPage,
|
||||
pageSize: this.pageSize,
|
||||
vehicleId: this.vehicleIdQuery.trim(),
|
||||
goodsId: this.goodsIdQuery.trim(),
|
||||
reason: this.reasonQuery.trim(),
|
||||
updateTime: timeFormatter(this.updateTimeQuery),
|
||||
updateEndTime: timeFormatter(this.updateEndTimeQuery),
|
||||
userName: store.getters.getUserName
|
||||
}
|
||||
downloadStockUpdateRecordExcel(request).then(res => {
|
||||
const link = document.createElement('a');//创建a标签
|
||||
try {
|
||||
// let blob = new Blob([res.data],{type: 'application/vnd.ms-excel'}); //如果后台返回的不是blob对象类型,先定义成blob对象格式,该type导出为xls格式,
|
||||
let blob = res.data //如果后台返回的直接是blob对象类型,直接获取数据
|
||||
// let _fileName = res.headers['content-disposition'].split(';')[1].split('=')[1]; //拆解获取文件名,如果后端有给返回文件名的话
|
||||
let _fileName = "库存更新记录" + dateFormatter(new Date) + ".xlsx"
|
||||
link.style.display = 'none'//隐藏
|
||||
|
||||
// 兼容不同浏览器的URL对象
|
||||
const url = window.URL || window.webkitURL || window.moxURL
|
||||
link.href = url.createObjectURL(blob)
|
||||
link.setAttribute('download', _fileName.substring(_fileName.lastIndexOf('_') + 1))
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
document.body.removeChild(link)
|
||||
url.revokeObjectURL(link.href)//移除url对象
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
errorBox('下载文件失败')
|
||||
}
|
||||
}).catch(err => {
|
||||
console.log(err)
|
||||
errorBox('导出失败')
|
||||
})
|
||||
},
|
||||
timeFormat: (row, column, cellValue, index) => {
|
||||
return timeFormatter(cellValue)
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user