给单据中移除原来的excel导出逻辑

This commit is contained in:
jishenghua
2024-01-14 21:14:50 +08:00
parent 71e10b9fcb
commit b1d4265bdc
18 changed files with 111 additions and 238 deletions

View File

@@ -1,5 +1,5 @@
import { isURL } from '@/utils/validate'
import XLSX from 'xlsx'
import { downFilePost} from '@/api/manage'
import Vue from 'vue'
import introJs from 'intro.js'
@@ -585,58 +585,32 @@ export function changeListFmtMinus(str) {
return newArr;
}
/**
通用的打开下载对话框方法,没有测试过具体兼容性
@param url 下载地址也可以是一个blob对象必选
@param saveName 保存文件名,可选
*/
export function openDownloadDialog (url, saveName) {
if (typeof url === 'object' && url instanceof Blob) {
url = URL.createObjectURL(url) // 创建blob地址
//通过post方式导出Excel
export function exportXlsPost(fileName, title, head, tip, list) {
if(!fileName || typeof fileName != "string"){
fileName = "导出文件"
}
let aLink = document.createElement('a')
aLink.href = url
saveName = saveName + '_' + getNowFormatStr() + '.xls'
aLink.download = saveName || '' // HTML5新增的属性指定保存文件名可以不要后缀注意file:///模式下不会生效
let event
if (window.MouseEvent) event = new MouseEvent('click')
else {
event = document.createEvent('MouseEvents')
event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
}
aLink.dispatchEvent(event)
}
/**
* 将一个sheet转成最终的excel文件的blob对象然后利用URL.createObjectURL下载
* @param sheet
* @param sheetName
* @returns {Blob}
*/
export function sheet2blob (aoa, sheetName) {
let sheet = XLSX.utils.aoa_to_sheet(aoa)
sheetName = sheetName || 'sheet1'
let workbook = {
SheetNames: [sheetName],
Sheets: {}
}
workbook.Sheets[sheetName] = sheet
// 生成excel的配置项
let wopts = {
bookType: 'xls', // 要生成的文件类型
bookSST: false, // 是否生成Shared String Table官方解释是如果开启生成速度会下降但在低版本IOS设备上有更好的兼容性
type: 'binary'
}
let wbout = XLSX.write(workbook, wopts)
let blob = new Blob([s2ab(wbout)], { type: 'application/octet-stream' })
// 字符串转ArrayBuffer
function s2ab (s) {
let buf = new ArrayBuffer(s.length)
let view = new Uint8Array(buf)
for (let i = 0; i != s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF
return buf
}
return blob
let paramObj = {'title': title, 'head': head, 'tip': tip, 'list': list}
console.log("导出参数", paramObj)
downFilePost(paramObj).then((data)=>{
if (!data) {
this.$message.warning("文件下载失败")
return
}
if (typeof window.navigator.msSaveBlob !== 'undefined') {
window.navigator.msSaveBlob(new Blob([data],{type: 'application/vnd.ms-excel'}), fileName+'.xls')
}else{
let url = window.URL.createObjectURL(new Blob([data],{type: 'application/vnd.ms-excel'}))
let link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.setAttribute('download', fileName + '_' + getNowFormatStr()+'.xls')
document.body.appendChild(link)
link.click()
document.body.removeChild(link); //下载完成移除元素
window.URL.revokeObjectURL(url); //释放掉blob对象
}
})
}
/**

View File

@@ -1127,7 +1127,7 @@
import pick from 'lodash.pick'
import { getAction, postAction, getFileAccessHttpUrl } from '@/api/manage'
import { findBillDetailByNumber, findFinancialDetailByNumber, getPlatformConfigByKey, getCurrentSystemConfig} from '@/api/api'
import { getMpListShort, getCheckFlag, openDownloadDialog, sheet2blob } from "@/utils/util"
import { getMpListShort, getCheckFlag, exportXlsPost } from "@/utils/util"
import BillPrintIframe from './BillPrintIframe'
import FinancialDetail from '../../financial/dialog/FinancialDetail'
import JUpload from '@/components/jeecg/JUpload'
@@ -1747,21 +1747,22 @@
},
//零售出库|零售退货入库
retailExportExcel() {
let aoa = []
aoa = [['会员卡号:', this.model.organName, '', '单据日期:', this.model.operTimeStr, '', '单据编号:', this.model.number],[]]
let title = ['仓库名称', '条码', '名称', '规格', '型号', '颜色', '扩展信息', '库存', '单位', '序列号', '批号', '有效期', '多属性', '数量', '单价', '金额', '备注']
aoa.push(title)
let list = []
let head = '仓库名称,条码,名称,规格,型号,颜色,扩展信息,库存,单位,序列号,批号,有效期,多属性,数量,单价,金额,备注'
for (let i = 0; i < this.dataSource.length; i++) {
let item = []
let ds = this.dataSource[i]
let item = [ds.depotName, ds.barCode, ds.name, ds.standard, ds.model, ds.color, ds.materialOther, ds.stock, ds.unit,
ds.snList, ds.batchNumber, ds.expirationDate, ds.sku, ds.operNumber, ds.unitPrice, ds.allPrice, ds.remark]
aoa.push(item)
item.push(ds.depotName, ds.barCode, ds.name, ds.standard, ds.model, ds.color, ds.materialOther, ds.stock, ds.unit,
ds.snList, ds.batchNumber, ds.expirationDate, ds.sku, ds.operNumber, ds.unitPrice, ds.allPrice, ds.remark)
list.push(item)
}
openDownloadDialog(sheet2blob(aoa), this.billType + '_' + this.model.number)
let organName = this.model.organName? '会员卡号' + this.model.organName: ''
let tip = organName + ' ' + '单据日期:' + this.model.operTimeStr + ' ' + '单据编号:' + this.model.number
exportXlsPost(this.billType + '_' + this.model.number, '单据导出', head, tip, list)
},
//采购订单|销售订单
orderExportExcel() {
let aoa = []
let list = []
let finishType = ''
let organType = ''
if(this.billType === '采购订单') {
@@ -1771,98 +1772,104 @@
finishType = '已出库'
organType = '客户:'
}
aoa = [[organType, this.model.organName, '', '单据日期:', this.model.operTimeStr, '', '单据编号:', this.model.number],[]]
let title = ['条码', '名称', '规格', '型号', '颜色', '扩展信息', '库存', '单位', '多属性', '数量', finishType, '单价', '金额', '税率(%)', '税额', '价税合计', '备注']
aoa.push(title)
let head = '条码,名称,规格,型号,颜色,扩展信息,库存,单位,多属性,数量,' + finishType + ',单价,金额,税率(%),税额,价税合计,备注'
for (let i = 0; i < this.dataSource.length; i++) {
let item = []
let ds = this.dataSource[i]
let item = [ds.barCode, ds.name, ds.standard, ds.model, ds.color, ds.materialOther, ds.stock, ds.unit, ds.sku,
ds.operNumber, ds.finishNumber, ds.unitPrice, ds.allPrice, ds.taxRate, ds.taxMoney, ds.taxLastMoney, ds.remark]
aoa.push(item)
item.push(ds.barCode, ds.name, ds.standard, ds.model, ds.color, ds.materialOther, ds.stock, ds.unit, ds.sku,
ds.operNumber, ds.finishNumber, ds.unitPrice, ds.allPrice, ds.taxRate, ds.taxMoney, ds.taxLastMoney, ds.remark)
list.push(item)
}
openDownloadDialog(sheet2blob(aoa), this.billType + '_' + this.model.number)
let organName = this.model.organName? this.model.organName: ''
let tip = organType + organName + ' ' + '单据日期:' + this.model.operTimeStr + ' ' + '单据编号:' + this.model.number
exportXlsPost(this.billType + '_' + this.model.number, '单据导出', head, tip, list)
},
//采购入库|采购退货出库|销售出库|销售退货入库
purchaseSaleExportExcel() {
let aoa = []
let list = []
let organType = ''
if(this.billType === '采购入库' || this.billType === '采购退货出库') {
organType = '供应商:'
} else if(this.billType === '销售出库' || this.billType === '销售退货入库') {
organType = '客户:'
}
aoa = [[organType, this.model.organName, '', '单据日期:', this.model.operTimeStr, '', '单据编号:', this.model.number, '', '关联单号:', this.model.linkNumber],[]]
let title = ['仓库名称', '条码', '名称', '规格', '型号', '颜色', '扩展信息', '库存', '单位', '序列号', '批号', '有效期', '多属性', '数量', '单价', '金额', '税率(%)', '税额', '价税合计', '重量', '备注']
aoa.push(title)
let head = '仓库名称,条码,名称,规格,型号,颜色,扩展信息,库存,单位,序列号,批号,有效期,多属性,数量,单价,金额,税率(%),税额,价税合计,重量,备注'
for (let i = 0; i < this.dataSource.length; i++) {
let item = []
let ds = this.dataSource[i]
let item = [ds.depotName, ds.barCode, ds.name, ds.standard, ds.model, ds.color, ds.materialOther, ds.stock, ds.unit,
ds.snList, ds.batchNumber, ds.expirationDate, ds.sku, ds.operNumber, ds.unitPrice, ds.allPrice, ds.taxRate, ds.taxMoney, ds.taxLastMoney, ds.weight, ds.remark]
aoa.push(item)
item.push(ds.depotName, ds.barCode, ds.name, ds.standard, ds.model, ds.color, ds.materialOther, ds.stock, ds.unit,
ds.snList, ds.batchNumber, ds.expirationDate, ds.sku, ds.operNumber, ds.unitPrice, ds.allPrice, ds.taxRate, ds.taxMoney, ds.taxLastMoney, ds.weight, ds.remark)
list.push(item)
}
openDownloadDialog(sheet2blob(aoa), this.billType + '_' + this.model.number)
let organName = this.model.organName? this.model.organName: ''
let linkNumber = this.model.linkNumber? this.model.linkNumber: ''
let tip = organType + organName + ' ' + '单据日期:' + this.model.operTimeStr + ' ' + '单据编号:' +
this.model.number + '' + '关联单号:' + linkNumber
exportXlsPost(this.billType + '_' + this.model.number, '单据导出', head, tip, list)
},
//其它入库|其它出库
otherExportExcel() {
let aoa = []
let list = []
let organType = ''
if(this.billType === '其它入库') {
organType = '供应商:'
} else if(this.billType === '其它出库') {
organType = '客户:'
}
aoa = [[organType, this.model.organName, '', '单据日期:', this.model.operTimeStr, '', '单据编号:', this.model.number],[]]
let title = ['仓库名称', '条码', '名称', '规格', '型号', '颜色', '扩展信息', '库存', '单位', '序列号', '批号', '有效期', '多属性', '数量', '单价', '金额', '备注']
aoa.push(title)
let head = '仓库名称,条码,名称,规格,型号,颜色,扩展信息,库存,单位,序列号,批号,有效期,多属性,数量,单价,金额,备注'
for (let i = 0; i < this.dataSource.length; i++) {
let item = []
let ds = this.dataSource[i]
let item = [ds.depotName, ds.barCode, ds.name, ds.standard, ds.model, ds.color, ds.materialOther, ds.stock, ds.unit,
ds.snList, ds.batchNumber, ds.expirationDate, ds.sku, ds.operNumber, ds.unitPrice, ds.allPrice, ds.remark]
aoa.push(item)
item.push(ds.depotName, ds.barCode, ds.name, ds.standard, ds.model, ds.color, ds.materialOther, ds.stock, ds.unit,
ds.snList, ds.batchNumber, ds.expirationDate, ds.sku, ds.operNumber, ds.unitPrice, ds.allPrice, ds.remark)
list.push(item)
}
openDownloadDialog(sheet2blob(aoa), this.billType + '_' + this.model.number)
let organName = this.model.organName? this.model.organName: ''
let tip = organType + organName + ' ' + '单据日期:' + this.model.operTimeStr + ' ' + '单据编号:' + this.model.number
exportXlsPost(this.billType + '_' + this.model.number, '单据导出', head, tip, list)
},
//调拨出库
allocationOutExportExcel() {
let aoa = []
aoa = [['单据日期:', this.model.operTimeStr, '', '单据编号:', this.model.number],[]]
let title = ['仓库名称', '条码', '名称', '规格', '型号', '颜色', '扩展信息', '库存', '调入仓库', '单位', '多属性', '数量', '单价', '金额', '备注']
aoa.push(title)
let list = []
let head = '仓库名称,条码,名称,规格,型号,颜色,扩展信息,库存,调入仓库,单位,多属性,数量,单价,金额,备注'
for (let i = 0; i < this.dataSource.length; i++) {
let item = []
let ds = this.dataSource[i]
let item = [ds.depotName, ds.barCode, ds.name, ds.standard, ds.model, ds.color, ds.materialOther, ds.stock, ds.anotherDepotName, ds.unit,
ds.sku, ds.operNumber, ds.unitPrice, ds.allPrice, ds.remark]
aoa.push(item)
item.push(ds.depotName, ds.barCode, ds.name, ds.standard, ds.model, ds.color, ds.materialOther, ds.stock, ds.anotherDepotName, ds.unit,
ds.sku, ds.operNumber, ds.unitPrice, ds.allPrice, ds.remark)
list.push(item)
}
openDownloadDialog(sheet2blob(aoa), this.billType + '_' + this.model.number)
let tip = '单据日期:' + this.model.operTimeStr + ' ' + '单据编号:' + this.model.number
exportXlsPost(this.billType + '_' + this.model.number, '单据导出', head, tip, list)
},
//组装单|拆卸单
assembleExportExcel() {
let aoa = []
aoa = [['单据日期:', this.model.operTimeStr, '', '单据编号:', this.model.number],[]]
let title = ['商品类型', '仓库名称', '条码', '名称', '规格', '型号', '颜色', '扩展信息', '库存', '单位', '多属性', '数量', '单价', '金额', '备注']
aoa.push(title)
let list = []
let head = ['商品类型,仓库名称,条码,名称,规格,型号,颜色,扩展信息,库存,单位,多属性,数量,单价,金额,备注']
for (let i = 0; i < this.dataSource.length; i++) {
let item = []
let ds = this.dataSource[i]
let item = [ds.mType, ds.depotName, ds.barCode, ds.name, ds.standard, ds.model, ds.color, ds.materialOther, ds.stock, ds.unit,
ds.sku, ds.operNumber, ds.unitPrice, ds.allPrice, ds.remark]
aoa.push(item)
item.push(ds.mType, ds.depotName, ds.barCode, ds.name, ds.standard, ds.model, ds.color, ds.materialOther, ds.stock, ds.unit,
ds.sku, ds.operNumber, ds.unitPrice, ds.allPrice, ds.remark)
list.push(item)
}
openDownloadDialog(sheet2blob(aoa), this.billType + '_' + this.model.number)
let tip = '单据日期:' + this.model.operTimeStr + ' ' + '单据编号:' + this.model.number
exportXlsPost(this.billType + '_' + this.model.number, '单据导出', head, tip, list)
},
//盘点复盘
stockCheckReplayExportExcel() {
let aoa = []
aoa = [['单据日期:', this.model.operTimeStr, '', '单据编号:', this.model.number, '', '关联单据:', this.model.linkNumber],[]]
let title = ['仓库名称', '条码', '名称', '规格', '型号', '扩展信息', '库存', '单位', '多属性', '数量', '单价', '金额', '备注']
aoa.push(title)
let list = []
let head = '仓库名称,条码,名称,规格,型号,扩展信息,库存,单位,多属性,数量,单价,金额,备注'
for (let i = 0; i < this.dataSource.length; i++) {
let item = []
let ds = this.dataSource[i]
let item = [ds.depotName, ds.barCode, ds.name, ds.standard, ds.model, ds.materialOther, ds.stock, ds.unit,
ds.sku, ds.operNumber, ds.unitPrice, ds.allPrice, ds.remark]
aoa.push(item)
item.push(ds.depotName, ds.barCode, ds.name, ds.standard, ds.model, ds.materialOther, ds.stock, ds.unit,
ds.sku, ds.operNumber, ds.unitPrice, ds.allPrice, ds.remark)
list.push(item)
}
openDownloadDialog(sheet2blob(aoa), this.billType + '_' + this.model.number)
let linkNumber = this.model.linkNumber? this.model.linkNumber: ''
let tip = '单据日期:' + this.model.operTimeStr + ' ' + '单据编号:' + this.model.number + '' + '关联单号:' + linkNumber
exportXlsPost(this.billType + '_' + this.model.number, '单据导出', head, tip, list)
}
}
}

View File

@@ -135,7 +135,7 @@
<script>
import BillDetail from '../bill/dialog/BillDetail'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getNowFormatYear, openDownloadDialog, sheet2blob} from "@/utils/util"
import { getNowFormatYear } from "@/utils/util"
import {getAction} from '@/api/manage'
import {findBySelectSup, findBillDetailByNumber, getAllOrganizationTreeByUser} from '@/api/api'
import JEllipsis from '@/components/jeecg/JEllipsis'

View File

@@ -116,7 +116,7 @@
</template>
<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getNowFormatYear, getMpListShort, openDownloadDialog, sheet2blob} from "@/utils/util"
import { getNowFormatYear, getMpListShort } from "@/utils/util"
import {getAction} from '@/api/manage'
import {findBySelectSup, getAllOrganizationTreeByUser} from '@/api/api'
import JEllipsis from '@/components/jeecg/JEllipsis'

View File

@@ -96,7 +96,7 @@
<script>
import DebtAccountList from './modules/DebtAccountList'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getNowFormatYear, openDownloadDialog, sheet2blob} from "@/utils/util"
import { getNowFormatYear } from "@/utils/util"
import { getAction } from '@/api/manage'
import {findBySelectCus} from '@/api/api'
import JEllipsis from '@/components/jeecg/JEllipsis'

View File

@@ -136,7 +136,7 @@
<script>
import BillDetail from '../bill/dialog/BillDetail'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getNowFormatYear, openDownloadDialog, sheet2blob} from "@/utils/util"
import { getNowFormatYear } from "@/utils/util"
import {getAction} from '@/api/manage'
import {findBySelectOrgan, findBillDetailByNumber, getUserList, getAllOrganizationTreeByUser} from '@/api/api'
import JEllipsis from '@/components/jeecg/JEllipsis'

View File

@@ -110,7 +110,7 @@
</template>
<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getNowFormatYear, openDownloadDialog, sheet2blob} from "@/utils/util"
import { getNowFormatYear } from "@/utils/util"
import {getAction} from '@/api/manage'
import {findBySelectOrgan, getAllOrganizationTreeByUser} from '@/api/api'
import JEllipsis from '@/components/jeecg/JEllipsis'

View File

@@ -107,7 +107,7 @@
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getAction } from '@/api/manage'
import {queryMaterialCategoryTreeList} from '@/api/api'
import { getMpListShort, openDownloadDialog, sheet2blob} from "@/utils/util"
import { getMpListShort } from "@/utils/util"
import JEllipsis from '@/components/jeecg/JEllipsis'
import moment from 'moment'
import Vue from 'vue'

View File

@@ -136,7 +136,7 @@
<script>
import BillDetail from '../bill/dialog/BillDetail'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getNowFormatYear, openDownloadDialog, sheet2blob} from "@/utils/util"
import { getNowFormatYear } from "@/utils/util"
import {getAction} from '@/api/manage'
import {findBySelectOrgan, findBillDetailByNumber, getUserList, getAllOrganizationTreeByUser} from '@/api/api'
import JEllipsis from '@/components/jeecg/JEllipsis'

View File

@@ -110,7 +110,7 @@
</template>
<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getNowFormatYear, openDownloadDialog, sheet2blob} from "@/utils/util"
import { getNowFormatYear } from "@/utils/util"
import {getAction} from '@/api/manage'
import {findBySelectOrgan, getAllOrganizationTreeByUser} from '@/api/api'
import JEllipsis from '@/components/jeecg/JEllipsis'

View File

@@ -116,7 +116,7 @@
</template>
<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getNowFormatYear, getMpListShort, openDownloadDialog, sheet2blob} from "@/utils/util"
import { getNowFormatYear, getMpListShort } from "@/utils/util"
import {getAction} from '@/api/manage'
import {findBySelectRetail, getAllOrganizationTreeByUser} from '@/api/api'
import JEllipsis from '@/components/jeecg/JEllipsis'

View File

@@ -116,7 +116,7 @@
</template>
<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getNowFormatYear, getMpListShort, openDownloadDialog, sheet2blob} from "@/utils/util"
import { getNowFormatYear, getMpListShort } from "@/utils/util"
import {getAction} from '@/api/manage'
import {findBySelectCus, getAllOrganizationTreeByUser} from '@/api/api'
import JEllipsis from '@/components/jeecg/JEllipsis'

View File

@@ -77,7 +77,7 @@
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import JEllipsis from '@/components/jeecg/JEllipsis'
import {getAction} from '@/api/manage'
import { getMpListShort, openDownloadDialog, sheet2blob} from "@/utils/util"
import { getMpListShort } from "@/utils/util"
import Vue from 'vue'
export default {
name: "StockWarningReport",

View File

@@ -96,7 +96,7 @@
<script>
import DebtAccountList from './modules/DebtAccountList'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getNowFormatYear, openDownloadDialog, sheet2blob} from "@/utils/util"
import { getNowFormatYear } from "@/utils/util"
import { getAction } from '@/api/manage'
import {findBySelectSup} from '@/api/api'
import JEllipsis from '@/components/jeecg/JEllipsis'

View File

@@ -71,7 +71,6 @@
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import JEllipsis from '@/components/jeecg/JEllipsis'
import { findBillDetailByNumber } from '@/api/api'
import { openDownloadDialog, sheet2blob} from "@/utils/util"
import { mixinDevice } from '@/utils/mixin'
export default {
@@ -181,13 +180,16 @@
})
},
exportExcel() {
let aoa = [['单据编号', '类型', '条码', '名称', '仓库名称', '数量', '日期']]
let list = []
let head = '单据编号,类型,条码,名称,仓库名称,数量,日期'
for (let i = 0; i < this.dataSource.length; i++) {
let item = []
let ds = this.dataSource[i]
let item = [ds.number, ds.type, ds.barCode, ds.materialName, ds.depotName, ds.basicNumber, ds.operTime]
aoa.push(item)
item.push(ds.number, ds.type, ds.barCode, ds.materialName, ds.depotName, ds.basicNumber, ds.operTime)
list.push(item)
}
openDownloadDialog(sheet2blob(aoa), '商品库存流水')
let tip = '商品库存流水查询'
this.handleExportXlsPost('商品库存流水', '商品库存流水', head, tip, list)
}
}
}