Browse Source

tableForm失去焦点校验

hella_online_20240829
zhang_li 4 months ago
parent
commit
277676960e
  1. 174
      src/api/wms/business/inputBlur.ts
  2. 4
      src/components/BasicForm/src/BasicForm.vue
  3. 11
      src/views/wms/purchasereceiptManage/purchasereceipt/purchasereceiptRequestMain/purchasereceiptRequestMain.data.ts

174
src/api/wms/business/inputBlur.ts

@ -23,6 +23,158 @@ const { t } = useI18n() // 国际化
* FormBlur * FormBlur
*/ */
export const tableFormBlurVer = async (headerItem, val, row, index, routeName, formRef, detailData, tableData, callback) => { export const tableFormBlurVer = async (headerItem, val, row, index, routeName, formRef, detailData, tableData, callback) => {
if (headerItem.tableForm.searchPage && headerItem.tableForm.verificationParams) {
if (val && isString(val)) {
if (val.indexOf(',') > -1) {
message.alert('该输入框只能输入一条数据')
row[headerItem.field] = ''
return
}
// 校验
const params = ref({})
const filters: any[] = []
const searchCondition = headerItem.tableForm.searchCondition //获取data.ts参数信息
const verificationParams = headerItem.tableForm.verificationParams //获取data.ts参数信息
// 循环参数设置参数为key:value格式
if (searchCondition && searchCondition.length > 0) {
for (let i = 0; i < searchCondition.length; i++) {
if (searchCondition[i].isMainValue) {
params.value[searchCondition[i].key] = formRef.formModel[
searchCondition[i].value
]
? formRef.formModel[searchCondition[i].value]
: detailData
? detailData[searchCondition[i].value]
: row
? row[searchCondition[i].value]
: ''
// 是否含有空参数情况
let isNull = false
if (
params.value[searchCondition[i].key] == '' ||
params.value[searchCondition[i].key] == undefined
) {
isNull = true
}
if (isNull) {
message.warning(
searchCondition[i].message ? searchCondition[i].message : '前置条件未选择!'
)
row[headerItem.field] = ''
return
}
filters.push({
action: searchCondition[i].action || '==',
column: searchCondition[i].key,
value: formRef.formModel[searchCondition[i].value]
})
} else {
// 扩展 转换为筛选条件进行查询
if (searchCondition[i].isSearch) {
if (searchCondition[i].isFormModel) {
//用formModel中的值
if (searchCondition[i].required) {
if (
formRef.formModel[searchCondition[i].value] == '' ||
formRef.formModel[searchCondition[i].value] == undefined
) {
message.warning(
searchCondition[i].message ? searchCondition[i].message : '前置条件未选择!'
)
row[headerItem.field] = ''
return
}
}
}
filters.push({
action: searchCondition[i].action || '==',
column: searchCondition[i].key,
value: formRef.formModel[searchCondition[i].value]
})
} else {
params.value[searchCondition[i].key] = searchCondition[i].value
}
}
}
}
if (verificationParams && verificationParams.length > 0) {
// 转换筛选条件所需
for (let i = 0; i < verificationParams.length; i++) {
// 扩展 转换为筛选条件进行查询
if (verificationParams[i].isSearch) {
if (verificationParams[i].isFormModel) {
filters.push({
action: verificationParams[i].action,
column: verificationParams[i].key,
value: formRef.formModel[verificationParams[i].value]
? formRef.formModel[verificationParams[i].value]
: val.trim()
})
filters.push({
action: searchCondition[i].action || '==',
column: searchCondition[i].key,
value: formRef.formModel[searchCondition[i].value]
})
} else {
filters.push({
action: searchCondition[i].action || '==',
column: searchCondition[i].key,
value: searchCondition[i].value
})
}
} else {
params[verificationParams[i].key] = verificationParams[i].value
}
}
}
// 判断改包装号是否已经添加
const seen = new Set()
const repeatCode = new Set()
const arr = tableData.map((item) => item[headerItem.field]?.trim())
arr.forEach((item) => {
if (item) {
if (seen.has(item)) {
repeatCode.add(item)
} else {
seen.add(item)
}
}
})
const arr1 = Array.from(repeatCode)
if (arr1.length > 0) {
message.warning(`${arr1.join(',')}${t('ts.已经存在')}`)
row[headerItem.field] = ''
return
}
if (filters.length > 0) {
params.value.isSearch = true
params.value.filters = filters
}
const obj = {
by: 'ASC',
pageNo: 1,
pageSize: 20
}
params.value = {
isSearch: params.value.isSearch,
filters: params.value.filters,
...obj
}
const list = ref()
// 调取包装接口
await headerItem.tableForm.searchPage(params.value).then(async (res) => {
list.value = res?.list?.length > 0 ? res.list.slice(0, 1) : []
// 只查一条数据,多条数据查询默认显示不存在
if (list.value?.length == 0) {
message.alert('代码' + row[headerItem.field] + '没有找到对应数据')
row[headerItem.field] = ''
return
}
callback(list.value)
})
}
} else {
if ( if (
headerItem.field == 'fromPackingNumber' || headerItem.field == 'fromPackingNumber' ||
headerItem.field == 'packingNumber' || headerItem.field == 'packingNumber' ||
@ -219,7 +371,7 @@ export const tableFormBlurVer = async (headerItem, val, row, index,routeName,for
list.value = res ? res : [] list.value = res ? res : []
// 只查一条数据,多条数据查询默认显示不存在 // 只查一条数据,多条数据查询默认显示不存在
if (res.length == 1) { if (res.length == 1) {
callback(searchField,list.value) callback(list.value)
} else { } else {
message.alert('代码' + row[headerItem.field] + '没有找到对应数据') message.alert('代码' + row[headerItem.field] + '没有找到对应数据')
row[headerItem.field] = '' row[headerItem.field] = ''
@ -229,22 +381,23 @@ export const tableFormBlurVer = async (headerItem, val, row, index,routeName,for
} }
} }
} }
}
export const FormBlur = async (field, val, routeName, formRef, detailData, formSchema, callback) => { export const FormBlur = async (field, val, routeName, formRef, detailData, formSchema, callback) => {
if (formSchema.searchPage && formSchema.verificationParams) { if (formSchema.searchPage && formSchema.verificationParams) {
//获取data.ts参数信息 //获取data.ts参数信息
let searchCondition = formSchema?.searchCondition || [] const searchCondition = formSchema?.searchCondition || []
//获取失去焦点参数信息 //获取失去焦点参数信息
let verificationParams = formSchema?.verificationParams || const verificationParams = formSchema?.verificationParams ||
[] []
console.log('走新方法啦') console.log('走新方法啦')
// searchCondition = [...searchCondition, ...verificationParams] // searchCondition = [...searchCondition, ...verificationParams]
if (val && isString(val)) { if (val && isString(val)) {
let setV = {} const setV = {}
setV[field] = '' setV[field] = ''
let params = {} let params = {}
const _searchCondition = {} const _searchCondition = {}
let filters: any[] = [] const filters: any[] = []
if (searchCondition && searchCondition.length > 0) { if (searchCondition && searchCondition.length > 0) {
// 转换筛选条件所需 // 转换筛选条件所需
for (let i = 0; i < searchCondition.length; i++) { for (let i = 0; i < searchCondition.length; i++) {
@ -359,12 +512,13 @@ export const FormBlur = async (field, val, routeName, formRef, detailData, formS
} }
} }
} }
console.log(filters)
if (filters.length > 0) { if (filters.length > 0) {
_searchCondition.isSearch = true _searchCondition.isSearch = true
_searchCondition.filters = filters _searchCondition.filters = filters
} }
console.log(4545, _searchCondition) console.log(4545, _searchCondition)
let obj = { const obj = {
by: 'ASC', by: 'ASC',
pageNo: 1, pageNo: 1,
pageSize: 20 pageSize: 20
@ -382,8 +536,8 @@ export const FormBlur = async (field, val, routeName, formRef, detailData, formS
return return
} }
await formSchema.searchPage(params).then((res) => { await formSchema.searchPage(params).then((res) => {
let arr1 = val.split(',') const arr1 = val.split(',')
let list = ref([]) const list = ref([])
list.value = res?.list?.length > 0 ? res.list.slice(0, 1) : [] list.value = res?.list?.length > 0 ? res.list.slice(0, 1) : []
if (list.value?.length == 0) { if (list.value?.length == 0) {
message.alert('暂无数据') message.alert('暂无数据')
@ -391,8 +545,8 @@ export const FormBlur = async (field, val, routeName, formRef, detailData, formS
return return
} }
if (arr1.length != list.value.length) { if (arr1.length != list.value.length) {
let arr2 = list.value.map((item) => item.code) const arr2 = list.value.map((item) => item.code)
let str = [ const str = [
...arr1.filter((item) => !arr2.includes(item)), ...arr1.filter((item) => !arr2.includes(item)),
...arr2.filter((item) => !arr1.includes(item)) ...arr2.filter((item) => !arr1.includes(item))
].join(',') ].join(',')

4
src/components/BasicForm/src/BasicForm.vue

@ -904,11 +904,11 @@ const inputStringBlur = async (headerItem, val, row, index) => {
formRef.value, formRef.value,
props.detailData, props.detailData,
props.tableData, props.tableData,
(searchField, list) => { ( list) => {
emit( emit(
'searchTableSuccess', 'searchTableSuccess',
headerItem.field, headerItem.field,
searchField, headerItem.tableForm.searchField,
list, list,
formRef.value, formRef.value,
'tableForm', 'tableForm',

11
src/views/wms/purchasereceiptManage/purchasereceipt/purchasereceiptRequestMain/purchasereceiptRequestMain.data.ts

@ -989,6 +989,7 @@ export const PurchasereceiptRequestDetail = useCrudSchemas(reactive<CrudSchema[]
} }
}, },
tableForm: { tableForm: {
enterSearch: true,
isInpuFocusShow: true, isInpuFocusShow: true,
searchListPlaceholder: '请选择库位代码', // 输入框占位文本 searchListPlaceholder: '请选择库位代码', // 输入框占位文本
searchField: 'code', // 查询弹窗赋值字段 searchField: 'code', // 查询弹窗赋值字段
@ -999,7 +1000,15 @@ export const PurchasereceiptRequestDetail = useCrudSchemas(reactive<CrudSchema[]
key: 'available', key: 'available',
value: 'TRUE', value: 'TRUE',
isMainValue: false isMainValue: false
}] }],
verificationParams: [{
key: 'code',
action: '==',
value: '',
isMainValue: false,
isSearch: true,
isFormModel: true,
}], // 失去焦点校验参数
}, },
isTableForm: true, isTableForm: true,
isForm: false isForm: false

Loading…
Cancel
Save