Browse Source

值不可重复

master
xuhuajiao 2 weeks ago
parent
commit
4de05c1c4c
  1. 11
      src/views/collectReorganizi/collectionLibrary/module/collectHeader.vue
  2. 149
      src/views/components/category/PreviewForm.vue
  3. 2
      src/views/prearchiveLibrary/index.vue

11
src/views/collectReorganizi/collectionLibrary/module/collectHeader.vue

@ -826,16 +826,11 @@ export default {
console.log('data.echo', data.echo) console.log('data.echo', data.echo)
const archivesNo = data.echo.archive_no const archivesNo = data.echo.archive_no
if (archivesNo) { if (archivesNo) {
let categoryId
if (this.isDesFormType !== 'mergeFile' && this.isDesFormType !== 'arcives' && this.isDesFormType !== 'manageArcives') {
categoryId = this.selectedCategory.pid
} else {
categoryId = this.selectedCategory.id
}
const categoryId = this.selectedCategory.id
this.$refs.previewForm.FetchNoFormatField(categoryId).then(() => { this.$refs.previewForm.FetchNoFormatField(categoryId).then(() => {
FetchMaxItemNoByArchivesNo({ archivesNo, categoryId, categoryLevel: this.collectLevel }).then(res => { FetchMaxItemNoByArchivesNo({ archivesNo, categoryId, categoryLevel: this.collectLevel }).then(res => {
if (res) { if (res) {
const newItemNo = (parseInt(res) + 1).toString()
const newItemNo = (parseInt(res)).toString()
const field = this.formPreviewData.find(item => item.fieldName === 'item_no') const field = this.formPreviewData.find(item => item.fieldName === 'item_no')
if (field && field.isFilling) { if (field && field.isFilling) {
const fillingDigit = field.fillingDigit const fillingDigit = field.fillingDigit
@ -843,7 +838,9 @@ export default {
} else { } else {
this.$set(this.$refs.previewForm.addOrUpdateForm, 'item_no', newItemNo) this.$set(this.$refs.previewForm.addOrUpdateForm, 'item_no', newItemNo)
} }
this.$refs.previewForm.maxItemNo = newItemNo
this.$refs.previewForm.handleAuto() this.$refs.previewForm.handleAuto()
this.arcId = null
} }
}) })
}) })

149
src/views/components/category/PreviewForm.vue

@ -1193,21 +1193,56 @@ export default {
}) })
}, 100) }, 100)
}, },
// api
// api -
handlerIsRepeat(params, item) { 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) { async isRepeatHandle(item) {
// //
@ -1218,14 +1253,14 @@ export default {
const params = this.isDesFormType !== 'prearchiveLibrary' const params = this.isDesFormType !== 'prearchiveLibrary'
? { ? {
'categoryId': this.selectedCategory.id, 'categoryId': this.selectedCategory.id,
// 'archivesId': this.arcId,
'archivesId': this.arcId,
'categoryLevel': this.collectLevel, 'categoryLevel': this.collectLevel,
'fieldName': item.fieldName, 'fieldName': item.fieldName,
'fieldValue': this.addOrUpdateForm[item.fieldName] 'fieldValue': this.addOrUpdateForm[item.fieldName]
} }
: { : {
'documentId': this.selectedCategory.id, 'documentId': this.selectedCategory.id,
'archivesId': null,
'archivesId': this.arcId,
'fieldName': item.fieldName, 'fieldName': item.fieldName,
'value': this.addOrUpdateForm[item.fieldName] 'value': this.addOrUpdateForm[item.fieldName]
} }
@ -1278,14 +1313,14 @@ export default {
const params = this.isDesFormType !== 'prearchiveLibrary' && this.isDesFormType !== 'mergeFile' const params = this.isDesFormType !== 'prearchiveLibrary' && this.isDesFormType !== 'mergeFile'
? { ? {
'categoryId': this.selectedCategory.id, 'categoryId': this.selectedCategory.id,
// 'archivesId': this.arcId,
'archivesId': this.arcId,
'categoryLevel': this.collectLevel, 'categoryLevel': this.collectLevel,
'fieldName': this.treeCurrentFiled.fieldName, 'fieldName': this.treeCurrentFiled.fieldName,
'fieldValue': val.dictionaryName 'fieldValue': val.dictionaryName
} }
: { : {
'documentId': this.selectedCategory.id, 'documentId': this.selectedCategory.id,
'archivesId': null,
'archivesId': this.arcId,
'fieldName': this.treeCurrentFiled.fieldName, 'fieldName': this.treeCurrentFiled.fieldName,
'value': val.dictionaryName 'value': val.dictionaryName
} }
@ -1569,24 +1604,80 @@ export default {
this.formPreviewData[newIndex] = index 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') { if (this.archivesType === 'add' || this.archivesType === 'copy') {
this.addOrUpdateForm.fonds_affiliation = this.selectedCategory.fondsId this.addOrUpdateForm.fonds_affiliation = this.selectedCategory.fondsId
} }
const originalArchiveNo = this.addOrUpdateForm.archive_no const originalArchiveNo = this.addOrUpdateForm.archive_no
console.log('this.addOrUpdateForm', this.addOrUpdateForm) 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) => { this.$refs[formName].validate((valid, fields) => {
if (valid) { if (valid) {
this.addOrUpdateForm.archive_no = originalArchiveNo this.addOrUpdateForm.archive_no = originalArchiveNo
@ -1724,7 +1815,7 @@ export default {
console.log(params) console.log(params)
if (this.archivesType === 'add' || this.archivesType === 'copy') { if (this.archivesType === 'add' || this.archivesType === 'copy') {
collectAdd(params).then(res => { collectAdd(params).then(res => {
console.log('res', res)
console.log('collectAdd-res', res)
if (res.code !== 500) { if (res.code !== 500) {
this.$message({ message: res, type: 'success', offset: 8 }) this.$message({ message: res, type: 'success', offset: 8 })
this.$emit('close-dialog', parentsId) this.$emit('close-dialog', parentsId)
@ -1737,7 +1828,7 @@ export default {
localStorage.removeItem('savePrevFromData') localStorage.removeItem('savePrevFromData')
} }
} else { } 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('close-dialog', parentsId)
} }
this.$emit('formLoadingShow', false) this.$emit('formLoadingShow', false)
@ -1749,7 +1840,7 @@ export default {
this.$message({ message: res, type: 'success', offset: 8 }) this.$message({ message: res, type: 'success', offset: 8 })
this.$emit('close-dialog', parentsId) this.$emit('close-dialog', parentsId)
} else { } 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('close-dialog', parentsId)
} }
this.$emit('formLoadingShow', false) this.$emit('formLoadingShow', false)

2
src/views/prearchiveLibrary/index.vue

@ -418,8 +418,10 @@ export default {
this.$refs.previewForm.addOrUpdateForm = data.echo this.$refs.previewForm.addOrUpdateForm = data.echo
this.$refs.previewForm.fileOriginal = '' this.$refs.previewForm.fileOriginal = ''
this.$refs.previewForm.fileJsonString = '' this.$refs.previewForm.fileJsonString = ''
this.arcId = null
} else { } else {
this.$refs.previewForm.archivesType = 'add' this.$refs.previewForm.archivesType = 'add'
this.arcId = null
} }
}) })
}) })

Loading…
Cancel
Save