85 lines
1.9 KiB
JavaScript
85 lines
1.9 KiB
JavaScript
import ngModule from '../../module';
|
|
import Section from 'salix/components/section';
|
|
|
|
export default class Controller extends Section {
|
|
constructor($element, $) {
|
|
super($element, $);
|
|
|
|
this.address = {
|
|
isActive: true,
|
|
isDefaultAddress: false
|
|
};
|
|
}
|
|
|
|
onSubmit() {
|
|
this.$.watcher.submit().then(res => {
|
|
if (this.address.isDefaultAddress)
|
|
this.client.defaultAddressFk = res.data.id;
|
|
|
|
this.$state.go('client.card.address.index');
|
|
});
|
|
}
|
|
|
|
showCustomAgent(event) {
|
|
if (event.defaultPrevented) return;
|
|
event.preventDefault();
|
|
|
|
this.$.customAgent.show();
|
|
}
|
|
|
|
onCustomAgentAccept() {
|
|
return this.$http.post(`CustomsAgents`, this.newCustomsAgent)
|
|
.then(res => this.address.customsAgentFk = res.data.id);
|
|
}
|
|
|
|
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;
|
|
|
|
this.address.provinceId = province.id;
|
|
|
|
if (postcodes.length === 1)
|
|
this.address.postalCode = 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;
|
|
|
|
this.address.city = town.name;
|
|
this.address.provinceId = province.id;
|
|
}
|
|
|
|
onResponse(response) {
|
|
this.address.postalCode = response.code;
|
|
}
|
|
}
|
|
|
|
Controller.$inject = ['$element', '$scope'];
|
|
|
|
ngModule.component('vnClientAddressCreate', {
|
|
template: require('./index.html'),
|
|
controller: Controller,
|
|
bindings: {
|
|
client: '<'
|
|
}
|
|
});
|