|
@@ -1,17 +1,22 @@
|
|
|
<template>
|
|
|
<div class="white pa-3">
|
|
|
<m-search :items="searchItems" v-model="searchValues" class="mb-3" @search="onSearch">
|
|
|
- <template #button>
|
|
|
+ <!-- <template #button>
|
|
|
<m-button type="primary" plain @click="onSave">提交所有临时文件</m-button>
|
|
|
- </template>
|
|
|
+ </template> -->
|
|
|
</m-search>
|
|
|
<m-table
|
|
|
:headers="headers"
|
|
|
:items="items"
|
|
|
- :loading="loading"
|
|
|
+ v-loading="loading"
|
|
|
>
|
|
|
+ <template #header>
|
|
|
+ <div class="header">
|
|
|
+ <m-button size="small" type="primary" icon="el-icon-finished" :loading="submitLoading" @click="onSave">提交当前临时文件</m-button>
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
<template #month>
|
|
|
- {{ searchValues.month }}
|
|
|
+ {{ queryValues.month }}
|
|
|
</template>
|
|
|
<template #file="{ row }">
|
|
|
{{ filesValues[row.fileType]?.name }}
|
|
@@ -27,7 +32,7 @@
|
|
|
:http-request="e => onImport(e, row.fileType)"
|
|
|
:on-remove="() => onRemove(row.fileType)"
|
|
|
>
|
|
|
- <m-button slot="trigger" text type="primary" @click="onUpdate(row)">更新文件</m-button>
|
|
|
+ <m-button slot="trigger" text type="primary">导入文件</m-button>
|
|
|
</el-upload>
|
|
|
<m-button text type="danger" v-show="filesValues[row.fileType]" @click="onDelete(row)">移除临时文件</m-button>
|
|
|
</div>
|
|
@@ -51,23 +56,35 @@ export default {
|
|
|
month: dateFormat('YYYY-mm', new Date()),
|
|
|
category: null
|
|
|
},
|
|
|
+ queryValues: {},
|
|
|
filesValues: {},
|
|
|
categoryItems: [],
|
|
|
historyItems: [],
|
|
|
formItems: [],
|
|
|
headers: [
|
|
|
- { label: '月份', prop: 'month' },
|
|
|
+ { label: '月份', prop: 'month', width: 100 },
|
|
|
{ label: '业务线', prop: 'category' },
|
|
|
+ { label: '文件名', prop: 'fileName' },
|
|
|
{ label: '文件', prop: 'history' },
|
|
|
{ label: '临时文件', prop: 'file' },
|
|
|
{ label: '操作', prop: 'actions' }
|
|
|
],
|
|
|
- loading: false
|
|
|
+ loading: false,
|
|
|
+ submitLoading: false
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
|
items () {
|
|
|
- return this.categoryItems.find(e => e.category === this.searchValues.category)?.files ?? []
|
|
|
+ const items = this.categoryItems.find(e => e.category === this.queryValues.category)?.files
|
|
|
+ if (!items) {
|
|
|
+ return []
|
|
|
+ }
|
|
|
+ return items.map(e => {
|
|
|
+ return {
|
|
|
+ ...e,
|
|
|
+ history: this.historyItems.find(h => h.fileType === e.fileType)?.fileOriginalFilename
|
|
|
+ }
|
|
|
+ })
|
|
|
},
|
|
|
searchItems () {
|
|
|
return [
|
|
@@ -113,6 +130,7 @@ export default {
|
|
|
return
|
|
|
}
|
|
|
this.searchValues.category = data[0].category
|
|
|
+ this.queryValues = { ...this.searchValues }
|
|
|
this.onChange()
|
|
|
this.onGetHistory()
|
|
|
} catch (error) {
|
|
@@ -121,22 +139,24 @@ export default {
|
|
|
},
|
|
|
async onGetHistory () {
|
|
|
try {
|
|
|
- const { data } = await getSalaryCalculateFiles(this.searchValues)
|
|
|
- console.log(data)
|
|
|
+ this.loading = true
|
|
|
+ const { data } = await getSalaryCalculateFiles(this.queryValues)
|
|
|
+ this.historyItems = data
|
|
|
} catch (error) {
|
|
|
this.$message.error(error)
|
|
|
+ } finally {
|
|
|
+ this.loading = false
|
|
|
}
|
|
|
},
|
|
|
onSearch (query) {
|
|
|
if (!query.category) {
|
|
|
- this.searchValues.category = this.categoryItems[0].category
|
|
|
+ this.searchValues.category = this.categoryItems[0]?.category ?? null
|
|
|
}
|
|
|
- this.onChange()
|
|
|
+ this.queryValues = { ...this.searchValues }
|
|
|
this.onGetHistory()
|
|
|
},
|
|
|
onChange () {
|
|
|
- const items = this.categoryItems.find(e => e.category === this.searchValues.category)?.files ?? []
|
|
|
- debugger
|
|
|
+ const items = this.categoryItems.find(e => e.category === this.queryValues.category)?.files ?? []
|
|
|
if (!items.length) {
|
|
|
this.filesValues = {}
|
|
|
return
|
|
@@ -157,7 +177,6 @@ export default {
|
|
|
onRemove (key) {
|
|
|
this.filesValues[key] = null
|
|
|
},
|
|
|
- onUpdate () {},
|
|
|
onDelete (row) {
|
|
|
this.filesValues[row.fileType] = null
|
|
|
},
|
|
@@ -166,33 +185,37 @@ export default {
|
|
|
this.$message.warning('请先上传文件')
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
const h = this.$createElement
|
|
|
this.$confirm(h('div', [
|
|
|
h('p', undefined, '确定要更新文件吗?'),
|
|
|
- h('p', undefined, `更新月份:${this.searchValues.month}`),
|
|
|
- h('p', undefined, `更新物业线:${this.searchValues.category}`),
|
|
|
+ h('p', undefined, `更新月份:${this.queryValues.month}`),
|
|
|
+ h('p', undefined, `更新物业线:${this.queryValues.category}`),
|
|
|
h('p', { style: 'color: red' }, '上传文件后,将覆盖之前的文件,请谨慎操作!')
|
|
|
]), '提示', {
|
|
|
confirmButtonText: '确定',
|
|
|
cancelButtonText: '取消',
|
|
|
type: 'warning'
|
|
|
}).then(async () => {
|
|
|
+ this.submitLoading = true
|
|
|
try {
|
|
|
- const obj = Object.keys(this.filesValues).reduce((res, key) => {
|
|
|
+ const formData = new FormData()
|
|
|
+ Object.keys(this.filesValues).forEach(key => {
|
|
|
if (!this.filesValues[key]) {
|
|
|
- return res
|
|
|
+ return
|
|
|
}
|
|
|
- res.files.push(this.filesValues[key])
|
|
|
- res.fileTypes.push(key)
|
|
|
- return res
|
|
|
- }, { files: [], fileTypes: [] })
|
|
|
- const { data } = await uploadSalaryCalculateFiles({
|
|
|
- ...obj,
|
|
|
- ...this.searchValues
|
|
|
+ formData.append('files', this.filesValues[key])
|
|
|
+ formData.append('fileTypes', key)
|
|
|
})
|
|
|
- console.log(data)
|
|
|
+ formData.append('month', this.queryValues.month)
|
|
|
+ formData.append('category', this.queryValues.category)
|
|
|
+ await uploadSalaryCalculateFiles(formData)
|
|
|
+ this.$message.success('保存成功')
|
|
|
+ this.onGetHistory()
|
|
|
} catch (error) {
|
|
|
- this.$snackbar.error(error)
|
|
|
+ this.$message.error(error)
|
|
|
+ } finally {
|
|
|
+ this.submitLoading = false
|
|
|
}
|
|
|
}).catch(_ => {})
|
|
|
}
|
|
@@ -220,4 +243,8 @@ export default {
|
|
|
content: '移除';
|
|
|
}
|
|
|
}
|
|
|
+.header {
|
|
|
+ display: flex;
|
|
|
+ justify-content: flex-end;
|
|
|
+}
|
|
|
</style>
|