<template>
|
<el-dialog v-model="isShow" title="导入库存" @close="closeModal">
|
<FileUpload
|
ref="fileUploadRef"
|
accept=".xlsx, .xls"
|
:headers="upload.headers"
|
:action="upload.url"
|
:disabled="upload.isUploading"
|
:showTip="true"
|
@success="handleFileSuccess"
|
:downloadTemplate="downloadTemplate"
|
/>
|
<template #footer>
|
<div class="dialog-footer">
|
<el-button type="primary" @click="submitFileForm">确 定</el-button>
|
<el-button @click="closeModal">取 消</el-button>
|
</div>
|
</template>
|
</el-dialog>
|
</template>
|
|
<script setup>
|
import {computed, getCurrentInstance, reactive} from "vue";
|
import { getToken } from "@/utils/auth.js";
|
import { FileUpload } from "@/components/Upload";
|
import { ElMessage } from "element-plus";
|
|
defineOptions({
|
name: "导入库存",
|
});
|
|
const { proxy } = getCurrentInstance()
|
|
const props = defineProps({
|
visible: {
|
type: Boolean,
|
required: true,
|
},
|
|
type: {
|
type: String,
|
required: true,
|
default: 'qualified',
|
},
|
});
|
|
const emit = defineEmits(['update:visible', 'uploadSuccess']);
|
|
|
const isShow = computed({
|
get() {
|
return props.visible;
|
},
|
set(val) {
|
emit('update:visible', val);
|
},
|
});
|
|
const fileUploadRef = ref();
|
const upload = reactive({
|
// 是否显示弹出层(库存导入)
|
open: false,
|
// 是否禁用上传
|
isUploading: false,
|
// 设置上传的请求头部
|
headers: { Authorization: "Bearer " + getToken() },
|
// 上传的地址
|
url: import.meta.env.VITE_APP_BASE_API + "/stockInventory/importStockInventory",
|
});
|
|
const submitFileForm = () => {
|
fileUploadRef.value.uploadApi();
|
};
|
|
const handleFileSuccess = (response) => {
|
const { code, msg } = response;
|
if (code == 200) {
|
ElMessage({ message: "导入成功", type: "success" });
|
emit('uploadSuccess');
|
closeModal();
|
} else {
|
ElMessage({ message: msg, type: "error" });
|
}
|
};
|
|
const downloadTemplate = () => {
|
proxy.download("/stockInventory/downloadStockInventory", {}, "库存导入模板.xlsx");
|
}
|
|
const closeModal = () => {
|
isShow.value = false;
|
};
|
</script>
|