salix/modules/worker/front/create/index.js

98 lines
2.4 KiB
JavaScript
Raw Normal View History

2022-11-14 14:19:16 +00:00
import ngModule from '../module';
import Section from 'salix/components/section';
export default class Controller extends Section {
constructor($element, $) {
super($element, $);
this.$http.get('NewWorkerConfigs/findOne').then(res => {
return this.worker = Object.assign({}, res.data);
});
}
onSubmit() {
return this.$.watcher.submit().then(json => {
2022-12-12 14:05:49 +00:00
this.$state.go('worker.card.basicData', {id: json.data.id});
2022-11-14 14:19:16 +00:00
});
}
autofillBic() {
if (!this.worker || !this.worker.iban) return;
let bankEntityId = parseInt(this.worker.iban.substr(4, 4));
let filter = {where: {id: bankEntityId}};
if (this.ibanCountry != 'ES') return;
this.$http.get(`BankEntities`, {filter}).then(response => {
const hasData = response.data && response.data[0];
if (hasData)
this.worker.bankEntityFk = response.data[0].id;
else if (!hasData)
this.worker.bankEntityFk = null;
});
}
get province() {
return this._province;
}
// Province auto complete
set province(selection) {
this._province = selection;
}
get town() {
return this._town;
}
// Town auto complete
set town(selection) {
this._town = selection;
if (!selection) return;
const province = selection.province;
const postcodes = selection.postcodes;
if (!this.client.provinceFk)
this.client.provinceFk = province.id;
if (postcodes.length === 1)
this.client.postcode = postcodes[0].code;
}
get postcode() {
return this._postcode;
}
// Postcode auto complete
set postcode(selection) {
this._postcode = selection;
if (!selection) return;
const town = selection.town;
const province = town.province;
if (!this.client.city)
this.client.city = town.name;
if (!this.client.provinceFk)
this.client.provinceFk = province.id;
}
onResponse(response) {
this.client.postcode = response.code;
this.client.city = response.city;
this.client.provinceFk = response.provinceFk;
}
}
Controller.$inject = ['$element', '$scope'];
ngModule.vnComponent('vnWorkerCreate', {
template: require('./index.html'),
controller: Controller
});