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';
|
2019-09-02 07:25:18 +00:00
|
|
|
import './style.scss';
|
2017-01-31 13:13:06 +00:00
|
|
|
|
2020-03-17 10:17:50 +00:00
|
|
|
class Controller extends Section {
|
|
|
|
constructor($element, $) {
|
|
|
|
super($element, $);
|
2019-09-02 07:25:18 +00:00
|
|
|
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();
|
2019-02-28 07:55:34 +00:00
|
|
|
}
|
|
|
|
|
2018-02-08 08:04:29 +00:00
|
|
|
setDefault(address) {
|
2020-03-17 10:17:50 +00:00
|
|
|
let query = `Clients/${this.$params.id}`;
|
2019-02-28 07:55:34 +00:00
|
|
|
let params = {defaultAddressFk: address.id};
|
|
|
|
this.$http.patch(query, params).then(res => {
|
|
|
|
if (res.data) {
|
|
|
|
this.client.defaultAddressFk = res.data.defaultAddressFk;
|
|
|
|
this.sortAddresses();
|
2020-07-23 14:07:08 +00:00
|
|
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
2019-02-28 07:55:34 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
isDefaultAddress(address) {
|
2019-10-01 14:17:57 +00:00
|
|
|
return this.client && this.client.defaultAddressFk === address.id;
|
2019-02-28 07:55:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sort address by default address
|
|
|
|
*/
|
|
|
|
sortAddresses() {
|
|
|
|
if (!this.client || !this.addresses) return;
|
2019-06-18 07:34:32 +00:00
|
|
|
this.addresses = this.addresses.sort((a, b) => {
|
2019-02-28 07:55:34 +00:00
|
|
|
return this.isDefaultAddress(b) - this.isDefaultAddress(a);
|
|
|
|
});
|
2017-09-28 12:34:18 +00:00
|
|
|
}
|
2020-06-12 08:53:33 +00:00
|
|
|
|
|
|
|
exprBuilder(param, value) {
|
|
|
|
switch (param) {
|
|
|
|
case 'search':
|
|
|
|
return /^\d+$/.test(value)
|
|
|
|
? {id: value}
|
|
|
|
: {nickname: {like: `%${value}%`}};
|
|
|
|
}
|
|
|
|
}
|
2017-09-28 12:34:18 +00:00
|
|
|
}
|
2020-03-17 10:17:50 +00:00
|
|
|
Controller.$inject = ['$element', '$scope'];
|
2017-09-28 12:34:18 +00:00
|
|
|
|
2020-07-24 12:22:30 +00:00
|
|
|
ngModule.vnComponent('vnClientAddressIndex', {
|
2018-05-23 12:26:51 +00:00
|
|
|
template: require('./index.html'),
|
2019-02-28 07:55:34 +00:00
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
client: '<'
|
|
|
|
}
|
2017-06-03 11:01:47 +00:00
|
|
|
});
|