// export Vue Component export default { name: 'SendPoll', data() { return { phone: '', type: 'user', loading: false, question: '', options: ['', ''], max_vote: 1, } }, computed: { phone_id() { return this.type === 'user' ? `${this.phone}@${window.TYPEUSER}` : `${this.phone}@${window.TYPEGROUP}` } }, methods: { showModal() { $('#modalSendPoll').modal({ onApprove: function () { return false; } }).modal('show'); }, async sendProcess() { try { let response = await this.sendApi() window.showSuccessInfo(response) $('#modalSendPoll').modal('hide'); } catch (err) { window.showErrorInfo(err) } }, sendApi() { return new Promise(async (resolve, reject) => { try { this.loading = true; const payload = { phone: this.phone_id, question: this.question, max_answer: this.max_vote, options: this.options } let response = await window.http.post(`/send/poll`, payload) this.sendReset(); resolve(response.data.message) } catch (error) { if (error.response) { reject(error.response.data.message) } else { reject(error.message) } } finally { this.loading = false; } }) }, sendReset() { this.phone = ''; this.type = 'user'; this.question = ''; this.options = ['', '']; this.max_vote = 1; }, addOption() { this.options.push('') }, deleteOption(index) { this.options.splice(index, 1) } }, template: `