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

65 lines
1.5 KiB
JavaScript
Raw Normal View History

2018-05-23 12:26:51 +00:00
import ngModule from '../../module';
import Component from 'core/lib/component';
export default class Controller extends Component {
constructor($element, $) {
super($element, $);
2020-01-28 08:03:20 +00:00
this.address = {
isActive: true,
isDefaultAddress: false
};
}
2019-07-08 12:07:09 +00:00
get postcodeSelection() {
return this._postcodeSelection;
}
set postcodeSelection(selection) {
this._postcodeSelection = selection;
if (!selection) return;
const town = selection.town;
const province = town.province;
2019-07-08 12:07:09 +00:00
this.address.city = town.name;
this.address.provinceFk = province.id;
}
2019-07-08 12:07:09 +00:00
onResponse(response) {
this.address.postalCode = response.code;
}
onSubmit() {
this.$.watcher.submit().then(res => {
2020-01-28 08:03:20 +00:00
if (this.address.isDefaultAddress)
this.client.defaultAddressFk = res.data.id;
this.$state.go('client.card.address.index');
});
}
2020-01-28 10:56:26 +00:00
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'];
2018-05-23 12:26:51 +00:00
ngModule.component('vnClientAddressCreate', {
template: require('./index.html'),
controller: Controller,
bindings: {
client: '<'
}
2017-06-03 11:01:47 +00:00
});