|
|
|
@ -1193,21 +1193,56 @@ export default { |
|
|
|
}) |
|
|
|
}, 100) |
|
|
|
}, |
|
|
|
// 判断重复api |
|
|
|
// 判断重复api - 表单验证方式 |
|
|
|
handlerIsRepeat(params, item) { |
|
|
|
if (this.isDesFormType !== 'prearchiveLibrary') { |
|
|
|
FetchIsRepeatByField(params).then(res => { |
|
|
|
if (res) { |
|
|
|
this.$message({ message: item.fieldCnName + '不可重复', type: 'error', offset: 8 }) |
|
|
|
const validateRepeat = async(value) => { |
|
|
|
if (!value) { |
|
|
|
return null |
|
|
|
} |
|
|
|
try { |
|
|
|
const fieldValue = this.addOrUpdateForm[item.fieldName] |
|
|
|
let response |
|
|
|
if (this.isDesFormType !== 'prearchiveLibrary') { |
|
|
|
// 非预归档库场景 |
|
|
|
const requestParams = { |
|
|
|
'categoryId': this.selectedCategory.id, |
|
|
|
'archivesId': this.arcId, |
|
|
|
'categoryLevel': this.collectLevel, |
|
|
|
'fieldName': item.fieldName, |
|
|
|
'fieldValue': fieldValue |
|
|
|
} |
|
|
|
response = await FetchIsRepeatByField(requestParams) |
|
|
|
} else { |
|
|
|
// 预归档库场景 |
|
|
|
const requestParams = { |
|
|
|
'documentId': this.selectedCategory.id, |
|
|
|
'archivesId': this.arcId, |
|
|
|
'fieldName': item.fieldName, |
|
|
|
'value': fieldValue |
|
|
|
} |
|
|
|
response = await FetchReDoeditIsRepeat(requestParams) |
|
|
|
} |
|
|
|
}) |
|
|
|
} else { |
|
|
|
FetchReDoeditIsRepeat(params).then(res => { |
|
|
|
if (res) { |
|
|
|
this.$message({ message: item.fieldCnName + '不可重复', type: 'error', offset: 8 }) |
|
|
|
if (response) { |
|
|
|
return `${item.fieldCnName}不可重复` |
|
|
|
} |
|
|
|
}) |
|
|
|
return null |
|
|
|
} catch (error) { |
|
|
|
console.error('重复检查失败:', error) |
|
|
|
return '验证重复时发生错误,请稍后再试' |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
this.$set(this.rules, item.fieldName, [{ |
|
|
|
validator: async(rule, value, callback) => { |
|
|
|
const errorMessage = await validateRepeat(value) |
|
|
|
if (errorMessage) { |
|
|
|
callback(new Error(errorMessage)) |
|
|
|
} else { |
|
|
|
callback() |
|
|
|
} |
|
|
|
}, |
|
|
|
trigger: 'blur' |
|
|
|
}]) |
|
|
|
}, |
|
|
|
async isRepeatHandle(item) { |
|
|
|
// 记录最后修改的字段名 |
|
|
|
@ -1218,14 +1253,14 @@ export default { |
|
|
|
const params = this.isDesFormType !== 'prearchiveLibrary' |
|
|
|
? { |
|
|
|
'categoryId': this.selectedCategory.id, |
|
|
|
// 'archivesId': this.arcId, |
|
|
|
'archivesId': this.arcId, |
|
|
|
'categoryLevel': this.collectLevel, |
|
|
|
'fieldName': item.fieldName, |
|
|
|
'fieldValue': this.addOrUpdateForm[item.fieldName] |
|
|
|
} |
|
|
|
: { |
|
|
|
'documentId': this.selectedCategory.id, |
|
|
|
'archivesId': null, |
|
|
|
'archivesId': this.arcId, |
|
|
|
'fieldName': item.fieldName, |
|
|
|
'value': this.addOrUpdateForm[item.fieldName] |
|
|
|
} |
|
|
|
@ -1278,14 +1313,14 @@ export default { |
|
|
|
const params = this.isDesFormType !== 'prearchiveLibrary' && this.isDesFormType !== 'mergeFile' |
|
|
|
? { |
|
|
|
'categoryId': this.selectedCategory.id, |
|
|
|
// 'archivesId': this.arcId, |
|
|
|
'archivesId': this.arcId, |
|
|
|
'categoryLevel': this.collectLevel, |
|
|
|
'fieldName': this.treeCurrentFiled.fieldName, |
|
|
|
'fieldValue': val.dictionaryName |
|
|
|
} |
|
|
|
: { |
|
|
|
'documentId': this.selectedCategory.id, |
|
|
|
'archivesId': null, |
|
|
|
'archivesId': this.arcId, |
|
|
|
'fieldName': this.treeCurrentFiled.fieldName, |
|
|
|
'value': val.dictionaryName |
|
|
|
} |
|
|
|
@ -1569,24 +1604,80 @@ export default { |
|
|
|
this.formPreviewData[newIndex] = index |
|
|
|
} |
|
|
|
}, |
|
|
|
submitForm(formName, categoryId, quickPaperArcId, arcAddType) { |
|
|
|
// 时间格式化 |
|
|
|
// this.formPreviewData.map(item => { |
|
|
|
// if (item.isInputClass === 'date') { |
|
|
|
// if (this.addOrUpdateForm[item.fieldName] !== '') { |
|
|
|
// this.$set(this.addOrUpdateForm, item.fieldName, parseTime(this.addOrUpdateForm[item.fieldName]).split(' ')[0]) |
|
|
|
// } |
|
|
|
// } |
|
|
|
// }) |
|
|
|
async validateRepeatFieldsBeforeSubmit(formName) { |
|
|
|
let hasError = false |
|
|
|
const repeatFields = this.formPreviewData.filter(item => item.isRepeat) |
|
|
|
for (const item of repeatFields) { |
|
|
|
const fieldValue = this.addOrUpdateForm[item.fieldName] |
|
|
|
if (!fieldValue) continue |
|
|
|
|
|
|
|
let response |
|
|
|
try { |
|
|
|
if (this.isDesFormType !== 'prearchiveLibrary') { |
|
|
|
const requestParams = { |
|
|
|
'categoryId': this.selectedCategory.id, |
|
|
|
'archivesId': this.arcId, |
|
|
|
'categoryLevel': this.collectLevel, |
|
|
|
'fieldName': item.fieldName, |
|
|
|
'fieldValue': fieldValue |
|
|
|
} |
|
|
|
response = await FetchIsRepeatByField(requestParams) |
|
|
|
} else { |
|
|
|
const requestParams = { |
|
|
|
'documentId': this.selectedCategory.id, |
|
|
|
'archivesId': this.arcId, |
|
|
|
'fieldName': item.fieldName, |
|
|
|
'value': fieldValue |
|
|
|
} |
|
|
|
response = await FetchReDoeditIsRepeat(requestParams) |
|
|
|
} |
|
|
|
if (response) { |
|
|
|
const errorMsg = `${item.fieldCnName}不可重复` |
|
|
|
|
|
|
|
if (this.$refs[formName]) { |
|
|
|
// 方式1:动态添加验证规则并触发验证 |
|
|
|
const repeatRule = { |
|
|
|
validator: (rule, value, callback) => { |
|
|
|
callback(new Error(errorMsg)) |
|
|
|
}, |
|
|
|
trigger: 'blur' |
|
|
|
} |
|
|
|
|
|
|
|
// 获取当前字段的验证规则 |
|
|
|
let fieldRules = this.rules[item.fieldName] || [] |
|
|
|
// 添加重复验证规则 |
|
|
|
fieldRules = [repeatRule, ...fieldRules.filter(r => r.validator && typeof r.validator === 'function')] |
|
|
|
this.$set(this.rules, item.fieldName, fieldRules) |
|
|
|
|
|
|
|
// 触发该字段的验证 |
|
|
|
this.$refs[formName].validateField(item.fieldName) |
|
|
|
} |
|
|
|
|
|
|
|
hasError = true |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
console.error('重复检查失败:', error) |
|
|
|
} |
|
|
|
} |
|
|
|
return !hasError |
|
|
|
}, |
|
|
|
async submitForm(formName, categoryId, quickPaperArcId, arcAddType) { |
|
|
|
if (this.archivesType === 'add' || this.archivesType === 'copy') { |
|
|
|
this.addOrUpdateForm.fonds_affiliation = this.selectedCategory.fondsId |
|
|
|
} |
|
|
|
const originalArchiveNo = this.addOrUpdateForm.archive_no |
|
|
|
|
|
|
|
console.log('this.addOrUpdateForm', this.addOrUpdateForm) |
|
|
|
this.$nextTick(() => { |
|
|
|
console.log('this.addOrUpdateForm.archive_no', this.addOrUpdateForm.archive_no) |
|
|
|
|
|
|
|
// 先验证重复字段 |
|
|
|
// if (this.archivesType !== 'edit') { |
|
|
|
const isRepeatValid = await this.validateRepeatFieldsBeforeSubmit(formName) |
|
|
|
if (!isRepeatValid) { |
|
|
|
return false |
|
|
|
} |
|
|
|
// } |
|
|
|
|
|
|
|
this.$nextTick(() => { |
|
|
|
this.$refs[formName].validate((valid, fields) => { |
|
|
|
if (valid) { |
|
|
|
this.addOrUpdateForm.archive_no = originalArchiveNo |
|
|
|
@ -1724,7 +1815,7 @@ export default { |
|
|
|
console.log(params) |
|
|
|
if (this.archivesType === 'add' || this.archivesType === 'copy') { |
|
|
|
collectAdd(params).then(res => { |
|
|
|
console.log('res', res) |
|
|
|
console.log('collectAdd-res', res) |
|
|
|
if (res.code !== 500) { |
|
|
|
this.$message({ message: res, type: 'success', offset: 8 }) |
|
|
|
this.$emit('close-dialog', parentsId) |
|
|
|
@ -1737,7 +1828,7 @@ export default { |
|
|
|
localStorage.removeItem('savePrevFromData') |
|
|
|
} |
|
|
|
} else { |
|
|
|
this.$message({ message: res.message, type: 'error', offset: 8 }) |
|
|
|
this.$message({ message: res.message + ',新增失败', type: 'error', offset: 8 }) |
|
|
|
this.$emit('close-dialog', parentsId) |
|
|
|
} |
|
|
|
this.$emit('formLoadingShow', false) |
|
|
|
@ -1749,7 +1840,7 @@ export default { |
|
|
|
this.$message({ message: res, type: 'success', offset: 8 }) |
|
|
|
this.$emit('close-dialog', parentsId) |
|
|
|
} else { |
|
|
|
this.$message({ message: res.message, type: 'error', offset: 8 }) |
|
|
|
this.$message({ message: res.message + ',编辑失败', type: 'error', offset: 8 }) |
|
|
|
this.$emit('close-dialog', parentsId) |
|
|
|
} |
|
|
|
this.$emit('formLoadingShow', false) |
|
|
|
|