Commit 5cbc90f2 authored by 何远江's avatar 何远江

添加订单项次列表 文件导出

parent b6825d8f
...@@ -26,7 +26,8 @@ ...@@ -26,7 +26,8 @@
"vue": "^3.3.4", "vue": "^3.3.4",
"vue-router": "^4.2.5", "vue-router": "^4.2.5",
"vxe-table": "^4.5.13", "vxe-table": "^4.5.13",
"xe-utils": "^3.5.14" "xe-utils": "^3.5.14",
"xlsx": "^0.18.5"
}, },
"devDependencies": { "devDependencies": {
"@rushstack/eslint-patch": "^1.3.3", "@rushstack/eslint-patch": "^1.3.3",
......
import * as XLSX from 'xlsx'
import { saveAs } from 'file-saver'
export function exportExcel(data: any[], filename?: string) {
const worksheet = XLSX.utils.json_to_sheet(data)
const workbook = XLSX.utils.book_new()
XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1')
const excelBuffer = XLSX.write(workbook, { bookType: 'xlsx', type: 'array' })
const blob = new Blob([excelBuffer], { type: 'application/octet-stream' })
saveAs(blob, filename || '数据导出.xlsx')
}
...@@ -106,7 +106,7 @@ ...@@ -106,7 +106,7 @@
</template> </template>
</vxe-modal> </vxe-modal>
<TemplateVariable v-model:visible="tempVisible" v-bind="detailVariable" /> <TemplateVariable v-model:visible="tempVisible" v-bind="detailVariable" @download="download" />
</div> </div>
</template> </template>
...@@ -124,6 +124,7 @@ import TemplateVariable from './components/TemplateVariable.vue' ...@@ -124,6 +124,7 @@ import TemplateVariable from './components/TemplateVariable.vue'
import { filterRunData2 } from '@/utils/excel' import { filterRunData2 } from '@/utils/excel'
import { uploadFile } from '@/api/excel' import { uploadFile } from '@/api/excel'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import { exportExcel } from '@/utils/export-excel'
const loading = ref(false) const loading = ref(false)
const formState = reactive({ const formState = reactive({
...@@ -148,7 +149,9 @@ const detailVariable = ref({ ...@@ -148,7 +149,9 @@ const detailVariable = ref({
titles: [], titles: [],
data: [] data: []
}) })
const currentRow = ref()
const handleShowVarRun = async (row: any) => { const handleShowVarRun = async (row: any) => {
currentRow.value = row
const { data } = await apiOrderVarGetNewVars(row.orderItemId) const { data } = await apiOrderVarGetNewVars(row.orderItemId)
const { res, titles } = filterRunData2(data.result || [], false) const { res, titles } = filterRunData2(data.result || [], false)
...@@ -212,6 +215,10 @@ const submitImport = async () => { ...@@ -212,6 +215,10 @@ const submitImport = async () => {
} }
} }
const download = () => {
exportExcel(detailVariable.value.data, `${new Date().getTime()}_${currentRow.value.orderNo}.xlsx`)
}
const onReset = () => { const onReset = () => {
formState.currentPage = 1 formState.currentPage = 1
formState.productCode = '' formState.productCode = ''
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
> >
<template #default> <template #default>
<el-button type="primary" @click="download">导出</el-button>
<vxe-table ref="xTable" border :data="data" size="small" height="400"> <vxe-table ref="xTable" border :data="data" size="small" height="400">
<vxe-column v-for="column in titles" :key="item" :field="column" :title="column"></vxe-column> <vxe-column v-for="column in titles" :key="item" :field="column" :title="column"></vxe-column>
...@@ -47,7 +48,7 @@ ...@@ -47,7 +48,7 @@
default: () => [] default: () => []
} }
}, },
emits: ['update:visible'], emits: ['update:visible', 'download'],
setup(props, { emit }) { setup(props, { emit }) {
const showEdit = ref(false) const showEdit = ref(false)
const xTable = ref<VxeTableInstance>() const xTable = ref<VxeTableInstance>()
...@@ -66,11 +67,16 @@ ...@@ -66,11 +67,16 @@
emit('update:visible', false) emit('update:visible', false)
} }
const download = () => {
emit('download')
}
return { return {
showEdit, showEdit,
xTable, xTable,
tableData, tableData,
onHide, onHide,
download
} }
} }
}) })
......
This diff is collapsed.
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