Vue.component('v-select', VueSelect.VueSelect); var antiznakTariffs = new Vue({ el: '#antiznakTariffs', data() { return { tariffs: [], tariff_id: null, is_show_tariffs: true, is_show_edit_tariff: false, edit_id: 0, error_edit: false, edit_count: null, edit_price: null, } }, methods: { //Типы оплат getTariffs() { axios.post('/ajax/vue_ajax/antiznak_axios.php', { request: 'get_tariffs', }, ) .then((response) => { console.log(response.data); var res = response.data; this.tariffs = res; }) .catch(function(error) { console.log(error); }); }, //Редактирование тарифа edit_tariff(id) { //console.log(id); let tempTariff = this.tariffs.find(x => x.id === id); if (!this.isEmpty(tempTariff)) { this.edit_count = tempTariff.count; this.edit_price = tempTariff.price; this.edit_id = id; } //console.log(tempTariff); this.is_show_edit_tariff = true; this.is_show_tariffs = false; }, //сохранение тарифа save_edit() { axios.post('/ajax/vue_ajax/antiznak_axios.php', { request: 'save_tariff', count: this.edit_count, price: this.edit_price, id: this.edit_id }, ) .then((response) => { // console.log(response.data); this.getTariffs(); this.close_edit(); }) .catch(function(error) { console.log(error); }); }, //закрыть редактирование close_edit() { this.is_show_edit_tariff = false; this.is_show_tariffs = true; this.edit_id = 0; }, //Проверка на пустоту isEmpty(data) { if (typeof(data) === 'object') { if (JSON.stringify(data) === '{}' || JSON.stringify(data) === '[]') { return true; } else if (!data) { return true; } return false; } else if (typeof(data) === 'string') { if (!data.trim()) { return true; } return false; } else if (typeof(data) === 'undefined') { return true; } else { return false; } }, }, created: function() { this.getTariffs(); } })