Commit 8f8d2d3b by chenwq

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

1 parent e7cfee60
......@@ -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% 后才算结束,再根据失败数量判断成功或失败。
export function getImportPollStatus(result = {}) {
if (result.progress === 100 && Number(result.failNum) === 0) {
......
......@@ -31,6 +31,9 @@
@change="handleFileChange"
/>
</el-button>
<el-button type="text" class="template-btn" :disabled="importing" @click="handleDownloadTemplate">
下载模板
</el-button>
<div v-if="form.fileName" class="file-name-box">
<i class="el-icon-document"></i>
<span class="file-name">{{ form.fileName }}</span>
......@@ -54,11 +57,13 @@
import { downLoadFile } from "@/common/util"
import { readFileAsDataURL } from "@/libs/file"
import { startPolling } from "@/libs/interval"
import { mapActions, mapState } from "vuex"
import { getImportExcelProcess, importReconciliationBill } from "@api/accountManage"
import {
IMPORT_BILL_FILE_RULE,
buildImportBillFormData,
buildImportBillPayload,
buildImportTemplateDownloadTask,
getImportPollStatus,
getImportUuid,
normalizeImportPollResult
......@@ -79,7 +84,7 @@ export default {
fileRule: IMPORT_BILL_FILE_RULE,
fileInputKey: Date.now(),
form: {
billType: "",
billType: "1",
fileName: "",
file: null
},
......@@ -97,7 +102,13 @@ export default {
beforeDestroy() {
this.stopPolling()
},
computed: {
...mapState({
dowloadList: state => state.d2admin.user.dowloadList
})
},
methods: {
...mapActions("d2admin/user", ["actionSetDownloadList"]),
handleClose() {
if (this.importing) {
this.$message.warning("正在导入中,请稍后")
......@@ -148,6 +159,17 @@ export default {
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() {
try {
this.importing = true
......@@ -230,6 +252,11 @@ export default {
overflow: hidden;
}
.template-btn {
margin-left: 10px;
padding: 0;
}
.file-input {
position: absolute;
top: 0;
......
......@@ -3,6 +3,7 @@ import {
IMPORT_BILL_TYPE_OPTIONS,
buildImportBillFormData,
buildImportBillPayload,
buildImportTemplateDownloadTask,
getImportPollStatus
} from "@/views/financeManage/accountStateManage/importBill"
......@@ -45,4 +46,13 @@ describe("importBill helpers", () => {
expect(getImportPollStatus({ progress: 100, failNum: 0 })).toBe("success")
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!