salix/modules/client/front/address/create/index.js

65 lines
1.5 KiB
JavaScript

import ngModule from '../../module';
import Component from 'core/lib/component';
export default class Controller extends Component {
constructor($element, $) {
super($element, $);
this.address = {
isActive: true,
isDefaultAddress: false
};
}
get postcodeSelection() {
return this._postcodeSelection;
}
set postcodeSelection(selection) {
this._postcodeSelection = selection;
if (!selection) return;
const town = selection.town;
const province = town.province;
this.address.city = town.name;
this.address.provinceFk = province.id;
}
onResponse(response) {
this.address.postalCode = response.code;
}
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);
}
}
Controller.$inject = ['$element', '$scope'];
ngModule.component('vnClientAddressCreate', {
template: require('./index.html'),
controller: Controller,
bindings: {
client: '<'
}
});