|
@@ -85,29 +85,25 @@ export default {
|
|
|
return isHeaderOk
|
|
|
},
|
|
|
/* 校验导入的销售方列表编码(与选择的公司必须一致) **/
|
|
|
- validateCompanyNo(companys = []) {
|
|
|
+ validateCompanyNo(value, row) {
|
|
|
const verification = createFieldVerification()
|
|
|
const current = this.currentCompany
|
|
|
- companys.forEach((companyNo, index) => {
|
|
|
- if (companyNo !== current) {
|
|
|
- verification.isValid = false
|
|
|
- verification.message = `第 ${index + 1} 行,销售方公司必须与选择的公司一致`
|
|
|
- return verification
|
|
|
- }
|
|
|
- })
|
|
|
+ if (value !== current) {
|
|
|
+ verification.isValid = false
|
|
|
+ verification.message = `第 ${row} 行,销售方公司必须与选择的公司一致`
|
|
|
+ return verification
|
|
|
+ }
|
|
|
return verification
|
|
|
},
|
|
|
/* 校验导入的购买方列表编码(开头必须为KH) **/
|
|
|
- validateKhNo(customers = []) {
|
|
|
+ validateKhNo(value, row) {
|
|
|
const verification = createFieldVerification()
|
|
|
- customers.forEach((customerNo, index) => {
|
|
|
- const perfix = String(customerNo || '').slice(0, 2)
|
|
|
- if (perfix !== 'KH') {
|
|
|
- verification.isValid = false
|
|
|
- verification.message = `第 ${index + 1} 行,"购买方公司编码必须以'KH'开头`
|
|
|
- return verification
|
|
|
- }
|
|
|
- })
|
|
|
+ const perfix = String(value || '').slice(0, 2)
|
|
|
+ if (perfix !== 'KH') {
|
|
|
+ verification.isValid = false
|
|
|
+ verification.message = `第 ${row} 行,"购买方公司编码必须以'KH'开头`
|
|
|
+ return verification
|
|
|
+ }
|
|
|
return verification
|
|
|
},
|
|
|
formatDate2(serialNumber, format = '-', mao = ':') {
|
|
@@ -133,53 +129,42 @@ export default {
|
|
|
return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds
|
|
|
},
|
|
|
/* 校验导入的联系电话是否合法 **/
|
|
|
- validateMobile(mobiles = []) {
|
|
|
+ validateMobile(value, row) {
|
|
|
const verification = createFieldVerification()
|
|
|
- mobiles.forEach((mobile, index) => {
|
|
|
- if (!isMobile(mobile)) {
|
|
|
- verification.isValid = false
|
|
|
- verification.message = `第${Number(index) + 1}行,联系方式,手机号格式不正确`
|
|
|
- return verification
|
|
|
- }
|
|
|
- })
|
|
|
+ if (!isMobile(value)) {
|
|
|
+ verification.isValid = false
|
|
|
+ verification.message = `第${Number(row)}行,联系方式,手机号格式不正确`
|
|
|
+ return verification
|
|
|
+ }
|
|
|
return verification
|
|
|
},
|
|
|
/* 校验导入的购买方列表编码(开头必须为QS) **/
|
|
|
- validateSupplierNo(suppliers = []) {
|
|
|
+ validateSupplierNo(value, row) {
|
|
|
const verification = createFieldVerification()
|
|
|
- suppliers.forEach((supplierNo, index) => {
|
|
|
- const perfix = String(supplierNo || '').slice(0, 2)
|
|
|
- if (perfix !== 'QS') {
|
|
|
- verification.isValid = false
|
|
|
- verification.message = `第 ${index + 1} 供应商公司编码必须以'QS'开头`
|
|
|
- return verification
|
|
|
- }
|
|
|
- })
|
|
|
+ const perfix = String(value || '').slice(0, 2)
|
|
|
+ if (perfix !== 'QS') {
|
|
|
+ console.log(111)
|
|
|
+ verification.isValid = false
|
|
|
+ verification.message = `第 ${row} 供应商公司编码必须以'QS'开头`
|
|
|
+ return verification
|
|
|
+ }
|
|
|
return verification
|
|
|
},
|
|
|
- validateNumberField(numberFields) {
|
|
|
+ validateNumberField(field, value, row) {
|
|
|
const verification = createFieldVerification()
|
|
|
- for (const field of helper.fields(numberFields)) {
|
|
|
- for (const row in numberFields[field]) {
|
|
|
- if (!/^\d*\.?\d+$/.test(numberFields[field][row]) && row !== 'remove') {
|
|
|
- verification.isValid = false
|
|
|
- verification.message = `第${Number(row) + 1}行,${getTableLabel(field)}必须为数字,且不能小于0`
|
|
|
- return verification
|
|
|
- }
|
|
|
- }
|
|
|
+ if (!/^\d*\.?\d+$/.test(value)) {
|
|
|
+ verification.isValid = false
|
|
|
+ verification.message = `第${Number(row)}行,${getTableLabel(field)}必须为数字,且不能小于0`
|
|
|
+ return verification
|
|
|
}
|
|
|
return verification
|
|
|
},
|
|
|
- validateIntNumberField(intNumberField) {
|
|
|
+ validateIntNumberField(field, value, row) {
|
|
|
const verification = createFieldVerification()
|
|
|
- for (const field of helper.fields(intNumberField)) {
|
|
|
- for (const row in intNumberField[field]) {
|
|
|
- if (!/^\d+$/.test(intNumberField[field][row]) && row !== 'remove') {
|
|
|
- verification.isValid = false
|
|
|
- verification.message = `第${Number(row) + 1}行,${getTableLabel(field)}必须为正整数`
|
|
|
- return verification
|
|
|
- }
|
|
|
- }
|
|
|
+ if (!/^\d+$/.test(value)) {
|
|
|
+ verification.isValid = false
|
|
|
+ verification.message = `第${Number(row)}行,${getTableLabel(field)}必须为正整数`
|
|
|
+ return verification
|
|
|
}
|
|
|
return verification
|
|
|
},
|
|
@@ -189,22 +174,18 @@ export default {
|
|
|
dateFields.forEach((date, index) => {
|
|
|
if (!(/^\d{4}-\d{1,2}-\d{1,2}\s\d{1,2}:\d{1,2}:\d{1,2}$/.test(date))) {
|
|
|
verification.isValid = false
|
|
|
- verification.message = `第${Number(index) + 1}行,发货日期不能为空,且必须为日期格式`
|
|
|
+ verification.message = `第${Number(index)}行,发货日期不能为空,且必须为日期格式`
|
|
|
return verification
|
|
|
}
|
|
|
})
|
|
|
return verification
|
|
|
},
|
|
|
- validateRequiredField(requiredFields) {
|
|
|
+ validateRequiredField(field, value, row) {
|
|
|
const verification = createFieldVerification()
|
|
|
- for (const field of helper.fields(requiredFields)) {
|
|
|
- for (const row in requiredFields[field]) {
|
|
|
- if (replaceTextWrapAndSpace(requiredFields[field][row]) === '') {
|
|
|
- verification.isValid = false
|
|
|
- verification.message = `第${Number(row) + 1}行,${getTableLabel(field)}不能为空`
|
|
|
- return verification
|
|
|
- }
|
|
|
- }
|
|
|
+ if (replaceTextWrapAndSpace(value) === '') {
|
|
|
+ verification.isValid = false
|
|
|
+ verification.message = `第${row}行,${getTableLabel(field)}不能为空`
|
|
|
+ return verification
|
|
|
}
|
|
|
return verification
|
|
|
},
|
|
@@ -223,26 +204,94 @@ export default {
|
|
|
},
|
|
|
/* 校验导入的数据 **/
|
|
|
validateFields(tableData = []) {
|
|
|
- const mapTableFieldToTableData = {}
|
|
|
- for (const tableItem of tableData) {
|
|
|
- const propertys = Object.keys(tableItem)
|
|
|
- for (const property of propertys) {
|
|
|
- const value = tableItem[property]
|
|
|
- if (!mapTableFieldToTableData[property]) mapTableFieldToTableData[property] = []
|
|
|
- mapTableFieldToTableData[property].push(value)
|
|
|
+ // const mapTableFieldToTableData = {}
|
|
|
+ // for (const tableItem of tableData) {
|
|
|
+ // const propertys = Object.keys(tableItem)
|
|
|
+ // for (const property of propertys) {
|
|
|
+ // const value = tableItem[property]
|
|
|
+ // if (!mapTableFieldToTableData[property]) mapTableFieldToTableData[property] = []
|
|
|
+ // mapTableFieldToTableData[property].push(value)
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // return this.handleNotValidFields(
|
|
|
+ // () => this.validateRequiredField(helper.write(mapTableFieldToTableData, requiredFields)),
|
|
|
+ // () => this.validateIntNumberField(helper.write(mapTableFieldToTableData, intNumberFields)),
|
|
|
+ // () => this.validateNumberField(helper.write(mapTableFieldToTableData, numberFields)),
|
|
|
+ // () => this.validateDateField(mapTableFieldToTableData[PROPERTYS.SEND_TIME]),
|
|
|
+ // () => this.validateMobile(mapTableFieldToTableData[PROPERTYS.MOBILE]),
|
|
|
+ // () => this.validateKhNo(mapTableFieldToTableData[PROPERTYS.CUSTOMER_NO]),
|
|
|
+ // () => this.validateCompanyNo(mapTableFieldToTableData[PROPERTYS.COMPANY_NO]),
|
|
|
+ // () => this.validateSupplierNo(mapTableFieldToTableData[PROPERTYS.SUPPLIER_NO])
|
|
|
+ // )
|
|
|
+
|
|
|
+ let verification = null
|
|
|
+ for (const row in tableData) {
|
|
|
+ if (row === 'remove') {
|
|
|
+ continue
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- return this.handleNotValidFields(
|
|
|
- () => this.validateRequiredField(helper.write(mapTableFieldToTableData, requiredFields)),
|
|
|
- () => this.validateIntNumberField(helper.write(mapTableFieldToTableData, intNumberFields)),
|
|
|
- () => this.validateNumberField(helper.write(mapTableFieldToTableData, numberFields)),
|
|
|
- () => this.validateDateField(mapTableFieldToTableData[PROPERTYS.SEND_TIME]),
|
|
|
- () => this.validateMobile(mapTableFieldToTableData[PROPERTYS.MOBILE]),
|
|
|
- () => this.validateKhNo(mapTableFieldToTableData[PROPERTYS.CUSTOMER_NO]),
|
|
|
- () => this.validateCompanyNo(mapTableFieldToTableData[PROPERTYS.COMPANY_NO]),
|
|
|
- () => this.validateSupplierNo(mapTableFieldToTableData[PROPERTYS.SUPPLIER_NO])
|
|
|
- )
|
|
|
+ const tableItem = tableData[row]
|
|
|
+ const index = Number(row) + 1
|
|
|
+
|
|
|
+ for (const field in tableItem) {
|
|
|
+ if (requiredFields.includes(field)) {
|
|
|
+ verification = this.validateRequiredField(field, tableItem[field], index)
|
|
|
+ if (!verification.isValid) {
|
|
|
+ MessageBox({ type: 'warning', title: '数据填写错误', message: verification.message })
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (intNumberFields.includes(field)) {
|
|
|
+ verification = this.validateIntNumberField(field, tableItem[field], index)
|
|
|
+ if (!verification.isValid) {
|
|
|
+ MessageBox({ type: 'warning', title: '数据填写错误', message: verification.message })
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (numberFields.includes(field)) {
|
|
|
+ verification = this.validateNumberField(field, tableItem[field], index)
|
|
|
+ if (!verification.isValid) {
|
|
|
+ MessageBox({ type: 'warning', title: '数据填写错误', message: verification.message })
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (field === PROPERTYS.MOBILE) {
|
|
|
+ verification = this.validateMobile(tableItem[field], index)
|
|
|
+ if (!verification.isValid) {
|
|
|
+ MessageBox({ type: 'warning', title: '数据填写错误', message: verification.message })
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (field === PROPERTYS.CUSTOMER_NO) {
|
|
|
+ verification = this.validateKhNo(tableItem[field], index)
|
|
|
+ if (!verification.isValid) {
|
|
|
+ MessageBox({ type: 'warning', title: '数据填写错误', message: verification.message })
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (field === PROPERTYS.COMPANY_NO) {
|
|
|
+ verification = this.validateCompanyNo(tableItem[field], index)
|
|
|
+ if (!verification.isValid) {
|
|
|
+ MessageBox({ type: 'warning', title: '数据填写错误', message: verification.message })
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (field === PROPERTYS.SUPPLIER_NO) {
|
|
|
+ verification = this.validateSupplierNo(tableItem[field], index)
|
|
|
+ if (!verification.isValid) {
|
|
|
+ MessageBox({ type: 'warning', title: '数据填写错误', message: verification.message })
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true
|
|
|
},
|
|
|
mapTemplateItemToTableItem(templateItem) {
|
|
|
const tableItem = {}
|