export default { name: 'SendFile', props: { maxFileSize: { type: String, required: true, } }, data() { return { caption: '', type: 'user', phone: '', loading: false, } }, computed: { phone_id() { return this.type === 'user' ? `${this.phone}@${window.TYPEUSER}` : `${this.phone}@${window.TYPEGROUP}` } }, methods: { openModal() { $('#modalSendFile').modal({ onApprove: function () { return false; } }).modal('show'); }, async handleSubmit() { try { let response = await this.sendApi() showSuccessInfo(response) $('#modalSendFile').modal('hide'); } catch (err) { showErrorInfo(err) } }, async sendApi() { this.loading = true; try { let payload = new FormData(); payload.append("caption", this.caption) payload.append("phone", this.phone_id) payload.append("file", $("#file_file")[0].files[0]) let response = await http.post(`/send/file`, 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.caption = ''; this.phone = ''; this.type = 'user'; $("#file_file").val(''); }, }, template: `