linweizeng 2 лет назад
Родитель
Сommit
0f4976b132

+ 74 - 21
src/business/platform/form/formrender/dynamic-form/dynamic-form-table.vue

@@ -120,7 +120,7 @@
         <!--按钮支持自定义对话框-->
         <custom-dialog :visible="customDialogVisible" :value="[]" :template-key="customDialogKey" :dynamic-params="customDialogDynamicParams" @close="(visible) => (customDialogVisible = visible)" @action-event="handleCustomDialogActionEvent" />
 
-        <import-table :visible="importTableDialogVisible" :title="field.label" @close="(visible) => (importTableDialogVisible = visible)" @action-event="handleImportTableActionEvent" />
+        <import-table :visible="importTableDialogVisible" :title="field.label" @close="(visible) => ImportTableAction(visible)" @action-event="handleImportTableActionEvent" />
         <component :is="dialogTemplate" v-if="dialogTemplate" ref="dialogTemplate" v-bind="dialogTemplateAtts" />
         <formrender-dialog ref="jyxtEdit" :visible="formDialogVisible" :title="field.label" :form-def="dialogFormDef" :data="dialogFormData" :mode="mode" :edit-from-type="editFromType" custom-class="ibps-dialog-80" @close="(visible) => (formDialogVisible = visible)" @action-event="handleFormDialogActionEvent" />
     </div>
@@ -221,7 +221,9 @@ export default {
             dialogTemplate: null,
             dialogTemplateAtts: {},
 
-            oldList: [] // 子表旧数据
+            oldList: [], // 子表旧数据
+            importList: [],
+            importVlaue: null
         }
     },
     computed: {
@@ -656,31 +658,82 @@ export default {
         handleImport () {
             this.importTableDialogVisible = true
         },
+        ImportTableAction (val) {
+            this.importTableDialogVisible = false
+            this.importList = []
+            this.importVlaue = null
+        },
         handleImportTableActionEvent (file, options) {
-            const formData = FormUtils.getTableDefaultColumnData(this.field)
-            IbpsImport.xlsx(file, options).then(({ header, results }) => {
-                const columnMap = {}
-                this.nameColumns.forEach((column) => {
-                    columnMap[column.label] = column
+            if (this.importList.length > 0) {
+                this.loading = false
+                const formData = this.setValue(this.importVlaue)
+                IbpsImport.xlsx(file, options).then(({ header, results }) => {
+                    results.forEach((item) => {
+                        const data = JSON.parse(JSON.stringify(formData))
+                        for (const key in item) {
+                            if (this.importVlaue[key]) {
+                                data[this.importVlaue[key]] = item[key]
+                            }
+                        }
+                        this.dataModel.push(data)
+                    })
+                    this.importTableDialogVisible = false
+                    this.importVlaue = null
+                    this.importList = []
+                    ActionUtils.success('导入成功')
                 })
-                results.forEach((result) => {
-                    const data = JSON.parse(JSON.stringify(formData))
-                    for (const key in result) {
-                        if (columnMap[key]) {
-                            const column = columnMap[key]
-                            const name = column.name
-                            const value = this.importDataFormatter(result[key], column)
-                            data[name] = value
+            } else {
+                const formData = FormUtils.getTableDefaultColumnData(this.field)
+                IbpsImport.xlsx(file, options).then(({ header, results }) => {
+                    const columnMap = {}
+                    this.nameColumns.forEach((column) => {
+                        columnMap[column.label] = column
+                    })
+                    results.forEach((result) => {
+                        const data = JSON.parse(JSON.stringify(formData))
+                        for (const key in result) {
+                            if (columnMap[key]) {
+                                const column = columnMap[key]
+                                const name = column.name
+                                const value = this.importDataFormatter(result[key], column)
+                                data[name] = value
+                            }
                         }
-                    }
-                    // TODO: 需要格式化的成数据库的数据
-                    // 数据添加
-                    this.dataModel.push(data)
+                        // TODO: 需要格式化的成数据库的数据
+                        // 数据添加
+                        this.dataModel.push(data)
+                    })
+                    this.importTableDialogVisible = false
+                    ActionUtils.success('导入成功')
                 })
-                this.importTableDialogVisible = false
-                ActionUtils.success('导入成功')
+            }
+        },
+
+        // 自定义导入
+        customHandleImport (data = []) {
+            this.importList = data
+            this.importVlaue = this.getKeys(this.importList)
+            this.importTableDialogVisible = true
+        },
+        setValue (data) {
+            const obj = {}
+            Object.values(data).forEach((item) => {
+                obj[item] = ''
             })
+            return obj
         },
+        getKeys (data) {
+            const obj = {}
+            if (data.length > 0) {
+                data.forEach((item) => {
+                    obj[item.label] = item.name
+                })
+                return obj
+            } else {
+                return obj
+            }
+        },
+
         // 数据导出
         getIbpsExport (columns, data, title, message, nameKey = 'name') {
             IbpsExport.excel({