|
|
@@ -183,29 +183,28 @@ |
|
|
|
<el-table-column label="起始号段"> |
|
|
|
<template v-slot="scope"> |
|
|
|
<div class="input-wrap"> |
|
|
|
<el-form-item label="" :prop="`startId-${scope.$index}-${scope.row.startId}`" |
|
|
|
label-width="0px" style="width: 100%" :rules="{validator: validateStartId,trigger: 'blur', required: true, }"> |
|
|
|
<el-input maxlength="60" v-trim clearable v-model="scope.row.startId" |
|
|
|
placeholder="请输入起始号段" :disabled="typeOption === 'view' || typeOption === 'sure'" |
|
|
|
|
|
|
|
<el-form-item label="" :prop="`startId-${scope.$index}`" label-width="0px" style="width: 100%" |
|
|
|
:rules="[{ validator: validateIdOverlap, trigger: 'blur' }]"> |
|
|
|
<el-input v-model="scope.row.startId" placeholder="请输入开始号段" maxlength="20" |
|
|
|
:disabled="typeOption === 'view' || typeOption === 'sure'" clearable="" |
|
|
|
@input="handleApplyCount(scope.row, scope.$index)"/> |
|
|
|
</el-form-item> |
|
|
|
|
|
|
|
</div> |
|
|
|
</template> |
|
|
|
</el-table-column> |
|
|
|
<el-table-column label="结束号段"> |
|
|
|
<template v-slot="scope"> |
|
|
|
<div class="input-wrap"> |
|
|
|
<el-form-item label="" :prop="`endId-${scope.$index}-${scope.row.endId}`" |
|
|
|
label-width="0px" style="width: 100%" :rules="{ |
|
|
|
validator: validateEndId, |
|
|
|
trigger: 'blur', |
|
|
|
required: true, |
|
|
|
}"> |
|
|
|
<el-input maxlength="60" v-trim clearable v-model="scope.row.endId" |
|
|
|
placeholder="请输入结束号段" |
|
|
|
:disabled="typeOption === 'view' || typeOption === 'sure'" |
|
|
|
|
|
|
|
<el-form-item label="" :prop="`endId-${scope.$index}`" label-width="0px" style="width: 100%" |
|
|
|
:rules="[{required: true, validator: validateIdOverlap, trigger: 'blur' }]"> |
|
|
|
<el-input v-model="scope.row.endId" placeholder="请输入结束号段" maxlength="20" |
|
|
|
:disabled="typeOption === 'view' || typeOption === 'sure'" clearable |
|
|
|
@input="handleApplyCount(scope.row, scope.$index)"/> |
|
|
|
</el-form-item> |
|
|
|
|
|
|
|
</div> |
|
|
|
</template> |
|
|
|
</el-table-column> |
|
|
@@ -213,7 +212,7 @@ |
|
|
|
<el-table-column label="操作" width="340" v-if="typeOption === 'add' || typeOption === 'edit'"> |
|
|
|
<template v-slot="scope"> |
|
|
|
<el-button class="op-btn" type="primary" @click="validHandle(scope.row, scope.$index)">校验</el-button> |
|
|
|
<el-button class="op-btn" type="danger" v-if="scope.$index > 0" @click="deleteHandle(scope.row, scope.$index)">删除</el-button> |
|
|
|
<el-button class="op-btn" type="danger" :disabled="addForm.detailList.length <= 1" @click="deleteHandle(scope.row, scope.$index)">删除</el-button> |
|
|
|
<el-button class="op-btn" type="success" v-if="scope.$index === (addForm.detailList.length - 1)" @click="addMoreHandle(scope.row)">继续添加</el-button> |
|
|
|
</template> |
|
|
|
</el-table-column> |
|
|
@@ -597,9 +596,21 @@ function validDetailHandle(row: IObject) { |
|
|
|
} |
|
|
|
|
|
|
|
function deleteHandle(row: IObject, index: number) { |
|
|
|
if (addForm.value.detailList.length <= 1) { |
|
|
|
ElMessage.warning("至少保留一行数据!"); |
|
|
|
return; |
|
|
|
} |
|
|
|
let list = [...addForm.value.detailList]; |
|
|
|
list.splice(index, 1); |
|
|
|
addForm.value.detailList = list; |
|
|
|
|
|
|
|
nextTick(() => { |
|
|
|
dataFormRef.value?.clearValidate(); // 清除所有校验 |
|
|
|
list.forEach((_, i) => { |
|
|
|
dataFormRef.value?.validateField([`startId-${i}`]); |
|
|
|
dataFormRef.value?.validateField([`endId-${i}`]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
// 继续添加 |
|
|
@@ -646,6 +657,48 @@ function validateEndId(rule: any, value: string, callback: (e?: Error) => any) { |
|
|
|
callback(); |
|
|
|
} |
|
|
|
|
|
|
|
// 校验函数 |
|
|
|
function validateIdOverlap(rule: any, value: string, callback: (e?: Error) => void) { |
|
|
|
const indexArr = rule.field.split("-"); |
|
|
|
const currentIndex = parseInt(indexArr[1]); |
|
|
|
const field = indexArr[0]; |
|
|
|
const detailList = addForm.value.detailList; |
|
|
|
|
|
|
|
const currentRow = detailList[currentIndex]; |
|
|
|
const currentStart = currentRow.startId; |
|
|
|
const currentEnd = currentRow.endId; |
|
|
|
|
|
|
|
// if (!currentStart || !currentEnd) { |
|
|
|
// return callback(new Error("请先填写完整的号段范围!")); |
|
|
|
// } |
|
|
|
|
|
|
|
if(currentStart && currentEnd) { |
|
|
|
if (currentStart > currentEnd) { |
|
|
|
return callback(new Error("结束号段必须大于或等于开始号段!")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
for (let i = 0; i < detailList.length; i++) { |
|
|
|
if (i === currentIndex) continue; |
|
|
|
|
|
|
|
const otherRow = detailList[i]; |
|
|
|
const otherStart = otherRow.startId; |
|
|
|
const otherEnd = otherRow.endId; |
|
|
|
|
|
|
|
if (otherStart && otherEnd) { |
|
|
|
if ( |
|
|
|
(currentStart >= otherStart && currentStart <= otherEnd) || |
|
|
|
(currentEnd >= otherStart && currentEnd <= otherEnd) || |
|
|
|
(otherStart >= currentStart && otherStart <= currentEnd) || |
|
|
|
(otherEnd >= currentStart && otherEnd <= currentEnd) |
|
|
|
) { |
|
|
|
return callback(new Error(`号段范围与第 ${i + 1} 行重叠!`)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
callback(); |
|
|
|
} |
|
|
|
// 校验开始编号 |
|
|
|
function validateStartId( |
|
|
|
rule: any, |