elt validations

This commit is contained in:
Chika 2021-06-18 14:58:39 +03:00
parent dccbce9adb
commit af0d37e446
3 changed files with 50 additions and 6 deletions

View File

@ -10,14 +10,13 @@ export const requiredFields: ElementsNames[] = [
'cbxLeaseObjectUsed',
'tbxLeaseObjectYear',
'tbxLeaseObjectMotorPower',
'selectEngineType',
'tbxLeasingPeriod',
'tbxLeaseObjectPrice',
'tbxSupplierDiscountRub',
'tbxInsFranchise',
'selectLeaseObjectCategory',
'selectLeaseObjectUseFor',
'tbxINNForCalc',
'radioInfuranceOPF',
];
export const conditions: TElements<ValidationCondition> = {
@ -62,6 +61,46 @@ export const conditions: TElements<ValidationCondition> = {
isValid: true,
};
},
selectLeaseObjectCategory: calculationStore => {
const leaseObjectCategory = calculationStore.getValue(
'leaseObjectCategory',
);
const leaseObjectType = calculationStore.getOption('selectLeaseObjectType');
if (!leaseObjectCategory) {
if (['6', '10'].includes(leaseObjectType?.evo_id || '')) {
return {
isValid: true,
};
} else
return {
isValid: false,
message: 'Не указана категория ТС',
};
}
return {
isValid: true,
};
},
selectEngineType: calculationStore => {
const engineType = calculationStore.getValue('engineType');
if (!engineType) {
if (['8'].includes(engineType?.evo_id || ''))
return {
isValid: true,
};
else
return {
isValid: false,
message: 'Не указан тип двигателя',
};
}
return {
isValid: true,
};
},
};
export const resetFields: ElementsNames[] = [

View File

@ -11,7 +11,7 @@ const mapCategory = {
};
const mapSubCategoryBuilder = (leaseObjectUseFor, maxMass, countSeats) => ({
100000000: '0',
100000000: () => '0',
100000001: () => {
if (leaseObjectUseFor === 100000001) {
return '11';
@ -70,7 +70,8 @@ export default function (this: ICalculationStore) {
maxMass,
countSeats,
);
const subCategory = mapSubCategory[leaseObjectCategory]();
const subCategory = get(mapSubCategory, leaseObjectCategory, () => '0')();
let seatingCapacity = 0;
if (leaseObjectCategory === 100000003) {

View File

@ -3,6 +3,7 @@ import {
TElements,
} from 'core/types/Calculation/Store/elements';
import { ValidationCondition } from 'core/validation/validate';
import { omit } from 'lodash';
import { conditions as kaskoConditions } from '../../Kasko/lib/validation';
export const requiredFields: ElementsNames[] = [
@ -16,9 +17,9 @@ export const requiredFields: ElementsNames[] = [
'tbxMaxMass',
'tbxCountSeats',
'cbxWithTrailer',
'selectLeaseObjectCategory',
'tbxINNForCalc',
'radioObjectRegistration',
'radioInfuranceOPF',
];
const conditions: TElements<ValidationCondition> = {
@ -50,5 +51,8 @@ export const resetFields: ElementsNames[] = [
export default {
requiredFields,
conditions: Object.assign(conditions, kaskoConditions),
conditions: Object.assign(
conditions,
omit(kaskoConditions, ['selectEngineType']),
),
};