|
@@ -1,61 +1,103 @@
|
|
|
<template>
|
|
|
<div class="white pa-3">
|
|
|
- <m-card shadow="never" class="content pa-3">
|
|
|
- <m-form ref="form" :items="formItems" v-model="query" label-width="300px">
|
|
|
- <template v-for="item in items" #[item.prop]>
|
|
|
+ <m-search :items="searchItems" v-model="searchValues" class="mb-3" @search="onSearch">
|
|
|
+ <template #button>
|
|
|
+ <m-button type="primary" plain @click="onSave">提交所有临时文件</m-button>
|
|
|
+ </template>
|
|
|
+ </m-search>
|
|
|
+ <m-table
|
|
|
+ :headers="headers"
|
|
|
+ :items="items"
|
|
|
+ :loading="loading"
|
|
|
+ >
|
|
|
+ <template #month>
|
|
|
+ {{ searchValues.month }}
|
|
|
+ </template>
|
|
|
+ <template #file="{ row }">
|
|
|
+ {{ filesValues[row.fileType]?.name }}
|
|
|
+ </template>
|
|
|
+ <template #actions="{ row }">
|
|
|
+ <div class="d-flex">
|
|
|
<el-upload
|
|
|
- :key="item.prop"
|
|
|
- :ref="item.prop"
|
|
|
+ class="mr-3"
|
|
|
action="#"
|
|
|
:limit="1"
|
|
|
- :file-list="query[item.prop] ? [query[item.prop]] : []"
|
|
|
- :on-exceed="(files, fileList) => onExceed(files, fileList, item.prop)"
|
|
|
- :http-request="e => onImport(e, item.prop)"
|
|
|
- :on-remove="() => onRemove(item.prop)"
|
|
|
+ :show-file-list="false"
|
|
|
+ :on-exceed="(files, fileList) => onExceed(files, fileList, row.fileType)"
|
|
|
+ :http-request="e => onImport(e, row.fileType)"
|
|
|
+ :on-remove="() => onRemove(row.fileType)"
|
|
|
>
|
|
|
- <m-button slot="trigger" size="small" type="primary" plain>点击上传</m-button>
|
|
|
+ <m-button slot="trigger" text type="primary" @click="onUpdate(row)">更新文件</m-button>
|
|
|
</el-upload>
|
|
|
- </template>
|
|
|
- <el-form-item>
|
|
|
- <m-button icon="el-icon-check" type="primary" size="small" @click="onSave">提交</m-button>
|
|
|
- <m-button icon="el-icon-s-promotion" type="primary" size="small">绩效计算</m-button>
|
|
|
- <m-button icon="el-icon-time" type="primary" size="small">绩效计算历史记录</m-button>
|
|
|
- </el-form-item>
|
|
|
- </m-form>
|
|
|
- </m-card>
|
|
|
+ <m-button text type="danger" v-show="filesValues[row.fileType]" @click="onDelete(row)">移除临时文件</m-button>
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ </m-table>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
import {
|
|
|
getSalaryCalculateTemplate,
|
|
|
- uploadSalaryCalculateFiles
|
|
|
+ uploadSalaryCalculateFiles,
|
|
|
+ getSalaryCalculateFiles
|
|
|
} from '@/api/salary'
|
|
|
+import { dateFormat } from '@/utils/date'
|
|
|
export default {
|
|
|
name: 'salary-calculate',
|
|
|
data () {
|
|
|
return {
|
|
|
- query: {
|
|
|
- month: null
|
|
|
+ searchValues: {
|
|
|
+ month: dateFormat('YYYY-mm', new Date()),
|
|
|
+ category: null
|
|
|
},
|
|
|
- items: []
|
|
|
+ filesValues: {},
|
|
|
+ categoryItems: [],
|
|
|
+ historyItems: [],
|
|
|
+ formItems: [],
|
|
|
+ headers: [
|
|
|
+ { label: '月份', prop: 'month' },
|
|
|
+ { label: '业务线', prop: 'category' },
|
|
|
+ { label: '文件', prop: 'history' },
|
|
|
+ { label: '临时文件', prop: 'file' },
|
|
|
+ { label: '操作', prop: 'actions' }
|
|
|
+ ],
|
|
|
+ loading: false
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
|
- formItems () {
|
|
|
+ items () {
|
|
|
+ return this.categoryItems.find(e => e.category === this.searchValues.category)?.files ?? []
|
|
|
+ },
|
|
|
+ searchItems () {
|
|
|
return [
|
|
|
{
|
|
|
label: '月份',
|
|
|
prop: 'month',
|
|
|
type: 'datePicker',
|
|
|
options: {
|
|
|
+ clearable: false,
|
|
|
type: 'month',
|
|
|
format: 'yyyy-MM',
|
|
|
valueFormat: 'yyyy-MM',
|
|
|
placeholder: '选择更新月份'
|
|
|
}
|
|
|
},
|
|
|
- ...this.items
|
|
|
+ {
|
|
|
+ label: '业务线',
|
|
|
+ prop: 'category',
|
|
|
+ type: 'select',
|
|
|
+ options: {
|
|
|
+ clearable: false,
|
|
|
+ placeholder: '选择业务线',
|
|
|
+ items: this.categoryItems.map(e => {
|
|
|
+ return {
|
|
|
+ label: e.category,
|
|
|
+ value: e.category
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
]
|
|
|
}
|
|
|
},
|
|
@@ -66,43 +108,102 @@ export default {
|
|
|
async onInit () {
|
|
|
try {
|
|
|
const { data } = await getSalaryCalculateTemplate()
|
|
|
- this.items = data.map(e => {
|
|
|
- this.$set(this.query, e.fileType, null)
|
|
|
- return {
|
|
|
- label: e.fileName,
|
|
|
- prop: e.fileType,
|
|
|
- rules: [
|
|
|
- { required: true, message: '请上传文件', trigger: 'change' }
|
|
|
- ]
|
|
|
- }
|
|
|
- })
|
|
|
+ this.categoryItems = data
|
|
|
+ if (!data.length) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ this.searchValues.category = data[0].category
|
|
|
+ this.onChange()
|
|
|
+ this.onGetHistory()
|
|
|
+ } catch (error) {
|
|
|
+ this.$message.error(error)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async onGetHistory () {
|
|
|
+ try {
|
|
|
+ const { data } = await getSalaryCalculateFiles(this.searchValues)
|
|
|
+ console.log(data)
|
|
|
} catch (error) {
|
|
|
this.$message.error(error)
|
|
|
}
|
|
|
},
|
|
|
- onExceed (files, fileList, ref) {
|
|
|
- this.query[ref] = files[0]
|
|
|
+ onSearch (query) {
|
|
|
+ if (!query.category) {
|
|
|
+ this.searchValues.category = this.categoryItems[0].category
|
|
|
+ }
|
|
|
+ this.onChange()
|
|
|
+ this.onGetHistory()
|
|
|
+ },
|
|
|
+ onChange () {
|
|
|
+ const items = this.categoryItems.find(e => e.category === this.searchValues.category)?.files ?? []
|
|
|
+ debugger
|
|
|
+ if (!items.length) {
|
|
|
+ this.filesValues = {}
|
|
|
+ return
|
|
|
+ }
|
|
|
+ this.filesValues = {
|
|
|
+ ...items.reduce((res, v) => {
|
|
|
+ res[v.fileType] = null
|
|
|
+ return res
|
|
|
+ }, {})
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onExceed (files, fileList, key) {
|
|
|
+ this.filesValues[key] = files[0]
|
|
|
},
|
|
|
onImport (e, key) {
|
|
|
- this.query[key] = e.file
|
|
|
+ this.filesValues[key] = e.file
|
|
|
},
|
|
|
onRemove (key) {
|
|
|
- this.query[key] = null
|
|
|
- console.log(this.query)
|
|
|
+ this.filesValues[key] = null
|
|
|
+ },
|
|
|
+ onUpdate () {},
|
|
|
+ onDelete (row) {
|
|
|
+ this.filesValues[row.fileType] = null
|
|
|
},
|
|
|
async onSave () {
|
|
|
- try {
|
|
|
- const { data } = await uploadSalaryCalculateFiles()
|
|
|
- console.log(data)
|
|
|
- } catch (error) {
|
|
|
- this.$snackbar.error(error)
|
|
|
+ if (Object.values(this.filesValues).every(e => e === null)) {
|
|
|
+ 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', { style: 'color: red' }, '上传文件后,将覆盖之前的文件,请谨慎操作!')
|
|
|
+ ]), '提示', {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'warning'
|
|
|
+ }).then(async () => {
|
|
|
+ try {
|
|
|
+ const obj = Object.keys(this.filesValues).reduce((res, key) => {
|
|
|
+ if (!this.filesValues[key]) {
|
|
|
+ return res
|
|
|
+ }
|
|
|
+ res.files.push(this.filesValues[key])
|
|
|
+ res.fileTypes.push(key)
|
|
|
+ return res
|
|
|
+ }, { files: [], fileTypes: [] })
|
|
|
+ const { data } = await uploadSalaryCalculateFiles({
|
|
|
+ ...obj,
|
|
|
+ ...this.searchValues
|
|
|
+ })
|
|
|
+ console.log(data)
|
|
|
+ } catch (error) {
|
|
|
+ this.$snackbar.error(error)
|
|
|
+ }
|
|
|
+ }).catch(_ => {})
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
+.d-flex {
|
|
|
+ display: flex;
|
|
|
+}
|
|
|
.content {
|
|
|
width: 50%;
|
|
|
min-width: 500px;
|