Vue.component('account_addresses', { template: `
+ Add address
{{address.title}}
Building: {{address.building}}, Road: {{address.road}}, Block: {{address.block}}, {{address.area}}
{{address.memo}}
Set as primary Primary Update Delete
`, props: ['api_url', 'site_url', 'selection_mode'], data: function () { return { is_loading: true, addresses: [], create_dialog: false, update_address: null, selected_address: null } }, methods: { loadAddresses: function () { var thisCompo = this; this.is_loading = true; axios.post(thisCompo.api_url + '/users/addresses/list', { access_token: getCookie('access_token'), }) .then(function (response) { thisCompo.addresses = response.data.data; thisCompo.is_loading = false; for(var i in thisCompo.addresses) { var thisAddr = thisCompo.addresses[i]; if(thisAddr.is_default) { thisCompo.selected_address = thisAddr; } } }) .catch(function (error) { console.log(error); }); }, deleteAddress: function (addressId) { var thisCompo = this; this.is_loading = true; axios.post(thisCompo.api_url + '/users/addresses/delete', { 'access_token': getCookie('access_token'), 'address_id': addressId, }) .then(function (response) { if (response.data.success) { thisCompo.loadAddresses(); } thisCompo.is_loading = false; }) .catch(function (error) { console.log(error); }); }, setAsDefault: function (address) { var thisCompo = this; this.is_loading = true; axios.post(thisCompo.api_url + '/users/addresses/set_as_default', { 'access_token': getCookie('access_token'), 'address_id': address.id, }) .then(function (response) { if (response.data.success) { thisCompo.loadAddresses(); } thisCompo.is_loading = false; }) .catch(function (error) { console.log(error); }); }, updateAddress: function(address) { this.update_address = address; this.create_dialog = true; }, createAddress: function() { this.update_address = null; this.create_dialog = true; } }, watch: { api_url: { handler: function (newVal, oldVal) { this.loadAddresses(); } }, selected_address: { handler: function (newVal, oldVal) { this.$emit('address_update', newVal); } } }, created: function () { this.loadAddresses(); } });