feat:备件信息-添加导入按钮

main
黄伟杰 2 months ago
parent fb5f085432
commit c2d05ed928

@ -71,5 +71,15 @@ export const ProductApi = {
// 导出产品 Excel
exportProduct: async (params) => {
return await request.download({ url: `/erp/product/export-excel`, params })
},
// 下载产品导入模板
importProductTemplate: async () => {
return await request.download({ url: `/erp/product/get-import-template` })
},
// 导入产品
importProduct: async (data: FormData) => {
return await request.upload({ url: `/erp/product/import`, data })
}
}

@ -31,6 +31,14 @@
>
<Icon icon="ep:plus" class="mr-5px" /> {{ t('action.add') }}
</el-button>
<el-button
type="warning"
plain
@click="openImport"
v-hasPermi="['erp:product:import']"
>
<Icon icon="ep:upload" class="mr-5px" /> {{ t('action.import') }}
</el-button>
<el-button
type="success"
plain
@ -97,6 +105,49 @@
<!-- 表单弹窗添加/修改 -->
<ProductForm ref="formRef" @success="getList" />
<Dialog v-model="importDialogVisible" :title="t('action.import')" width="400">
<el-upload
ref="uploadRef"
v-model:file-list="importFileList"
:action="importUrl + '?updateSupport=' + updateSupport"
:auto-upload="false"
:disabled="importLoading"
:headers="uploadHeaders"
:limit="1"
:on-error="handleImportError"
:on-exceed="handleImportExceed"
:on-success="handleImportSuccess"
accept=".xlsx, .xls"
drag
>
<Icon icon="ep:upload" />
<div class="el-upload__text">
将文件拖到此处或点击上传
</div>
<template #tip>
<div class="el-upload__tip text-center">
<div class="el-upload__tip">
<el-checkbox v-model="updateSupport" />
是否更新已存在的数据
</div>
<span>仅支持 .xlsx, .xls 格式</span>
<el-link
:underline="false"
style="font-size: 12px; vertical-align: baseline"
type="primary"
@click="importTemplate"
>
下载导入模板
</el-link>
</div>
</template>
</el-upload>
<template #footer>
<el-button :disabled="importLoading" type="primary" @click="submitImport">{{ t('common.ok') }}</el-button>
<el-button @click="importDialogVisible = false">{{ t('common.cancel') }}</el-button>
</template>
</Dialog>
</template>
<script setup lang="ts">
@ -108,8 +159,9 @@ import ProductForm from './ProductForm.vue'
import { DICT_TYPE } from '@/utils/dict'
import { defaultProps, handleTree } from '@/utils/tree'
import { erpPriceTableColumnFormatter } from '@/utils'
import BomForm from "@/views/mes/bom/BomForm.vue";
import {checkPermi} from "@/utils/permission";
import BomForm from '@/views/mes/bom/BomForm.vue'
import { checkPermi } from '@/utils/permission'
import { getAccessToken, getTenantId } from '@/utils/auth'
/** ERP 产品列表 */
defineOptions({ name: 'ErpProduct' })
@ -129,6 +181,15 @@ const queryParams = reactive({
const queryFormRef = ref() //
const exportLoading = ref(false) //
const importDialogVisible = ref(false)
const importLoading = ref(false)
const uploadRef = ref()
const importUrl =
import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL + '/erp/product/import'
const uploadHeaders = ref()
const importFileList = ref([])
const updateSupport = ref(0)
/** 查询列表 */
const getList = async () => {
loading.value = true
@ -188,6 +249,52 @@ const handleExport = async () => {
}
}
const openImport = () => {
importDialogVisible.value = true
importLoading.value = false
importFileList.value = []
updateSupport.value = 0
}
const submitImport = async () => {
if (importFileList.value.length === 0) {
message.error('请选择导入文件')
return
}
uploadHeaders.value = {
Authorization: 'Bearer ' + getAccessToken(),
tenantId: getTenantId()
}
importLoading.value = true
uploadRef.value?.submit()
}
const handleImportSuccess = (response: any) => {
if (!response || response.code !== 0) {
message.error(response?.msg || '导入失败')
importLoading.value = false
return
}
message.success('导入成功')
importLoading.value = false
importDialogVisible.value = false
getList()
}
const handleImportError = () => {
message.error('导入失败')
importLoading.value = false
}
const handleImportExceed = () => {
message.error('只能上传一个文件')
}
const importTemplate = async () => {
const res = await ProductApi.importProductTemplate()
download.excel(res, '产品导入模板.xls')
}
/** 初始化 **/
onMounted(async () => {
queryParams.categoryId = 2

Loading…
Cancel
Save