Commit 8f8d2d3b by chenwq

新增对账单导入模板下载功能,更新相关组件及单元测试

1 parent e7cfee60
...@@ -40,6 +40,20 @@ export function buildImportBillPayload({ billType, fileName, base64 }) { ...@@ -40,6 +40,20 @@ export function buildImportBillPayload({ billType, fileName, base64 }) {
} }
} }
export function buildImportTemplateDownloadTask(billType) {
const params = {
billType: billType,
method: "dj.api.smartcarlife.reconciliationBill.merchant.template.export.async"
}
return {
name: "对账单导入模板",
exportParam: JSON.stringify(params),
status: "waiting",
timeid: new Date().getTime()
}
}
// 轮询接口返回 100% 后才算结束,再根据失败数量判断成功或失败。 // 轮询接口返回 100% 后才算结束,再根据失败数量判断成功或失败。
export function getImportPollStatus(result = {}) { export function getImportPollStatus(result = {}) {
if (result.progress === 100 && Number(result.failNum) === 0) { if (result.progress === 100 && Number(result.failNum) === 0) {
......
...@@ -31,6 +31,9 @@ ...@@ -31,6 +31,9 @@
@change="handleFileChange" @change="handleFileChange"
/> />
</el-button> </el-button>
<el-button type="text" class="template-btn" :disabled="importing" @click="handleDownloadTemplate">
下载模板
</el-button>
<div v-if="form.fileName" class="file-name-box"> <div v-if="form.fileName" class="file-name-box">
<i class="el-icon-document"></i> <i class="el-icon-document"></i>
<span class="file-name">{{ form.fileName }}</span> <span class="file-name">{{ form.fileName }}</span>
...@@ -54,11 +57,13 @@ ...@@ -54,11 +57,13 @@
import { downLoadFile } from "@/common/util" import { downLoadFile } from "@/common/util"
import { readFileAsDataURL } from "@/libs/file" import { readFileAsDataURL } from "@/libs/file"
import { startPolling } from "@/libs/interval" import { startPolling } from "@/libs/interval"
import { mapActions, mapState } from "vuex"
import { getImportExcelProcess, importReconciliationBill } from "@api/accountManage" import { getImportExcelProcess, importReconciliationBill } from "@api/accountManage"
import { import {
IMPORT_BILL_FILE_RULE, IMPORT_BILL_FILE_RULE,
buildImportBillFormData, buildImportBillFormData,
buildImportBillPayload, buildImportBillPayload,
buildImportTemplateDownloadTask,
getImportPollStatus, getImportPollStatus,
getImportUuid, getImportUuid,
normalizeImportPollResult normalizeImportPollResult
...@@ -79,7 +84,7 @@ export default { ...@@ -79,7 +84,7 @@ export default {
fileRule: IMPORT_BILL_FILE_RULE, fileRule: IMPORT_BILL_FILE_RULE,
fileInputKey: Date.now(), fileInputKey: Date.now(),
form: { form: {
billType: "", billType: "1",
fileName: "", fileName: "",
file: null file: null
}, },
...@@ -97,7 +102,13 @@ export default { ...@@ -97,7 +102,13 @@ export default {
beforeDestroy() { beforeDestroy() {
this.stopPolling() this.stopPolling()
}, },
computed: {
...mapState({
dowloadList: state => state.d2admin.user.dowloadList
})
},
methods: { methods: {
...mapActions("d2admin/user", ["actionSetDownloadList"]),
handleClose() { handleClose() {
if (this.importing) { if (this.importing) {
this.$message.warning("正在导入中,请稍后") this.$message.warning("正在导入中,请稍后")
...@@ -148,6 +159,17 @@ export default { ...@@ -148,6 +159,17 @@ export default {
await this.submitImport() await this.submitImport()
}) })
}, },
handleDownloadTemplate() {
if (!this.form.billType) {
this.$message.warning("请先选择对账单类型")
return
}
const list = [
...this.dowloadList,
buildImportTemplateDownloadTask(this.form.billType)
]
this.actionSetDownloadList({ list, type: "dowloadList" })
},
async submitImport() { async submitImport() {
try { try {
this.importing = true this.importing = true
...@@ -230,6 +252,11 @@ export default { ...@@ -230,6 +252,11 @@ export default {
overflow: hidden; overflow: hidden;
} }
.template-btn {
margin-left: 10px;
padding: 0;
}
.file-input { .file-input {
position: absolute; position: absolute;
top: 0; top: 0;
......
...@@ -3,6 +3,7 @@ import { ...@@ -3,6 +3,7 @@ import {
IMPORT_BILL_TYPE_OPTIONS, IMPORT_BILL_TYPE_OPTIONS,
buildImportBillFormData, buildImportBillFormData,
buildImportBillPayload, buildImportBillPayload,
buildImportTemplateDownloadTask,
getImportPollStatus getImportPollStatus
} from "@/views/financeManage/accountStateManage/importBill" } from "@/views/financeManage/accountStateManage/importBill"
...@@ -45,4 +46,13 @@ describe("importBill helpers", () => { ...@@ -45,4 +46,13 @@ describe("importBill helpers", () => {
expect(getImportPollStatus({ progress: 100, failNum: 0 })).toBe("success") expect(getImportPollStatus({ progress: 100, failNum: 0 })).toBe("success")
expect(getImportPollStatus({ progress: 100, failNum: 2 })).toBe("failed") expect(getImportPollStatus({ progress: 100, failNum: 2 })).toBe("failed")
}) })
it("builds import template download task by bill type", () => {
const task = buildImportTemplateDownloadTask("1")
const exportParam = JSON.parse(task.exportParam)
expect(task.name).toBe("对账单导入模板")
expect(exportParam.billType).toBe("SHOP")
expect(exportParam.method).toBe("dj.api.smartcarlife.reconciliationBill.merchant.template.export.async")
})
}) })
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!