Browse Source

件号自动生成1

master
xuhuajiao 5 months ago
parent
commit
06ff9a4ce8
  1. 12
      src/api/collect/collect.js
  2. 142
      src/views/components/category/PreviewForm.vue
  3. 1
      src/views/prearchiveLibrary/index.vue

12
src/api/collect/collect.js

@ -403,6 +403,15 @@ export function FetchIsRepeatAllByArchivesNo(params) {
}) })
} }
// 通过档号获取最大件号
export function FetchMaxItemNoByArchivesNo(params) {
return request({
url: 'api/collect/getMaxItemNoByArchivesNo',
method: 'get',
params
})
}
export default { export default {
collectAdd, collectAdd,
collectEdit, collectEdit,
@ -444,5 +453,6 @@ export default {
FetchInitFileMarkCategoryView, FetchInitFileMarkCategoryView,
FetchMaxItemNoByParentId, FetchMaxItemNoByParentId,
FetchIsRepeatByArchivesNo, FetchIsRepeatByArchivesNo,
FetchIsRepeatAllByArchivesNo
FetchIsRepeatAllByArchivesNo,
FetchMaxItemNoByArchivesNo
} }

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

@ -201,7 +201,7 @@
<script> <script>
import { crud } from '@crud/crud' import { crud } from '@crud/crud'
import { FetchDoeditIsRepeat } from '@/api/archivesManage/archivesList' import { FetchDoeditIsRepeat } from '@/api/archivesManage/archivesList'
import { collectAdd, collectEdit, FetchIsRepeatByArchivesNo, FetchIsRepeatAllByArchivesNo } from '@/api/collect/collect'
import { collectAdd, collectEdit, FetchIsRepeatByArchivesNo, FetchIsRepeatAllByArchivesNo, FetchMaxItemNoByArchivesNo } from '@/api/collect/collect'
import { prearchEdit, FetchMergeToFile, FetchReDoeditIsRepeat } from '@/api/prearchiveLibrary/prearchiveLibrary' import { prearchEdit, FetchMergeToFile, FetchReDoeditIsRepeat } from '@/api/prearchiveLibrary/prearchiveLibrary'
import { getNoFormatField } from '@/api/system/category/fileNoFormat' import { getNoFormatField } from '@/api/system/category/fileNoFormat'
import draggable from 'vuedraggable' import draggable from 'vuedraggable'
@ -322,6 +322,10 @@ export default {
minioPreResult: [], // 存储合并后的minio结果 minioPreResult: [], // 存储合并后的minio结果
jsonArrayStore: [], // 存储每次的jsonArrayToSend项,与minioPreResult一一对应 jsonArrayStore: [], // 存储每次的jsonArrayToSend项,与minioPreResult一一对应
fileNameStore: [], // 存储每次的fileName,与minioPreResult一一对应 fileNameStore: [], // 存储每次的fileName,与minioPreResult一一对应
itemNoAutoGenerated: false, // 件号是否已自动生成
maxItemNo: null, // 最大可用件号
archiveNoDuplicate: false, // 档号是否重复
lastModifiedField: null, // 最后修改的字段名
iconShowRule: { iconShowRule: {
'3-1': 'item_no', '3-1': 'item_no',
'3-2': 'record_no', '3-2': 'record_no',
@ -793,6 +797,11 @@ export default {
// 使用for...of循环,支持async/await // 使用for...of循环,支持async/await
for (const val of this.autoMatic) { for (const val of this.autoMatic) {
// 如果件号字段没有值,跳过处理
if (val.fieldName === 'item_no' && !this.addOrUpdateForm[val.fieldName]) {
continue
}
if (!this.addOrUpdateForm[val.fieldName]) { if (!this.addOrUpdateForm[val.fieldName]) {
continue continue
} }
@ -856,8 +865,42 @@ export default {
}) })
console.log('档号生成完成:', string) console.log('档号生成完成:', string)
return string return string
}, },
// 根据档号查询最大件号并赋值
async fetchAndSetMaxItemNo(archivesNo) {
try {
const response = await FetchMaxItemNoByArchivesNo({ archivesNo })
console.log('查询最大件号响应:', response)
// 记录最大件号(每次都更新)
this.maxItemNo = response
if (response) {
// 获取件号字段的配置信息
const itemNoField = this.formPreviewData.find(item => item.fieldName === 'item_no')
if (itemNoField) {
// 将最大件号赋值给件号字段(每次都更新)
this.$set(this.addOrUpdateForm, 'item_no', response)
// 如果需要补零,则应用补零逻辑
if (itemNoField.isFilling && itemNoField.fillingDigit) {
this.autoAddZero(itemNoField.isFilling, 'item_no', response, itemNoField.fillingDigit)
}
// 标记件号已自动生成
this.itemNoAutoGenerated = true
console.log('件号自动赋值完成:', this.addOrUpdateForm.item_no)
// 检查件号是否是档号的组成项,如果是则重新生成档号(只在首次生成时执行)
const isItemNoInAutoMatic = this.autoMatic.some(item => item.fieldName === 'item_no')
if (isItemNoInAutoMatic && !this.itemNoAutoGenerated) {
// 如果件号是档号组成项,重新生成档号(只在首次时执行,避免循环调用)
await this.handleAuto()
}
}
}
} catch (error) {
console.error('查询最大件号失败:', error)
}
},
// 2. 抽离档号验证逻辑,确保异步验证稳定 // 2. 抽离档号验证逻辑,确保异步验证稳定
updateArchiveNoValidator(item) { updateArchiveNoValidator(item) {
const validateArchiveNo = async(value) => { const validateArchiveNo = async(value) => {
@ -874,27 +917,67 @@ export default {
if (this.isDesFormType === 'mergeFile') { if (this.isDesFormType === 'mergeFile') {
response = await FetchIsRepeatByArchivesNo({ archivesId: null, archivesNo: value }) response = await FetchIsRepeatByArchivesNo({ archivesId: null, archivesNo: value })
if (response !== 0) { if (response !== 0) {
// 标记档号重复
this.archiveNoDuplicate = true
// 档号重复时,请求最大件号
// await this.fetchAndSetMaxItemNo(value)
// 触发件号验证,显示最大可用件号
this.$nextTick(() => {
if (this.$refs.addOrUpdateForm) {
this.$refs.addOrUpdateForm.validateField('item_no')
}
})
return '请注意,该档号已被使用' return '请注意,该档号已被使用'
} }
// 档号不重复
this.archiveNoDuplicate = false
// 清除件号验证提示
this.$nextTick(() => {
if (this.$refs.addOrUpdateForm) {
this.$refs.addOrUpdateForm.clearValidate('item_no')
}
})
} else { } else {
response = await FetchIsRepeatAllByArchivesNo({ response = await FetchIsRepeatAllByArchivesNo({
archivesId: this.archivesType === 'add' ? null : this.addOrUpdateForm.id, archivesId: this.archivesType === 'add' ? null : this.addOrUpdateForm.id,
archivesNo: value archivesNo: value
}) })
if ((response.nodelcount !== 0 && response.delcount === 0) ||
(response.nodelcount === 0 && response.delcount !== 0)) {
if ((response.nodelcount !== 0 && response.delcount === 0) || (response.nodelcount === 0 && response.delcount !== 0)) {
// 标记档号重复
this.archiveNoDuplicate = true
// 档号重复时,请求最大件号
// await this.fetchAndSetMaxItemNo(value)
// 触发件号验证,显示最大可用件号
this.$nextTick(() => {
if (this.$refs.addOrUpdateForm) {
this.$refs.addOrUpdateForm.validateField('item_no')
}
})
return '请注意,该档号已被使用' return '请注意,该档号已被使用'
} }
// 档号不重复
this.archiveNoDuplicate = false
this.archivesSummaryResponse = response this.archivesSummaryResponse = response
// 清除件号验证提示
this.$nextTick(() => {
if (this.$refs.addOrUpdateForm) {
this.$refs.addOrUpdateForm.clearValidate('item_no')
}
})
} }
return null return null
} catch (error) { } catch (error) {
console.error('档号重复检查失败:', error) console.error('档号重复检查失败:', error)
// 验证失败时也应该重置状态
this.archiveNoDuplicate = false
return '验证档号重复时发生错误,请稍后再试' return '验证档号重复时发生错误,请稍后再试'
} }
} }
// 更新验证规则 // 更新验证规则
// 更新件号字段的验证规则(当档号重复时显示最大可用件号)
this.updateItemNoValidator()
this.$set(this.rules, item.fieldName, [{ this.$set(this.rules, item.fieldName, [{
validator: async(rule, value, callback) => { validator: async(rule, value, callback) => {
const errorMessage = await validateArchiveNo(value) const errorMessage = await validateArchiveNo(value)
@ -903,6 +986,19 @@ export default {
} else { } else {
callback() callback()
} }
// 档号验证完成后,根据结果决定是否触发件号验证
this.$nextTick(() => {
if (this.$refs.addOrUpdateForm) {
// 如果档号重复,自动触发件号验证以显示提示
if (this.archiveNoDuplicate) {
this.$refs.addOrUpdateForm.validateField('item_no')
} else {
// 如果档号不重复,清除件号的验证提示
this.$refs.addOrUpdateForm.clearValidate('item_no')
}
}
})
}, },
trigger: 'blur' // 明确触发时机 trigger: 'blur' // 明确触发时机
}]) }])
@ -915,6 +1011,22 @@ export default {
}) })
}, },
// 更新件号字段的验证规则
updateItemNoValidator() {
this.$set(this.rules, 'item_no', [{
validator: async(rule, value, callback) => {
// 通过档号是否重复来判断,而不是通过件号大小判断(因为可能有断档)
console.log('this.archiveNoDuplicate', this.archiveNoDuplicate)
if (this.archiveNoDuplicate && this.maxItemNo !== null) {
callback(new Error(`可用起始件号建议: ${this.maxItemNo}`))
} else {
callback()
}
},
trigger: ['blur', 'change'] // 同时支持 blur 和 change 触发
}])
},
// 排序 // 排序
compare(property) { compare(property) {
return function(a, b) { return function(a, b) {
@ -1086,6 +1198,9 @@ export default {
} }
}, },
async isRepeatHandle(item) { async isRepeatHandle(item) {
// 记录最后修改的字段名
this.lastModifiedField = item.fieldName
// 自动重复字段检查 // 自动重复字段检查
if (item.isRepeat) { if (item.isRepeat) {
const params = this.isDesFormType !== 'prearchiveLibrary' const params = this.isDesFormType !== 'prearchiveLibrary'
@ -1108,10 +1223,23 @@ export default {
if (this.isDesFormType !== 'prearchiveLibrary' && item.fieldName !== 'archive_no') { if (this.isDesFormType !== 'prearchiveLibrary' && item.fieldName !== 'archive_no') {
// 等待配置+档号生成都完成 // 等待配置+档号生成都完成
await this.fetchNoFormatAndAutoGenerate(this.selectedCategory.id) await this.fetchNoFormatAndAutoGenerate(this.selectedCategory.id)
const index = this.autoMatic.findIndex(i => item.fieldName === i.fieldName)
if (!item.isAutomatic && index !== -1) {
// 这里不需要再调用handleAuto,因为fetchNoFormatAndAutoGenerate已经包含了
// await this.handleAuto()
// 判断修改的字段是否是档号组成项(通过autoMatic数组判断)且不是件号
const isInAutoMatic = this.autoMatic && this.autoMatic.some(i => i.fieldName === item.fieldName)
if (isInAutoMatic && item.fieldName !== 'item_no') {
// 获取当前档号
const archiveNo = this.addOrUpdateForm.archive_no
if (archiveNo) {
// 1. 清除件号值和最大件号
this.$set(this.addOrUpdateForm, 'item_no', '')
this.maxItemNo = null
// 2. 立即更新档号(清除档号中的件号部分)
await this.handleAuto()
// 3. 请求最大件号并赋值
await this.fetchAndSetMaxItemNo(this.addOrUpdateForm.archive_no)
// 4. 再次更新档号(用新的件号)
await this.handleAuto()
}
} }
} }
}, },

1
src/views/prearchiveLibrary/index.vue

@ -238,7 +238,6 @@ export default {
isDisabled: false, isDisabled: false,
isHasCode: false, isHasCode: false,
selectedCategoryMerge: null, selectedCategoryMerge: null,
timer: null, timer: null,
mousedownTime: 0, mousedownTime: 0,
mousedownX: 0, mousedownX: 0,

Loading…
Cancel
Save