refs #5888 feat: add address-autocomplte in client and supplier fiscal-data
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Alex Moreno 2023-07-12 09:40:13 +02:00
parent bd205418a0
commit 3073955517
5 changed files with 62 additions and 115 deletions

View File

@ -4,13 +4,17 @@
data="$ctrl.locations"
order="code">
</vn-crud-model>
{{$ctrl.postCode}}
<vn-autocomplete
vn-two
vn-id="location"
label="Location"
vn-name="location"
ng-model="$ctrl.postCode"
data="$ctrl.locations">
data="$ctrl.locations"
selection="$ctrl.selection"
show-field="name"
value-field="id">
<tpl-item class="address">
<span>
{{::name}}
@ -18,10 +22,16 @@
</tpl-item>
<append>
<vn-icon-button
ui-sref="client.card.address.edit({id: $ctrl.clientId, addressId: $ctrl.addressId})"
icon="edit"
vn-tooltip="Edit address">
ui-sref="postcode.open()"
icon="add_circle"
vn-tooltip="New postcode">
</vn-icon-button>
</append>
</vn-autocomplete>
<!-- New postcode dialog -->
<vn-geo-postcode
vn-id="postcode"
on-response="$ctrl.onResponse($response)">
</vn-geo-postcode>

View File

@ -19,45 +19,56 @@ export default class AddressAutocomplete extends Component {
super(...args);
}
get addressData() {
return this._addressData;
}
set addressData(value) {
if (!value) return;
console.log(value);
this._addressData = value;
}
get locations() {
return this._locations;
}
set locations(value) {
if (!value) return;
console.log('set locations');
console.log(value);
for (let location of value) {
location.map(l => {
value = value.map(l => {
return {
name: l.code + ' ' + l.town.name + ', ' + l.town.province.name + ', ' + l.town.province.country.name,
id: l.code,
name: l.code + ' ' + l.town.name + ', ' + l.town.province.name + ', ' + l.town.province.country.country,
postalCode: l.code,
townFk: l.town.id,
townName: l.town.name,
provinceFk: l.town.province.id,
provinceName: l.town.province.name,
countryFk: l.town.province.country.id,
countryName: l.town.province.country.country,
};
});
}
console.log('location', location);
this._locations = value;
}
get postCode() {
return this._postCode;
}
set postCode(value) {
if (!value) return;
this._postCode = value;
if (!this.locations) return;
const selection = this.locations.find(location => location.id == value);
this.town = selection.townFk;
this.townName = selection.townName;
this.province = selection.provinceFk;
this.provinceName = selection.provinceName;
this.country = selection.countryFk;
this.countryName = selection.countryName;
}
}
ngModule.vnComponent('vnAddressAutocomplete', {
template: require('./index.html'),
controller: AddressAutocomplete,
bindings: {
addressData: '<?',
postCode: '<?'
postCode: '=?',
town: '=?',
province: '=?',
country: '=?',
townName: '=?',
provinceName: '=?',
countryName: '=?',
}
});

View File

@ -137,6 +137,14 @@
rule>
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-address-autocomplete
label="Address"
post-code="$ctrl.client.postcode"
town-name="$ctrl.client.city"
province="$ctrl.client.provinceFk"
country="$ctrl.client.countryFk"/>
</vn-horizontal>
<vn-horizontal>
<vn-check
label="Active"

View File

@ -193,10 +193,8 @@
<vn-horizontal>
<vn-address-autocomplete
label="Address"
address-data="$ctrl.supplier"
ng-model="$ctrl.supplier.postCode"
post-code="$ctrl.supplier.postCode"
town="$ctrl.supplier.city"
town-name="$ctrl.supplier.city"
province="$ctrl.supplier.provinceFk"
country="$ctrl.supplier.countryFk"
/>
@ -241,8 +239,4 @@
</vn-button>
</vn-button-bar>
</form>
<!-- New postcode dialog -->
<vn-geo-postcode
vn-id="postcode"
on-response="$ctrl.onResponse($response)">
</vn-geo-postcode>

View File

@ -1,85 +1,9 @@
import ngModule from '../module';
import Section from 'salix/components/section';
export default class Controller extends Section {
get province() {
return this._province;
}
// Province auto complete
set province(selection) {
const oldValue = this._province;
this._province = selection;
if (!selection || !oldValue) return;
const country = selection.country;
if (!this.supplier.countryFk)
this.supplier.countryFk = country.id;
}
get town() {
return this._town;
}
// Town auto complete
set town(selection) {
const oldValue = this._town;
this._town = selection;
if (!selection || !oldValue) return;
const province = selection.province;
const country = province.country;
const postcodes = selection.postcodes;
if (!this.supplier.provinceFk)
this.supplier.provinceFk = province.id;
if (!this.supplier.countryFk)
this.supplier.countryFk = country.id;
if (!this.supplier.postCode && postcodes.length === 1)
this.supplier.postCode = postcodes[0].code;
}
get postcode() {
return this._postcode;
}
// Postcode auto complete
set postcode(selection) {
const oldValue = this._postcode;
this._postcode = selection;
if (!selection || !oldValue) return;
const town = selection.town;
const province = town.province;
const country = province.country;
if (!this.supplier.city)
this.supplier.city = town.name;
if (!this.supplier.provinceFk)
this.supplier.provinceFk = province.id;
if (!this.supplier.countryFk)
this.supplier.countryFk = country.id;
}
onResponse(response) {
this.supplier.postCode = response.code;
this.supplier.city = response.city;
this.supplier.provinceFk = response.provinceFk;
this.supplier.countryFk = response.countryFk;
}
}
ngModule.vnComponent('vnSupplierFiscalData', {
template: require('./index.html'),
controller: Controller,
controller: Section,
bindings: {
supplier: '<'
}