|
@@ -26,8 +26,9 @@
|
|
|
|
|
|
<script>
|
|
|
import asyncRequest from '@/apis/service/netOrderEntry/netOrderEnter'
|
|
|
-import { isMobile, isPhone, isnumber, isnumber2, isnumber3 } from '@/utils/validate'
|
|
|
+import { isMobile } from '@/utils/validate'
|
|
|
import companyHelper from '@/mixins/companyHelper'
|
|
|
+import { replaceTextWrapAndSpace } from '../../../utils'
|
|
|
import { MessageBox } from 'element-ui'
|
|
|
|
|
|
import {
|
|
@@ -35,11 +36,12 @@ import {
|
|
|
columns,
|
|
|
PROPERTYS,
|
|
|
getTableProperty,
|
|
|
- createErrorMessage,
|
|
|
createFieldVerification,
|
|
|
requsetFields,
|
|
|
requiredFields,
|
|
|
- numberFields
|
|
|
+ numberFields,
|
|
|
+ getTableLabel,
|
|
|
+ intNumberFields
|
|
|
} from './template'
|
|
|
|
|
|
export default {
|
|
@@ -84,24 +86,26 @@ export default {
|
|
|
},
|
|
|
/* 校验导入的销售方列表编码(与选择的公司必须一致) **/
|
|
|
validateCompanyNo(companys = []) {
|
|
|
- const verification = createFieldVerification('销售方公司不能为空且必须与选择的公司一致')
|
|
|
+ const verification = createFieldVerification()
|
|
|
const current = this.currentCompany
|
|
|
companys.forEach((companyNo, index) => {
|
|
|
- if (companyNo !== current || !companyNo) {
|
|
|
+ if (companyNo !== current) {
|
|
|
verification.isValid = false
|
|
|
- verification.notValidRows.push(index + 1)
|
|
|
+ verification.message = `第 ${index + 1} 行,销售方公司必须与选择的公司一致`
|
|
|
+ return verification
|
|
|
}
|
|
|
})
|
|
|
return verification
|
|
|
},
|
|
|
/* 校验导入的购买方列表编码(开头必须为KH) **/
|
|
|
validateKhNo(customers = []) {
|
|
|
- const verification = createFieldVerification("购买方公司编码不能为空且必须以'KH'开头")
|
|
|
+ const verification = createFieldVerification()
|
|
|
customers.forEach((customerNo, index) => {
|
|
|
const perfix = String(customerNo || '').slice(0, 2)
|
|
|
- if (perfix !== 'KH' || !customerNo) {
|
|
|
+ if (perfix !== 'KH') {
|
|
|
verification.isValid = false
|
|
|
- verification.notValidRows.push(index + 1)
|
|
|
+ verification.message = `第 ${index + 1} 行,"购买方公司编码必须以'KH'开头`
|
|
|
+ return verification
|
|
|
}
|
|
|
})
|
|
|
return verification
|
|
@@ -130,91 +134,92 @@ export default {
|
|
|
},
|
|
|
/* 校验导入的联系电话是否合法 **/
|
|
|
validateMobile(mobiles = []) {
|
|
|
- const verification = createFieldVerification('联系电话不能为空且必须为手机号或电话号码')
|
|
|
+ const verification = createFieldVerification()
|
|
|
mobiles.forEach((mobile, index) => {
|
|
|
- if (!mobile || isMobile(mobile) && isPhone(mobile)) {
|
|
|
+ if (!isMobile(mobile)) {
|
|
|
verification.isValid = false
|
|
|
- verification.notValidRows.push(index + 1)
|
|
|
+ verification.message = `第${Number(index) + 1}行,联系方式,手机号格式不正确`
|
|
|
+ return verification
|
|
|
}
|
|
|
})
|
|
|
return verification
|
|
|
},
|
|
|
/* 校验导入的购买方列表编码(开头必须为QS) **/
|
|
|
validateSupplierNo(suppliers = []) {
|
|
|
- const verification = createFieldVerification("供应商公司编码不能为空且必须以'QS'开头")
|
|
|
+ const verification = createFieldVerification()
|
|
|
suppliers.forEach((supplierNo, index) => {
|
|
|
const perfix = String(supplierNo || '').slice(0, 2)
|
|
|
- if (perfix !== 'QS' || !supplierNo) {
|
|
|
+ if (perfix !== 'QS') {
|
|
|
verification.isValid = false
|
|
|
- verification.notValidRows.push(index + 1)
|
|
|
+ verification.message = `第 ${index + 1} 供应商公司编码必须以'QS'开头`
|
|
|
+ return verification
|
|
|
}
|
|
|
})
|
|
|
return verification
|
|
|
},
|
|
|
validateNumberField(numberFields) {
|
|
|
- const verification = createFieldVerification('税率、数量、销售单价、采购单价不能为空且必须是数字')
|
|
|
- const fields = helper.fields(numberFields)
|
|
|
- numberFields[fields[0]].forEach((_, index) => {
|
|
|
- const values = helper.values(numberFields, fields, index)
|
|
|
- const valuesIsNumber = values.every(value => {
|
|
|
- return isnumber(value) || isnumber2(value) || isnumber3(value)
|
|
|
- })
|
|
|
- if (!valuesIsNumber) {
|
|
|
- verification.isValid = false
|
|
|
- verification.notValidRows.push(index + 1)
|
|
|
+ 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
|
|
|
+ }
|
|
|
}
|
|
|
- })
|
|
|
+ }
|
|
|
+ return verification
|
|
|
+ },
|
|
|
+ validateIntNumberField(intNumberField) {
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
return verification
|
|
|
},
|
|
|
/* 校验导入的税率、数量、采购单价、销售单价是否为数字 **/
|
|
|
validateDateField(dateFields) {
|
|
|
- const verification = createFieldVerification('发货日期不能为空,且必须为日期格式')
|
|
|
+ const verification = createFieldVerification()
|
|
|
dateFields.forEach((date, index) => {
|
|
|
- if (!date || !(/^\d{4}-\d{1,2}-\d{1,2}\s\d{1,2}:\d{1,2}:\d{1,2}$/.test(date))) {
|
|
|
+ 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.notValidRows.push(index + 1)
|
|
|
+ verification.message = `第${Number(index) + 1}行,发货日期不能为空,且必须为日期格式`
|
|
|
+ return verification
|
|
|
}
|
|
|
})
|
|
|
return verification
|
|
|
},
|
|
|
- /* 所属平台、商品分类、商品名称、单位、收货人、收货地址、PO编号不能为空 **/
|
|
|
validateRequiredField(requiredFields) {
|
|
|
- const verification = createFieldVerification('所属平台、商品分类、商品名称、单位、收货人、收货地址、PO编号不能为空')
|
|
|
- const fields = helper.fields(requiredFields)
|
|
|
- requiredFields[fields[0]].forEach((_, index) => {
|
|
|
- if (!helper.values(requiredFields, fields, index).every(value => value && String(value).trim() !== '')) {
|
|
|
- verification.isValid = false
|
|
|
- verification.notValidRows.push(index + 1)
|
|
|
+ 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
|
|
|
+ }
|
|
|
}
|
|
|
- })
|
|
|
+ }
|
|
|
return verification
|
|
|
},
|
|
|
/* 处理不合法的值,提示错误信息,并返回最终的验证状态 **/
|
|
|
- handleNotValidFields(...validStates) {
|
|
|
- const messages = {}
|
|
|
+ handleNotValidFields(...validfns) {
|
|
|
let isFinalValid = true
|
|
|
-
|
|
|
- for (const validState of validStates) {
|
|
|
- const { message, isValid, notValidRows } = validState
|
|
|
- if (isValid) continue
|
|
|
- isFinalValid = false
|
|
|
-
|
|
|
- notValidRows.forEach(row => {
|
|
|
- if (!messages[row]) messages[row] = []
|
|
|
- messages[row].push(message)
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- return {
|
|
|
- isFinalValid,
|
|
|
- message: () => !isFinalValid && MessageBox({
|
|
|
- type: 'warning',
|
|
|
- title: '数据填写错误',
|
|
|
- dangerouslyUseHTMLString: true,
|
|
|
- message: createErrorMessage(messages),
|
|
|
- customClass: 'error-message__wrapper'
|
|
|
- })
|
|
|
+ for (const validFn of validfns) {
|
|
|
+ const { message, isValid } = validFn()
|
|
|
+ if (!isValid) {
|
|
|
+ isFinalValid = false
|
|
|
+ MessageBox({ type: 'warning', title: '数据填写错误', message })
|
|
|
+ break
|
|
|
+ }
|
|
|
}
|
|
|
+ return isFinalValid
|
|
|
},
|
|
|
/* 校验导入的数据 **/
|
|
|
validateFields(tableData = []) {
|
|
@@ -229,13 +234,14 @@ export default {
|
|
|
}
|
|
|
|
|
|
return this.handleNotValidFields(
|
|
|
- this.validateMobile(mapTableFieldToTableData[PROPERTYS.MOBILE]),
|
|
|
- this.validateKhNo(mapTableFieldToTableData[PROPERTYS.CUSTOMER_NO]),
|
|
|
- this.validateCompanyNo(mapTableFieldToTableData[PROPERTYS.COMPANY_NO]),
|
|
|
- this.validateSupplierNo(mapTableFieldToTableData[PROPERTYS.SUPPLIER_NO]),
|
|
|
- this.validateNumberField(helper.write(mapTableFieldToTableData, numberFields)),
|
|
|
- this.validateRequiredField(helper.write(mapTableFieldToTableData, requiredFields)),
|
|
|
- this.validateDateField(mapTableFieldToTableData[PROPERTYS.SEND_TIME])
|
|
|
+ () => 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])
|
|
|
)
|
|
|
},
|
|
|
mapTemplateItemToTableItem(templateItem) {
|
|
@@ -262,16 +268,22 @@ export default {
|
|
|
}
|
|
|
templateItems.forEach(templateItem => {
|
|
|
const tableItem = this.mapTemplateItemToTableItem(templateItem)
|
|
|
- if (tableItem[PROPERTYS.SEND_TIME]) {
|
|
|
- tableItem[PROPERTYS.SEND_TIME] = this.formatDate2(tableItem[PROPERTYS.SEND_TIME])
|
|
|
- }
|
|
|
+ Object.keys(tableItem).forEach(field => {
|
|
|
+ let target = ''
|
|
|
+ if (field === PROPERTYS.SEND_TIME) {
|
|
|
+ target = this.formatDate2(tableItem[PROPERTYS.SEND_TIME])
|
|
|
+ } else {
|
|
|
+ target = tableItem[field] ? String(tableItem[field]).trim() : ''
|
|
|
+ }
|
|
|
+ tableItem[field] = target
|
|
|
+ })
|
|
|
this.tableData.push(tableItem)
|
|
|
})
|
|
|
- this.validateFields(this.tableData).message()
|
|
|
+
|
|
|
+ this.validateFields(this.tableData)
|
|
|
},
|
|
|
async onSubmit() {
|
|
|
- const { message, isFinalValid } = this.validateFields(this.tableData)
|
|
|
- if (!isFinalValid) return message()
|
|
|
+ if (!this.validateFields(this.tableData)) return
|
|
|
|
|
|
const list = this.tableData.map(tableItem => requsetFields.reduce((prev, currentKey) => ({
|
|
|
...prev,
|