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