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

89 lines
2.0 KiB
JavaScript
Raw Normal View History

2018-05-23 12:26:51 +00:00
import ngModule from '../../module';
2020-03-17 10:17:50 +00:00
import Section from 'salix/components/section';
2020-03-17 10:17:50 +00:00
export default class Controller extends Section {
constructor($element, $) {
super($element, $);
2020-01-28 08:03:20 +00:00
this.address = {
isActive: true,
isDefaultAddress: false
};
}
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)
2020-05-28 07:54:31 +00:00
.then(res => this.address.customsAgentId = 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;
2020-05-21 09:14:34 +00:00
if (!this.address.provinceI)
this.address.provinceId = province.id;
2020-02-24 10:27:36 +00:00
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;
2020-05-21 09:14:34 +00:00
if (!this.address.city)
this.address.city = town.name;
if (!this.address.provinceId)
this.address.provinceId = province.id;
2020-02-24 10:27:36 +00:00
}
onResponse(response) {
this.address.postalCode = response.code;
}
}
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
});