feat: 添加上传
This commit is contained in:
parent
ceec8d07db
commit
bb9af44c94
@ -59,3 +59,14 @@ export function generateReceiptOrderNo() {
|
|||||||
method: 'get'
|
method: 'get'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function importReceipt(data) {
|
||||||
|
return request({
|
||||||
|
url: '/wms/receiptOrder/import',
|
||||||
|
method: 'post',
|
||||||
|
header: {
|
||||||
|
'Content-Type': 'multipart/form-data',
|
||||||
|
},
|
||||||
|
data: data
|
||||||
|
})
|
||||||
|
}
|
||||||
@ -62,7 +62,23 @@
|
|||||||
<el-card class="mt20">
|
<el-card class="mt20">
|
||||||
|
|
||||||
<el-row :gutter="10" class="mb8" type="flex" justify="space-between">
|
<el-row :gutter="10" class="mb8" type="flex" justify="space-between">
|
||||||
<el-col :span="6"><span style="font-size: large">入库单</span></el-col>
|
<el-col :span="21"><span style="font-size: large">入库单</span></el-col>
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-upload
|
||||||
|
ref="uploadRef"
|
||||||
|
class="upload-demo"
|
||||||
|
:auto-upload="true"
|
||||||
|
:show-file-list="false"
|
||||||
|
:limit="1"
|
||||||
|
:on-change="handleFileChange"
|
||||||
|
:on-exceed="handleExceed"
|
||||||
|
:before-upload="beforeUpload"
|
||||||
|
:http-request="customUpload"
|
||||||
|
accept=".xlsx,.xls"
|
||||||
|
>
|
||||||
|
<el-button type="primary">导入</el-button>
|
||||||
|
</el-upload>
|
||||||
|
</el-col>
|
||||||
<el-col :span="1.5">
|
<el-col :span="1.5">
|
||||||
<el-button
|
<el-button
|
||||||
type="primary"
|
type="primary"
|
||||||
@ -224,11 +240,11 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup name="ReceiptOrder">
|
<script setup name="ReceiptOrder">
|
||||||
import { listReceiptOrder, getReceiptOrder, delReceiptOrder, addReceiptOrder, updateReceiptOrder } from "@/api/wms/receiptOrder";
|
import { listReceiptOrder, getReceiptOrder, delReceiptOrder, addReceiptOrder, updateReceiptOrder, importReceipt } from "@/api/wms/receiptOrder";
|
||||||
import {getCurrentInstance, reactive, ref, toRefs} from "vue";
|
import {getCurrentInstance, reactive, ref, toRefs} from "vue";
|
||||||
import {useWmsStore} from "../../../../store/modules/wms";
|
import {useWmsStore} from "../../../../store/modules/wms";
|
||||||
import {listByReceiptOrderId} from "@/api/wms/receiptOrderDetail";
|
import {listByReceiptOrderId} from "@/api/wms/receiptOrderDetail";
|
||||||
import {ElMessageBox} from "element-plus";
|
import {ElMessageBox, ElMessage} from "element-plus";
|
||||||
import receiptPanel from "@/components/PrintTemplate/receipt-panel";
|
import receiptPanel from "@/components/PrintTemplate/receipt-panel";
|
||||||
|
|
||||||
const { proxy } = getCurrentInstance();
|
const { proxy } = getCurrentInstance();
|
||||||
@ -423,6 +439,58 @@ function ifExpand(expandedRows) {
|
|||||||
function getRowKey(row) {
|
function getRowKey(row) {
|
||||||
return row.id
|
return row.id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const uploadRef = ref(null)
|
||||||
|
const currentFile = ref(null)
|
||||||
|
|
||||||
|
// 文件上传前的校验
|
||||||
|
const beforeUpload = (file) => {
|
||||||
|
// 检查文件类型
|
||||||
|
const isExcel = file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ||
|
||||||
|
file.type === 'application/vnd.ms-excel' ||
|
||||||
|
/\.(xlsx|xls)$/i.test(file.name)
|
||||||
|
|
||||||
|
if (!isExcel) {
|
||||||
|
ElMessage.error('只能上传 Excel 文件(.xlsx 或 .xls)')
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// 文件选择变化时的处理
|
||||||
|
const handleFileChange = (file, fileList) => {
|
||||||
|
if (!file) return
|
||||||
|
currentFile.value = file.raw
|
||||||
|
}
|
||||||
|
|
||||||
|
// 超出文件限制
|
||||||
|
const handleExceed = () => {
|
||||||
|
ElMessage.warning('只能上传一个 Excel 文件,请先移除当前文件')
|
||||||
|
}
|
||||||
|
|
||||||
|
// 自定义上传方法
|
||||||
|
const customUpload = async (options) => {
|
||||||
|
const { file } = options
|
||||||
|
|
||||||
|
if (!file) {
|
||||||
|
ElMessage.error('请先选择文件')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建 FormData 对象
|
||||||
|
const formData = new FormData()
|
||||||
|
formData.append('file', file)
|
||||||
|
|
||||||
|
|
||||||
|
const res = await importReceipt(formData)
|
||||||
|
if (res.code === 200) {
|
||||||
|
ElMessage.success(res.msg)
|
||||||
|
handleQuery()
|
||||||
|
} else {
|
||||||
|
ElMessage.error(res.msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
getList();
|
getList();
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user