salix/modules/client/front/credit-insurance/index/index.js

69 lines
1.8 KiB
JavaScript
Raw Permalink Normal View History

2018-05-23 12:26:51 +00:00
import ngModule from '../../module';
2020-03-17 10:17:50 +00:00
import Section from 'salix/components/section';
2019-10-01 14:17:57 +00:00
import './style.scss';
2020-03-17 10:17:50 +00:00
class Controller extends Section {
$onChanges() {
if (this.client && this.client.id)
this._getClassifications(this.client.id);
}
_getClassifications(clientId) {
let filter = {
2018-03-28 13:07:48 +00:00
order: 'finished ASC, started DESC',
include: [
{
relation: 'insurances',
scope: {
fields: ['id', 'credit', 'created', 'grade'],
order: 'created DESC',
limit: 2
}
}
],
where: {client: clientId}
};
filter = encodeURIComponent(JSON.stringify(filter));
let query = `CreditClassifications?filter=${filter}`;
this.$http.get(query).then(res => {
if (res.data)
this.classifications = res.data;
});
}
canCreateNew() {
if (!this.classifications)
return false;
let items = this.classifications;
for (let i = 0; i < items.length; i++) {
if (!items[i].finished)
return false;
}
return true;
}
closeContract(classification) {
2018-03-28 13:07:48 +00:00
this.classificationId = classification.id;
2020-03-17 10:17:50 +00:00
this.$.closeContract.show();
2018-03-28 13:07:48 +00:00
}
2020-07-29 08:47:48 +00:00
returnDialog() {
2023-01-16 14:18:24 +00:00
let params = {finished: Date.vnNow()};
2020-07-29 08:47:48 +00:00
this.$http.patch(`CreditClassifications/${this.classificationId}`, params).then(() => {
this._getClassifications(this.client.id);
});
}
}
ngModule.vnComponent('vnClientCreditInsuranceIndex', {
2018-05-23 12:26:51 +00:00
template: require('./index.html'),
controller: Controller,
bindings: {
client: '<'
}
});