2018-05-23 12:26:51 +00:00
|
|
|
import ngModule from '../../module';
|
2017-02-07 11:58:25 +00:00
|
|
|
|
2017-06-03 11:01:47 +00:00
|
|
|
export default class Controller {
|
2019-06-13 11:08:11 +00:00
|
|
|
constructor($, $state) {
|
|
|
|
this.$ = $;
|
2019-02-28 07:55:34 +00:00
|
|
|
this.$state = $state;
|
|
|
|
this.data = {
|
|
|
|
address: {
|
|
|
|
clientFk: parseInt($state.params.id),
|
|
|
|
isActive: true
|
|
|
|
},
|
|
|
|
isDefaultAddress: false
|
2017-02-07 11:58:25 +00:00
|
|
|
};
|
2019-02-28 07:55:34 +00:00
|
|
|
this.address = this.data.address;
|
|
|
|
}
|
|
|
|
|
2019-06-13 11:08:11 +00:00
|
|
|
setLocation() {
|
|
|
|
const location = this.$.postcode.selection;
|
|
|
|
if (!location || !location.town) return;
|
|
|
|
const town = location.town;
|
|
|
|
const province = town.province;
|
|
|
|
const country = province.country;
|
|
|
|
|
|
|
|
this.address.city = location.town.name;
|
|
|
|
this.address.provinceFk = province.id;
|
|
|
|
this.address.countryFk = country.id;
|
|
|
|
}
|
|
|
|
|
2019-02-28 07:55:34 +00:00
|
|
|
onSubmit() {
|
2019-06-13 11:08:11 +00:00
|
|
|
this.$.watcher.submit().then(res => {
|
2019-02-28 07:55:34 +00:00
|
|
|
if (res.data && this.data.isDefaultAddress)
|
|
|
|
this.client.defaultAddressFk = res.data.id;
|
|
|
|
|
|
|
|
this.$state.go('client.card.address.index');
|
|
|
|
});
|
2017-02-07 11:58:25 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-28 07:55:34 +00:00
|
|
|
|
|
|
|
Controller.$inject = ['$scope', '$state'];
|
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
|
|
|
});
|