82 lines
2.1 KiB
JavaScript
82 lines
2.1 KiB
JavaScript
import ngModule from '../../module';
|
|
import './style.scss';
|
|
|
|
class Controller {
|
|
constructor($http, $scope, $stateParams) {
|
|
this.$http = $http;
|
|
this.$scope = $scope;
|
|
this.$stateParams = $stateParams;
|
|
this.filter = {
|
|
fields: [
|
|
'id',
|
|
'isDefaultAddress',
|
|
'isActive',
|
|
'nickname',
|
|
'street',
|
|
'city',
|
|
'provinceFk',
|
|
'phone',
|
|
'mobile',
|
|
'isEqualizated'
|
|
],
|
|
order: [
|
|
'isDefaultAddress DESC',
|
|
'isActive DESC',
|
|
'nickname ASC'],
|
|
include: [
|
|
{
|
|
relation: 'observations',
|
|
scope: {
|
|
include: 'observationType'
|
|
}
|
|
}, {
|
|
relation: 'province',
|
|
scope: {
|
|
fields: ['id', 'name']
|
|
}
|
|
}
|
|
]
|
|
};
|
|
}
|
|
|
|
onStarClick(event) {
|
|
event.stopPropagation();
|
|
event.preventDefault();
|
|
}
|
|
|
|
setDefault(address) {
|
|
let query = `/client/api/Clients/${this.$stateParams.id}`;
|
|
let params = {defaultAddressFk: address.id};
|
|
this.$http.patch(query, params).then(res => {
|
|
if (res.data) {
|
|
this.client.defaultAddressFk = res.data.defaultAddressFk;
|
|
this.sortAddresses();
|
|
}
|
|
});
|
|
}
|
|
|
|
isDefaultAddress(address) {
|
|
if (this.client)
|
|
return this.client.defaultAddressFk === address.id;
|
|
}
|
|
|
|
/**
|
|
* Sort address by default address
|
|
*/
|
|
sortAddresses() {
|
|
if (!this.client || !this.addresses) return;
|
|
this.addresses = this.addresses.sort((a, b) => {
|
|
return this.isDefaultAddress(b) - this.isDefaultAddress(a);
|
|
});
|
|
}
|
|
}
|
|
Controller.$inject = ['$http', '$scope', '$stateParams'];
|
|
|
|
ngModule.component('vnClientAddressIndex', {
|
|
template: require('./index.html'),
|
|
controller: Controller,
|
|
bindings: {
|
|
client: '<'
|
|
}
|
|
});
|