// 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: { openModal() { $('#modalSendPoll').modal({ onApprove: function () { return false; } }).modal('show'); }, async handleSubmit() { try { let response = await this.sendApi() window.showSuccessInfo(response) $('#modalSendPoll').modal('hide'); } catch (err) { window.showErrorInfo(err) } }, async sendApi() { this.loading = true; try { const payload = { phone: this.phone_id, question: this.question, max_answer: this.max_vote, options: this.options } const response = await window.http.post(`/send/poll`, 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.type = 'user'; this.question = ''; this.options = ['', '']; this.max_vote = 1; }, addOption() { this.options.push('') }, deleteOption(index) { this.options.splice(index, 1) } }, template: `
Send
Send Poll
Send a poll/vote with multiple options
` }