diff --git a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/components/table/index.js b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/components/table/index.js index 07222ad5..c5ad74f5 100644 --- a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/components/table/index.js +++ b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/components/table/index.js @@ -17,15 +17,13 @@ export default {
{{item.title}}
-
- +
{{row[item.dataKey]}}
+
`, styles: html``, setup() { const fileList = ref([]); - // const load = async () => {}; - // const editFormModel = ref(null); - // const editFormMode = ref(null); - // const defaultImportModel = config.import?.schema ? schemaToModel(config.import.schema) : {}; - // const importModel = ref(defaultImportModel); const openImportHandler = async () => { const url = "settleaccount/vmi/excel-to-json"; const method = "POST"; @@ -306,11 +326,12 @@ export default { }); // const setupRef = ref(1); + const scrollRef = ref(null); const adjListRef = ref(null); const adjList = ref([]); const showSetupDialog = () => { adjList.value = []; - for (let i = 0; i < 100; i++) { + for (let i = 0; i < 10; i++) { adjList.value.push({ invBillNum: i }); } setupRef.value = 1; @@ -318,8 +339,15 @@ export default { }; const deleteAdj = () => { const list = adjListRef.value.getSelection(); - list.forEach((o) => adjList.value.splice(o, 1)); - adjListRef.value.clearSelection(); + if (list.length > 0) { + for (let i = 0; i < list.length; i++) { + adjList.value.splice(list[i] - i, 1); + } + nextTick(() => { + adjListRef.value.clearSelection(); + scrollRef.value.update(); + }); + } }; const adjSchema = { type: "object", @@ -361,24 +389,69 @@ export default { const defaultAdjModel = schemaToModel(adjSchema); const adjModel = ref(Object.assign({}, defaultAdjModel)); const addAdjFormRef = ref(null); - const addAdj = () => { + const showAddAdjDialog = () => { adjModel.value = Object.assign({}, defaultAdjModel); addDialogVisible.value = true; }; - const submitAdj = async () => { + const addAdj = async () => { try { const valid = await addAdjFormRef.value.validate(); if (valid) { - adjList.value.unshift(JSON.parse(JSON.stringify(adjModel.value))); + adjList.value.unshift(adjModel.value); addDialogVisible.value = false; } } catch (error) { console.log(error); } }; - const importAdj = async () => { + const importAdjFromRef = ref(null); + const importAdjSchema = { + type: "object", + properties: { + files: { + title: "文件", + type: "array", + multiple: true, + input: "file", + accept: ".xlsx", + default: [], + limit: 1, + size: 100 * 1024 * 1024, + rules: [ + { + required: true, + trigger: "change", + }, + ], + }, + }, + }; + const defaultImportAdjModel = schemaToModel(importAdjSchema); + const importAdjModel = ref(defaultImportAdjModel); + const showImportAdjDialog = async () => { + importAdjModel.value = Object.assign({}, defaultImportAdjModel); importDialogVisible.value = true; }; + const importAdj = async () => { + try { + const valid = await importAdjFromRef.value.validate(); + if (valid) { + loading.value = true; + const url = "settleaccount/vmi/excel-to-json"; + const formData = new FormData(); + formData.append("files", importAdjModel.value.files[0].raw); + const result = await request(url, formData); + if (!result.errors) { + adjList.value = result.data; + importDialogVisible.value = false; + } + } + } catch (error) { + console.log(error); + } finally { + loading.value = false; + } + }; return { config, onCommand, @@ -402,12 +475,17 @@ export default { adjList, adjListRef, deleteAdj, + showAddAdjDialog, addAdj, - submitAdj, addAdjFormRef, + importAdjFromRef, adjSchema, adjModel, + showImportAdjDialog, + importAdjModel, + importAdjSchema, importAdj, + scrollRef, }; }, };