diff --git a/src/views/components/SendContact.js b/src/views/components/SendContact.js new file mode 100644 index 0000000..e3fbf25 --- /dev/null +++ b/src/views/components/SendContact.js @@ -0,0 +1,118 @@ +export default { + name: 'SendContact', + data() { + return { + type: 'user', + phone: '', + card_name: '', + card_phone: '', + loading: false, + } + }, + computed: { + phone_id() { + return this.type === 'user' ? `${this.phone}@${window.TYPEUSER}` : `${this.phone}@${window.TYPEGROUP}` + } + }, + methods: { + openModal() { + $('#modalSendContact').modal({ + onApprove: function () { + return false; + } + }).modal('show'); + }, + async handleSubmit() { + try { + this.loading = true; + let response = await this.sendApi() + showSuccessInfo(response) + $('#modalSendContact').modal('hide'); + } catch (err) { + showErrorInfo(err) + } finally { + this.loading = false; + } + }, + async sendApi() { + this.loading = true; + try { + const payload = { + phone: this.phone_id, + contact_name: this.card_name, + contact_phone: this.card_phone + } + let response = await window.http.post(`/send/contact`, payload) + this.handleReset(); + return response.data.message; + } catch (error) { + if (error.response) { + throw new Error(error.response.data.message); + } else { + throw new Error(error.message); + } + } finally { + this.loading = false; + } + }, + handleReset() { + this.phone = ''; + this.card_name = ''; + this.card_phone = ''; + this.type = 'user'; + }, + }, + template:` +