|
@@ -0,0 +1,123 @@
|
|
|
+<template>
|
|
|
+ <el-dialog
|
|
|
+ center
|
|
|
+ width="1024px"
|
|
|
+ title="导入采销订单补录"
|
|
|
+ :visible="innerVisible"
|
|
|
+ :close-on-click-modal="false"
|
|
|
+ @close="() => innerVisible = false"
|
|
|
+ >
|
|
|
+ <div v-if="tableData && tableData.length > 0" class="tr" style="padding: 10px 0 0 0">
|
|
|
+ <el-button :size="'mini'" @click="cancel">取消</el-button>
|
|
|
+ <el-button type="primary" :size="'mini'" @click="submit">提交</el-button>
|
|
|
+ </div>
|
|
|
+ <div v-else>
|
|
|
+ <upload-excel :on-success="handleSuccess" :before-upload="beforeUpload" />
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <ex-table
|
|
|
+ :columns="columns"
|
|
|
+ :table="table"
|
|
|
+ :data="tableData"
|
|
|
+ style="margin: 15px 0 0 0"
|
|
|
+ />
|
|
|
+ </el-dialog>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import { columns, getTableProperty } from './template'
|
|
|
+import companyHelper from '@/mixins/companyHelper'
|
|
|
+export default {
|
|
|
+ mixins: [companyHelper],
|
|
|
+ props: ['visible'],
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ columns,
|
|
|
+ loading: false,
|
|
|
+ tableData: [],
|
|
|
+ table: {
|
|
|
+ stripe: true,
|
|
|
+ border: true,
|
|
|
+ 'max-height': '800px'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ innerVisible: {
|
|
|
+ get() {
|
|
|
+ return this.visible
|
|
|
+ },
|
|
|
+ set(newVal) {
|
|
|
+ this.$emit('update:visible', newVal)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ validateTableHeader(header, importHeader) {
|
|
|
+ let isHeaderOk = true
|
|
|
+ if (header.length !== importHeader.length) return false
|
|
|
+ for (const index in header) {
|
|
|
+ const field = header[index]
|
|
|
+ const importField = importHeader[index]
|
|
|
+ if (field !== importField) {
|
|
|
+ console.log(field, importField)
|
|
|
+ isHeaderOk = false
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return isHeaderOk
|
|
|
+ },
|
|
|
+ /* 校验导入的销售方列表编码(与选择的公司必须一致) **/
|
|
|
+ validateCompanyNo() {
|
|
|
+ const current = this.currentCompany
|
|
|
+ },
|
|
|
+ /* 校验导入的数据 **/
|
|
|
+ validateFields(tableData = []) {
|
|
|
+ for (const index in tableData) {
|
|
|
+ const tableItem = tableData[index]
|
|
|
+ const propertys = Object.keys(tableItem)
|
|
|
+
|
|
|
+ propertys.forEach(property => {
|
|
|
+ switch (property) {
|
|
|
+ case 'companyNo':
|
|
|
+ break
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ mapTemplateItemToTableItem(templateItem) {
|
|
|
+ const tableItem = {}
|
|
|
+ const templatePropertys = Object.keys(templateItem)
|
|
|
+ templatePropertys.forEach(templateProperty => {
|
|
|
+ const tableproperty = getTableProperty(templateProperty)
|
|
|
+ tableItem[tableproperty] = templateItem[templateProperty]
|
|
|
+ })
|
|
|
+ return tableItem
|
|
|
+ },
|
|
|
+ handleSuccess({ results: templateItems, header: templateHeader }) {
|
|
|
+ const isHeaderValid = this.validateTableHeader(
|
|
|
+ this.columns.map(({ label }) => label).slice(1),
|
|
|
+ templateHeader
|
|
|
+ )
|
|
|
+
|
|
|
+ if (!isHeaderValid) {
|
|
|
+ this.$message.warning('表格与导入的表头不一致!')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if (templateItems.length === 0) {
|
|
|
+ this.$message.warning('导入的表格没有数据!')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ templateItems.forEach(templateItem => {
|
|
|
+ const tableItem = this.mapTemplateItemToTableItem(templateItem)
|
|
|
+ this.tableData.push(tableItem)
|
|
|
+ })
|
|
|
+
|
|
|
+ const isValid = this.validateFields(this.tableData)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</script>
|