fix bug
This commit is contained in:
@@ -467,6 +467,15 @@ const createTimeRangeMap = {
|
||||
createTimeRange: ['createTimeStart', 'createTimeEnd'],
|
||||
};
|
||||
|
||||
const standardNumberFields = [
|
||||
'scoreRateLower',
|
||||
'scoreRateUpper',
|
||||
'scoreRateIncrease',
|
||||
'creditLimitLower',
|
||||
'creditLimitUpper',
|
||||
'creditLimitIncrease',
|
||||
];
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
@@ -657,14 +666,7 @@ export default {
|
||||
(detail.categories || []).forEach(category => {
|
||||
map[category.categoryCode] = {
|
||||
...category,
|
||||
items: (category.items || []).map(item => ({
|
||||
...item,
|
||||
optionType: this.normalizeOptionType(item.optionType),
|
||||
options:
|
||||
item.options && item.options.length
|
||||
? item.options.map(option => this.normalizeOption(option))
|
||||
: [this.emptyOption()],
|
||||
})),
|
||||
items: (category.items || []).map(item => this.normalizeItem(item)),
|
||||
};
|
||||
});
|
||||
return {
|
||||
@@ -673,7 +675,7 @@ export default {
|
||||
...(map[category.categoryCode] || category),
|
||||
categoryName: category.categoryName,
|
||||
})),
|
||||
standards: detail.standards || [],
|
||||
standards: (detail.standards || []).map(standard => this.normalizeStandard(standard)),
|
||||
};
|
||||
},
|
||||
openConfig(row, readonly = false) {
|
||||
@@ -710,13 +712,16 @@ export default {
|
||||
return value === 'score' || value === 2 || String(value) === 'score' ? 'score' : 'option';
|
||||
},
|
||||
normalizeItem(item = {}) {
|
||||
const normalized = { ...this.emptyItem(), ...item };
|
||||
const score = Number(this.normalizePlainDecimal(normalized.score));
|
||||
return {
|
||||
...this.emptyItem(),
|
||||
...item,
|
||||
optionType: this.normalizeOptionType(item.optionType),
|
||||
...normalized,
|
||||
score: Number.isFinite(score) ? score : normalized.score,
|
||||
baseValue: this.normalizePlainDecimal(normalized.baseValue),
|
||||
optionType: this.normalizeOptionType(normalized.optionType),
|
||||
options:
|
||||
item.options && item.options.length
|
||||
? item.options.map(option => this.normalizeOption(option))
|
||||
normalized.options && normalized.options.length
|
||||
? normalized.options.map(option => this.normalizeOption(option))
|
||||
: [this.emptyOption()],
|
||||
};
|
||||
},
|
||||
@@ -724,6 +729,8 @@ export default {
|
||||
const normalized = { ...this.emptyOption(), ...option };
|
||||
return {
|
||||
...normalized,
|
||||
score: this.normalizePlainDecimal(normalized.score),
|
||||
changeValue: this.normalizePlainDecimal(normalized.changeValue),
|
||||
changeType:
|
||||
normalized.changeType === 'decrease' ||
|
||||
normalized.changeType === '每减少' ||
|
||||
@@ -738,6 +745,35 @@ export default {
|
||||
: 'add',
|
||||
};
|
||||
},
|
||||
normalizePlainDecimal(value) {
|
||||
if (value === undefined || value === null || value === '') return '';
|
||||
const text = String(value).trim();
|
||||
const matched = text.match(/^([+-]?)(\d+)(?:\.(\d*))?[eE]([+-]?\d+)$/);
|
||||
if (!matched) return text;
|
||||
const [, sign, integer, decimal = '', exponentText] = matched;
|
||||
const exponent = Number(exponentText);
|
||||
const digits = `${integer}${decimal}`;
|
||||
const decimalIndex = integer.length + exponent;
|
||||
const resultLength =
|
||||
decimalIndex <= 0 ? 2 - decimalIndex + digits.length : Math.max(decimalIndex, digits.length);
|
||||
if (!Number.isSafeInteger(exponent) || resultLength > 1000) return text;
|
||||
let result;
|
||||
if (decimalIndex <= 0) {
|
||||
result = `0.${'0'.repeat(-decimalIndex)}${digits}`;
|
||||
} else if (decimalIndex >= digits.length) {
|
||||
result = `${digits}${'0'.repeat(decimalIndex - digits.length)}`;
|
||||
} else {
|
||||
result = `${digits.slice(0, decimalIndex)}.${digits.slice(decimalIndex)}`;
|
||||
}
|
||||
return `${sign === '-' ? '-' : ''}${result}`;
|
||||
},
|
||||
normalizeStandard(standard = {}) {
|
||||
const normalized = { ...this.emptyStandard(), ...standard };
|
||||
standardNumberFields.forEach(field => {
|
||||
normalized[field] = this.normalizePlainDecimal(normalized[field]);
|
||||
});
|
||||
return normalized;
|
||||
},
|
||||
handleOptionTypeChange(value) {
|
||||
this.itemForm.optionType = this.normalizeOptionType(value);
|
||||
this.itemForm.options = (this.itemForm.options || []).map(option =>
|
||||
@@ -770,6 +806,10 @@ export default {
|
||||
(payload.categories || []).forEach(category => {
|
||||
(category.items || []).forEach(item => {
|
||||
item.score = this.toScoreValue(item.score);
|
||||
item.baseValue =
|
||||
this.normalizeOptionType(item.optionType) === 'score'
|
||||
? this.normalizePlainDecimal(item.baseValue)
|
||||
: null;
|
||||
(item.options || []).forEach(option => {
|
||||
option.score = this.toScoreValue(option.score);
|
||||
if (this.normalizeOptionType(item.optionType) === 'score') {
|
||||
@@ -778,6 +818,11 @@ export default {
|
||||
});
|
||||
});
|
||||
});
|
||||
(payload.standards || []).forEach(standard => {
|
||||
standardNumberFields.forEach(field => {
|
||||
standard[field] = this.normalizePlainDecimal(standard[field]);
|
||||
});
|
||||
});
|
||||
return payload;
|
||||
},
|
||||
hasDuplicateItemName(itemName, currentIndex = -1) {
|
||||
@@ -844,7 +889,8 @@ export default {
|
||||
const item = JSON.parse(JSON.stringify(this.itemForm));
|
||||
item.itemName = String(item.itemName || '').trim();
|
||||
item.optionType = this.normalizeOptionType(item.optionType);
|
||||
item.baseValue = item.optionType === 'score' ? String(item.baseValue).trim() : null;
|
||||
item.baseValue =
|
||||
item.optionType === 'score' ? this.normalizePlainDecimal(item.baseValue) : null;
|
||||
item.options = item.options.map(option => ({
|
||||
...option,
|
||||
optionName: String(option.optionName || '').trim(),
|
||||
@@ -874,7 +920,9 @@ export default {
|
||||
},
|
||||
openStandard(row, index = -1) {
|
||||
this.currentStandardIndex = index;
|
||||
this.standardForm = row ? JSON.parse(JSON.stringify(row)) : this.emptyStandard();
|
||||
this.standardForm = row
|
||||
? this.normalizeStandard(JSON.parse(JSON.stringify(row)))
|
||||
: this.emptyStandard();
|
||||
this.standardBox = true;
|
||||
},
|
||||
hasDuplicateCreditLevel(creditLevel, currentIndex = -1) {
|
||||
@@ -943,14 +991,7 @@ export default {
|
||||
}
|
||||
const standard = JSON.parse(JSON.stringify(this.standardForm));
|
||||
standard.creditLevel = String(standard.creditLevel || '').trim();
|
||||
[
|
||||
'scoreRateLower',
|
||||
'scoreRateUpper',
|
||||
'scoreRateIncrease',
|
||||
'creditLimitLower',
|
||||
'creditLimitUpper',
|
||||
'creditLimitIncrease',
|
||||
].forEach(field => {
|
||||
standardNumberFields.forEach(field => {
|
||||
standard[field] = Number(standard[field]);
|
||||
});
|
||||
const nextStandards = JSON.parse(JSON.stringify(this.configForm.standards));
|
||||
@@ -1130,14 +1171,6 @@ export default {
|
||||
this.$message.warning('发布前至少配置1条信用等级评估标准');
|
||||
return false;
|
||||
}
|
||||
const requiredFields = [
|
||||
'scoreRateLower',
|
||||
'scoreRateUpper',
|
||||
'scoreRateIncrease',
|
||||
'creditLimitLower',
|
||||
'creditLimitUpper',
|
||||
'creditLimitIncrease',
|
||||
];
|
||||
for (const standard of standards) {
|
||||
if (!standard.creditLevel) {
|
||||
this.$message.warning('评估标准中的信用等级不能为空');
|
||||
@@ -1147,7 +1180,7 @@ export default {
|
||||
this.$message.warning('评估标准中的信用等级只能选择A/B/C/D/E/F');
|
||||
return false;
|
||||
}
|
||||
if (requiredFields.some(field => this.isBlankValue(standard[field]))) {
|
||||
if (standardNumberFields.some(field => this.isBlankValue(standard[field]))) {
|
||||
this.$message.warning(`${standard.creditLevel}信用等级评估标准必填项未填写完整`);
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user