export default { name: 'SendLocation', data() { return { type: 'user', phone: '', latitude: '', longitude: '', loading: false, } }, computed: { phone_id() { return this.type === 'user' ? `${this.phone}@${window.TYPEUSER}` : `${this.phone}@${window.TYPEGROUP}` } }, methods: { openModal() { $('#modalSendLocation').modal({ onApprove: function () { return false; } }).modal('show'); }, async handleSubmit() { try { let response = await this.submitApi() showSuccessInfo(response) $('#modalSendLocation').modal('hide'); } catch (err) { showErrorInfo(err) } }, async submitApi() { this.loading = true; try { const payload = { phone: this.phone_id, latitude: this.latitude, longitude: this.longitude }; const response = await window.http.post(`/send/location`, payload); this.handleReset(); return response.data.message; } catch (error) { if (error.response) { throw new Error(error.response.data.message); } throw new Error(error.message); } finally { this.loading = false; } }, handleReset() { this.phone = ''; this.latitude = ''; this.longitude = ''; this.type = 'user'; }, }, template: `