2018-05-23 12:26:51 +00:00
|
|
|
import ngModule from '../../module';
|
2020-01-24 08:47:24 +00:00
|
|
|
import Component from 'core/lib/component';
|
|
|
|
|
|
|
|
export default class Controller extends Component {
|
|
|
|
constructor($element, $) {
|
|
|
|
super($element, $);
|
2017-02-07 11:58:25 +00:00
|
|
|
|
2020-01-28 08:03:20 +00:00
|
|
|
this.address = {
|
|
|
|
isActive: true,
|
2019-02-28 07:55:34 +00:00
|
|
|
isDefaultAddress: false
|
2017-02-07 11:58:25 +00:00
|
|
|
};
|
2019-02-28 07:55:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onSubmit() {
|
2019-06-13 11:08:11 +00:00
|
|
|
this.$.watcher.submit().then(res => {
|
2020-01-28 08:03:20 +00:00
|
|
|
if (this.address.isDefaultAddress)
|
2019-02-28 07:55:34 +00:00
|
|
|
this.client.defaultAddressFk = res.data.id;
|
|
|
|
|
|
|
|
this.$state.go('client.card.address.index');
|
|
|
|
});
|
2017-02-07 11:58:25 +00:00
|
|
|
}
|
2020-01-24 08:47:24 +00:00
|
|
|
|
2020-01-28 10:56:26 +00:00
|
|
|
showCustomAgent(event) {
|
|
|
|
if (event.defaultPrevented) return;
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
this.$.customAgent.show();
|
|
|
|
}
|
|
|
|
|
2020-01-24 08:47:24 +00:00
|
|
|
onCustomAgentAccept() {
|
|
|
|
return this.$http.post(`CustomsAgents`, this.newCustomsAgent)
|
|
|
|
.then(res => this.address.customsAgentFk = res.data.id);
|
|
|
|
}
|
2020-02-24 10:27:36 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2017-02-07 11:58:25 +00:00
|
|
|
}
|
2019-02-28 07:55:34 +00:00
|
|
|
|
2020-01-24 08:47:24 +00:00
|
|
|
Controller.$inject = ['$element', '$scope'];
|
2017-02-07 11:58:25 +00:00
|
|
|
|
2018-05-23 12:26:51 +00:00
|
|
|
ngModule.component('vnClientAddressCreate', {
|
|
|
|
template: require('./index.html'),
|
2019-02-28 07:55:34 +00:00
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
client: '<'
|
|
|
|
}
|
2017-06-03 11:01:47 +00:00
|
|
|
});
|