Browse Source

YT-170:客户模具分摊对账单导入接口以及校验接口

syhx
songguoqiang 1 month ago
parent
commit
ae51e4faa6
  1. 12
      src/api/wms/customerStatementMain/index.ts
  2. 427
      src/components/ImportForm/src/ImportCustomerStatementShareForm.vue

12
src/api/wms/customerStatementMain/index.ts

@ -57,7 +57,7 @@ export const exportCustomerStatementMain = async (params) => {
return await request.download({ url: `/wms/customer-statement-main/export-excel`, params }) return await request.download({ url: `/wms/customer-statement-main/export-excel`, params })
} }
// 下载用户导入模板 // 下载客户对账单导入模板
export const importTemplate = () => { export const importTemplate = () => {
return request.download({ url: '/wms/customer-statement-main/get-import-template' }) return request.download({ url: '/wms/customer-statement-main/get-import-template' })
} }
@ -86,3 +86,13 @@ export const nodeAbrogate = async (id: number) => {
export const sendBack = async (id: number) => { export const sendBack = async (id: number) => {
return await request.get({ url: `/wms/customer-statement-main/sendBack?id=` + id}) return await request.get({ url: `/wms/customer-statement-main/sendBack?id=` + id})
} }
// 导入客户模具分摊对账单前校验该客户对账单下是否存在已分摊的模具分摊对账单如果有提示
export const verifyDataExistShare = async (customerId:number) => {
return await request.get({ url: `/wms/customer-tool-apport-statement-detail/verifyDataExist?customerId=` + customerId })
}
// 下载客户模具分摊对账单导入模板
export const importShareTemplate = () => {
return request.download({ url: '/wms/customer-tool-apport-statement-detail/get-import-template' })
}

427
src/components/ImportForm/src/ImportCustomerStatementShareForm.vue

@ -0,0 +1,427 @@
<!-- 导入客户模具分摊对账单组件 -->
<template>
<Dialog v-model="dialogVisible" :title="t('ts.导入')" width="600" :close-on-click-modal="false">
<el-upload
ref="uploadRef"
v-model:file-list="fileList"
:action="
importUrl +
'?customerId=' +
props.importTemplateData.customerId +
'&file=' +
file +
'&updatePart=' +
updatePart +
'&outFile=' +
outFile +
'&extend=' + extend +
'&fromInventoryStatus=' + fromInventoryStatus +
'&toInventoryStatus=' + toInventoryStatus +
dataType
"
:auto-upload="false"
:disabled="formLoading"
:headers="uploadHeaders"
:limit="1"
:on-error="submitFormError"
:on-exceed="handleExceed"
:on-success="submitFormSuccess"
:accept="accept"
drag
style="width: 300px; margin: 0 auto"
v-loading="formLoading"
>
<Icon icon="ep:upload-filled" color="#c0c4cc" :size="60" />
<div class="el-upload__text">{{t('ts.将文件拖到此处,或')}}<em>{{t('ts.点击上传')}}</em></div>
<!-- <template #tip>
<div class="el-upload__tip ml--126px mr--80px">
<div class="flex" v-if="announcements&&announcements.length>0">
<div
class="label h-32px ml-22px mr-26px color-#acaeb3 font-size-14px w-100px text-right mt-2px"
style="line-height: 32px;"
>{{t('ts.注意事项')}}</div
>
<div class="">
<div class="notice color-#acaeb3 font-size-14px text-red">
<div class="mt-2" v-for="item in announcements">{{ item }}</div>
</div>
</div>
</div>
<div class="flex">
<div
class="label h-32px mr-26px color-#acaeb3 font-size-14px w-100px text-right"
style="line-height: 32px"
>{{t('ts.导入模式')}}</div
>
<div class="">
<div class="radio">
<el-radio-group v-model="mode">
<el-radio :label="1" v-show="updateIsShow" :disabled="updateIsDisable">{{ t('ts.更新')}}</el-radio>
<el-radio :label="2" v-show="appendIsShow" :disabled="appendIsDisable">{{ t('ts.追加') }}</el-radio>
<el-radio :label="3" v-show="coverIsShow" :disabled="coverIsDisable">{{ t('ts.覆盖') }}</el-radio>
</el-radio-group>
</div>
<div class="tips color-#acaeb3 font-size-14px">
<div class="mt-2">{{t('ts.更新:新增并修改')}}</div>
<div class="mt-2">{{ t('ts.追加:只新增,不修改') }}</div>
<div class="mt-2">{{ t('ts.覆盖:只修改不新增') }}</div>
</div>
</div>
</div>
<div class="flex mt-16px">
<div
class="label h-32px mr-26px color-#acaeb3 font-size-14px w-100px text-right"
style="line-height: 32px"
>{{ t('ts.部分保存') }}</div
>
<div class="">
<div class="switch">
<el-switch v-model="updatePart" />
</div>
<div class="tips color-#acaeb3 font-size-14px">
<div class="mt-2">{{ t('ts.部分保存:如存在错误数据,正确数据正常导入') }}</div>
<div class="mt-2">{{ t('ts.全部保存:全部数据正确,才能导入') }}</div>
</div>
</div>
</div>
<div class="flex mt-16px" v-if="isShowOut">
<div
class="label h-32px mr-26px color-#acaeb3 font-size-14px w-100px text-right"
style="line-height: 32px"
>是否外部资源</div
>
<div class="">
<div class="switch">
<el-switch v-model="outFile" />
</div>
</div>
</div>
</div>
</template> -->
</el-upload>
<template #footer>
<div class="flex items-center">
<div class="flex-1 text-left">
<el-button type="primary" plain @click="importTemplate">
<Icon icon="ep:download" />
{{ t('ts.下载模板') }}
</el-button>
</div>
<el-button :disabled="formLoading" type="primary" @click="verifyData">{{ t('ts.确 ') }}</el-button>
<el-button @click="dialogVisible = false">{{ t('ts.取 消') }}</el-button>
</div>
</template>
</Dialog>
</template>
<script lang="ts" setup>
import { getAccessToken, getTenantId } from '@/utils/auth'
import download from '@/utils/download'
import { getBaseUrl } from '@/utils/systemParam'
import * as CustomerApi from '@/api/wms/customer'
import * as CustomerStatementMainApi from '@/api/wms/customerStatementMain'
defineOptions({ name: 'ImportForm' })
const { t } = useI18n()
const message = useMessage() //
const dialogVisible = ref(false) //
const formLoading = ref(false) //
const uploadRef = ref()
const uploadHeaders = ref() // Header
const fileList = ref([]) //
const file = ref('')
const props = defineProps({
importTemplateData: {
type: Object,
required: true
},
//
accept: {
type: String,
required: false,
default: '.xlsx,.xls'
},
// .1
mode: {
type: Number,
required: false,
default: 1
},
// ,
updateIsDisable: {
type: Boolean,
required: false,
default: false
},
//
updateIsShow: {
type: Boolean,
required: false,
default: true
},
// ,
appendIsDisable: {
type: Boolean,
required: false,
default: false
},
//
appendIsShow: {
type: Boolean,
required: false,
default: true
},
// ,
coverIsDisable: {
type: Boolean,
required: false,
default: false
},
//
coverIsShow: {
type: Boolean,
required: false,
default: true
},
// ,
updatePart: {
type: Boolean,
required: false,
default: false
},
url: {
type: String,
required: false
},
//
isShowOut: {
type: Boolean,
required: false,
default: false
},
outFile: {
type: Boolean,
required: false,
default: false
},
//
extend: {
type: String,
required: false,
default: ''
},
// TODO: cxm
fromInventoryStatus: {
type: String,
required: false,
default: ''
},
// TODO: cxm
toInventoryStatus: {
type: String,
required: false,
default: ''
},
announcements:{
type: Array,
required: false,
default: []
}
})
const importTemplateData = ref(props.importTemplateData)
console.log(333,props.importTemplateData.dataType)
const dataType = ref('')
dataType.value = props.importTemplateData.dataType ?'&dataType=' + props.importTemplateData.dataType :''
const accept = ref(props.accept)
const mode = ref(props.mode) //.1
const updateIsDisable = ref(props.updateIsDisable) //,
const appendIsDisable = ref(props.appendIsDisable) //,
const coverIsDisable = ref(props.coverIsDisable) //,
const updatePart = ref(props.updatePart) //
const outFile = ref(props.outFile) //
const importUrl = getBaseUrl() + import.meta.env.VITE_API_URL + props.url
/** 打开弹窗 */
const open = () => {
dialogVisible.value = true
resetForm()
getCustomerList();//
}
defineExpose({ open }) // open
/** 校验数据 */
const verifyData = async () => {
if (fileList.value.length == 0) {
message.error('请上传文件')
return
}
const data = await CustomerStatementMainApi.verifyDataExistShare(props.importTemplateData.customerId);
console.log('data',data)
if(data.status==0){
submitForm();
}else if(data.status==2){
try {
//
await message.confirm('已存在相同客户编号及年月的对账单,是否确认导入?注意:如确认则上一版本对账单将自动作废。')
//
submitForm();
// await PurchasepriceApi.deletePurchaseprice(id)
// tableObject.loading = false
// message.success(t('common.delSuccess'))
// //
// buttonBaseClick('refresh',null)
} catch {
//
alert(123);
}
}else if(data.status==3){
await message.alertWarning('已存在相同客户编号及年月的对账单,且已确认分摊金额,无法导入')
}
}
/** 提交表单 */
const submitForm = async () => {
if (fileList.value.length == 0) {
message.error('请上传文件')
return
}
file.value = fileList.value[0].name
//
uploadHeaders.value = {
Authorization: 'Bearer ' + getAccessToken(),
'tenant-id': getTenantId()
}
formLoading.value = true
uploadRef.value!.submit()
}
/** 文件上传成功 */
const emits = defineEmits(['success'])
const submitFormSuccess = (response: any) => {
formLoading.value = true
console.log(response)
if (response) {
if (response.code == 500) {
uploadRef.value!.clearFiles()
message.error('导入失败')
formLoading.value = false
return
} else if (response.code == 0) {
if (response.data.errorCount > 0) {
message.confirm('文件中有部分数据导入失败,是否下载失败数据?').then(() => {
// download.excel(file, 'file_' + new Date().getTime())
// url
// const downloadElement = document.createElement('a')
// console.log(172, getBaseUrl() + import.meta.env.VITE_API_URL + '/' + response.data.errorFile)
// console.log(172, getBaseUrl() + '/admin-api/opt/profile/' + response.data.errorFile)
window.open(
getBaseUrl() + '/admin-api' + response.data.errorFile,
'222'
)
// downloadElement.setAttribute('href', getBaseUrl() + import.meta.env.VITE_API_URL + response.data.errorFile )
//
// downloadElement.click()
})
} else {
message.success('导入成功')
}
}else if(response.data == null){
message.error(response.msg)
}
}
// if (response.code !== 0) {
// message.error(response.msg)
// formLoading.value = false
// return
// }
// //
// const data = response.data
// const create = response.data.importResult[0]
// const update = response.data.importResult[1]
// const failure = response.data.importResult[2]
// let text = '' + data[create].length + ';'
// for (let name of data[create]) {
// text += '< ' + name + ' >'
// }
// text += '' + data[update].length + ';'
// for (const name of data[update]) {
// text += '< ' + name + ' >'
// }
// text += '' + Object.keys(data[failure]).length + ';'
// for (const name in data[failure]) {
// text += '< ' + name + ': ' + data[failure][name] + ' >'
// }
// message.alert(text)
//
formLoading.value = false
emits('success')
dialogVisible.value = false
}
/** 上传错误提示 */
const submitFormError = (): void => {
message.error('上传失败,请您重新上传!')
formLoading.value = false
}
/** 重置表单 */
const resetForm = () => {
//
formLoading.value = false
uploadRef.value?.clearFiles()
fileList.value = []
}
/** 文件数超出提示 */
const handleExceed = (): void => {
message.error('最多只能上传一个文件!')
}
/** 下载模板操作 */
const importTemplate = () => {
const res = importTemplateData.value.templateUrl
download.excel(res, importTemplateData.value.templateTitle)
}
const customerList = ref();
const queryParams = reactive({
customerCode: '',
yearsMonthStr: '',
})
const getCustomerList = async () => {//
var param ={}
const list = await CustomerApi.getCustomerList(param);
customerList.value = list;
}
</script>
<style scoped lang="scss">
.text-red{
color: var(--el-color-danger);
}
.tips {
div {
position: relative;
padding-left: 22px;
&::before {
width: 4px;
height: 4px;
border-radius: 50%;
content: '';
background: #c2c2c2;
position: absolute;
top: 50%;
margin-top: -2px;
left: 4px;
}
}
}
</style>
Loading…
Cancel
Save