|
@@ -27,6 +27,8 @@
|
|
|
<script>
|
|
|
import { columns, getTableProperty } from './template'
|
|
|
import companyHelper from '@/mixins/companyHelper'
|
|
|
+import { MessageBox } from 'element-ui'
|
|
|
+import { h } from 'vue'
|
|
|
export default {
|
|
|
mixins: [companyHelper],
|
|
|
props: ['visible'],
|
|
@@ -69,22 +71,87 @@ export default {
|
|
|
return isHeaderOk
|
|
|
},
|
|
|
/* 校验导入的销售方列表编码(与选择的公司必须一致) **/
|
|
|
- validateCompanyNo() {
|
|
|
+ validateCompanyNo(companys = []) {
|
|
|
+ let isValid = true
|
|
|
+ const notValidRows = []
|
|
|
const current = this.currentCompany
|
|
|
+
|
|
|
+ companys.forEach((companyNo, index) => {
|
|
|
+ if (companyNo !== current) {
|
|
|
+ isValid = false
|
|
|
+ notValidRows.push(index + 1)
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ return {
|
|
|
+ isValid,
|
|
|
+ notValidRows,
|
|
|
+ message: '销售方公司与选择的公司必须一致'
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /* 校验导入的购买方列表编码(开头必须为KH) **/
|
|
|
+ validateKhNo(customers = []) {
|
|
|
+ let isValid = true
|
|
|
+ const notValidRows = []
|
|
|
+ customers.forEach((customerNo, index) => {
|
|
|
+ const perfix = String(customerNo || '').slice(0, 1)
|
|
|
+ if (perfix !== 'KH') {
|
|
|
+ isValid = false
|
|
|
+ notValidRows.push(index + 1)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return {
|
|
|
+ isValid,
|
|
|
+ notValidRows,
|
|
|
+ message: "购买方公司编码必须以'KH'开头"
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /* 处理不合法的值,提示错误信息,并返回最终的验证状态 **/
|
|
|
+ handleNotValidFields(...validStates) {
|
|
|
+ const messages = {}
|
|
|
+ let finalValid = true
|
|
|
+
|
|
|
+ for (const validState of validStates) {
|
|
|
+ const { message, isValid, notValidRows } = validState
|
|
|
+ if (isValid) continue
|
|
|
+ finalValid = false
|
|
|
+
|
|
|
+ notValidRows.forEach(row => {
|
|
|
+ if (!messages[row]) messages[row] = []
|
|
|
+ messages[row].push(message)
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log(Object.keys(messages), messages['1'])
|
|
|
+ if (!finalValid) {
|
|
|
+ MessageBox({
|
|
|
+ type: 'warning',
|
|
|
+ title: '数据填写错误',
|
|
|
+ message: h('ul', null, [])
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ return finalValid
|
|
|
},
|
|
|
/* 校验导入的数据 **/
|
|
|
validateFields(tableData = []) {
|
|
|
- for (const index in tableData) {
|
|
|
- const tableItem = tableData[index]
|
|
|
- const propertys = Object.keys(tableItem)
|
|
|
+ const tableFieldToTableData = {}
|
|
|
|
|
|
- propertys.forEach(property => {
|
|
|
- switch (property) {
|
|
|
- case 'companyNo':
|
|
|
- break
|
|
|
- }
|
|
|
- })
|
|
|
+ for (const tableItem of tableData) {
|
|
|
+ const propertys = Object.keys(tableItem)
|
|
|
+ for (const property of propertys) {
|
|
|
+ const value = tableItem[property]
|
|
|
+ if (!tableFieldToTableData[property]) tableFieldToTableData[property] = []
|
|
|
+ tableFieldToTableData[property].push(value)
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ const finalValid = this.handleNotValidFields(
|
|
|
+ this.validateCompanyNo(tableFieldToTableData.companyNo),
|
|
|
+ this.validateKhNo(tableFieldToTableData.khNo)
|
|
|
+ )
|
|
|
+
|
|
|
+ return finalValid
|
|
|
},
|
|
|
mapTemplateItemToTableItem(templateItem) {
|
|
|
const tableItem = {}
|
|
@@ -117,6 +184,10 @@ export default {
|
|
|
})
|
|
|
|
|
|
const isValid = this.validateFields(this.tableData)
|
|
|
+
|
|
|
+ if (isValid) {
|
|
|
+ this.tableData = []
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|