add reactions

This commit is contained in:
Владислав Чикалкин 2020-11-11 19:46:37 +03:00
parent ac96ea502f
commit ebd7c2ef3c
4 changed files with 245 additions and 3 deletions

View File

@ -6,7 +6,6 @@ import { Status } from 'core/types/statuses';
import { ITableCell, TableProps } from 'core/types/Calculation/Store/tables';
import { toJS } from 'mobx';
import { calcPrice, calculatePerc, calculateRub } from './lib/tools';
import { query } from 'express';
import { gql } from '@apollo/client';
import { currentDate } from 'client/common/constants';
@ -409,6 +408,9 @@ const reactionEffects: IReactionEffect[] = [
break;
}
},
options: {
fireImmediately: true,
},
}),
calculationStore => ({
@ -2832,6 +2834,240 @@ const reactionEffects: IReactionEffect[] = [
fireImmediately: true,
},
}),
calculationStore => ({
expression: () => {
const { supplier } = calculationStore.values;
return supplier;
},
effect: supplierId => {
calculationStore.setOptions('selectFinDepartment', []);
calculationStore.setValue('finDepartment', null);
if (supplierId) {
const supplier = calculationStore.options.selectSupplier?.find(
x => x.accountid === supplierId,
);
if (supplier && supplier.evo_fin_department_accountid)
CalculationService.crmgqlquery({
query: gql`
query($accountid: Uuid!) {
account(accountid: $accountid) {
accountid
name
}
}
`,
toOptions: ['account'],
variables: {
accountid: supplier.evo_fin_department_accountid,
},
}).then(({ entities }) => {
if (entities.account && !Array.isArray(entities.account)) {
calculationStore.setOptions('selectFinDepartment', [
entities.account,
]);
}
});
}
},
}),
calculationStore => ({
expression: () => {
const { supplier, channel } = calculationStore.values;
return { supplierId: supplier, channelId: channel };
},
//TODO: add $ownerid: Uuid
effect: ({ supplierId, channelId }) => {
calculationStore.setOptions('selectAgent', []);
calculationStore.setValue('agent', null);
if (channelId === 100000002) {
CalculationService.crmgqlquery({
query: gql`
query(
$statecode: Int
$evo_account_type: [Int!]
$evo_legal_form: Int
) {
account: accounts(
statecode: $statecode
evo_account_type: $evo_account_type
evo_legal_form: $evo_legal_form
) {
accountid
name
}
}
`,
toOptions: ['account'],
variables: {
statecode: 0,
evo_account_type: [100000005],
evo_legal_form: 100000004,
},
}).then(({ entities }) => {
if (entities.account && Array.isArray(entities.account)) {
calculationStore.setOptions('selectAgent', entities.account);
}
});
} else {
if (supplierId) {
CalculationService.crmgqlquery({
query: gql`
query($statecode: Int, $salonaccountid: Uuid!) {
account: salon_agents(
statecode: $statecode
salonaccountid: $salonaccountid
) {
accountid
name
}
}
`,
toOptions: ['account'],
variables: {
statecode: 0,
salonaccountid: supplierId,
},
}).then(({ entities }) => {
if (entities.account && Array.isArray(entities.account)) {
calculationStore.setOptions('selectAgent', entities.account);
}
});
}
}
},
}),
//TODO
// calculationStore => ({
// expression: () => {
// const { product } = calculationStore.values;
// return product;
// },
// effect: productId => {
// if (productId) {
// const product = calculationStore.options.selectProduct?.find(
// x => x.evo_id === productId,
// );
// if (
// product &&
// product.evo_leasingobject_types &&
// Array.isArray(product.evo_leasingobject_types)
// ) {
// calculationStore.setOptions(
// 'selectLeaseObjectType',
// product.evo_leasingobject_types,
// );
// }
// }
// },
// }),
calculationStore => ({
expression: () => {
const { GPSBrand } = calculationStore.values;
return GPSBrand;
},
effect: GPSBrandId => {
calculationStore.setStatus('selectGPSModel', Status.Disabled);
calculationStore.setOptions('selectGPSModel', []);
calculationStore.setValue('GPSModel', null);
if (GPSBrandId) {
const gpsBrand = calculationStore.options.selectGPSBrand?.find(
x => x.evo_gps_brandid === GPSBrandId,
);
if (gpsBrand) {
CalculationService.crmgqlquery({
query: gql`
query($statecode: Int, $evo_gps_brandid: Uuid) {
evo_gps_model: evo_gps_models(
statecode: $statecode
evo_gps_brandid: $evo_gps_brandid
) {
evo_name
evo_gps_modelid
}
}
`,
variables: {
statecode: 0,
evo_gps_brandid: GPSBrandId,
},
toOptions: ['evo_gps_model'],
}).then(({ entities }) => {
if (
entities.evo_gps_model &&
Array.isArray(entities.evo_gps_model) &&
entities.evo_gps_model.length > 0
) {
calculationStore.setStatus('selectGPSModel', Status.Default);
calculationStore.setOptions(
'selectGPSModel',
entities.evo_gps_model,
);
calculationStore.setValue('GPSModel', null);
}
});
}
}
},
options: { fireImmediately: true },
}),
calculationStore => ({
expression: () => {
const { regionRegistration } = calculationStore.values;
return regionRegistration;
},
effect: regionRegistrationId => {
calculationStore.setStatus('selectTownRegistration', Status.Disabled);
calculationStore.setOptions('selectTownRegistration', []);
calculationStore.setValue('townRegistration', null);
if (regionRegistrationId) {
const regionRegistration = calculationStore.options.selectRegionRegistration?.find(
x => x.evo_regionid === regionRegistrationId,
);
if (regionRegistration) {
CalculationService.crmgqlquery({
query: gql`
query($statecode: Int, $evo_regionid: Uuid) {
evo_town: evo_towns(
statecode: $statecode
evo_regionid: $evo_regionid
) {
evo_name
evo_townid
}
}
`,
variables: {
statecode: 0,
evo_regionid: regionRegistrationId,
},
toOptions: ['evo_town'],
}).then(({ entities }) => {
if (
entities.evo_town &&
Array.isArray(entities.evo_town) &&
entities.evo_town.length > 0
) {
calculationStore.setStatus(
'selectTownRegistration',
Status.Default,
);
calculationStore.setOptions(
'selectTownRegistration',
entities.evo_town,
);
calculationStore.setValue('townRegistration', null);
}
});
}
}
},
options: { fireImmediately: true },
}),
];
export default reactionEffects;

View File

@ -42,7 +42,7 @@ const initialOptions: TEntityQuery[] = [
statecode: 0,
evo_legal_form: 100000001,
},
fields: ['accountid', 'name'],
fields: ['accountid', 'name', 'evo_fin_department_accountid'],
many: true,
toOption: true,
},

View File

@ -1,6 +1,12 @@
import { TValues, TValue } from 'core/types/Calculation/Store/values';
const initialValues: TValues<TValue> = {
lead: null,
opportunity: null,
quote: null,
channel: null,
contactClient: null,
account: null,
recalcWithRevision: false,
contactGender: 100000000,
leaseObjectPrice: 1000000,

View File

@ -79,7 +79,7 @@ export interface IEvoBaseproduct {
evo_datefrom?: Date;
evo_datefrom_param?: Date;
evo_dateto_param?: Date;
evo_leaseobject_types?: IEvoLeasingObjectType[];
evo_leasingobject_types?: IEvoLeasingObjectType[];
evo_brands?: IEvoBrand[];
}