HomeAccounting

Форк
0
123 строки · 3.4 Кб
1

2
import template from './template.html';
3

4
export default {
5
    name: "category-control",
6
    template: template,
7
    props: {
8
        showCategoryComponent: {
9
            type: Boolean,
10
            default: true,
11
        },
12
    },
13

14
    data: () => ({
15
        search: '',
16
        loadingDataTable: false,
17
        pagination: {'sortBy': 'name', 'ascending': true, 'rowsPerPage': -1},
18
        headers: [
19
            {
20
                text: 'ID',
21
                align: 'left',
22
                sortable: false,
23
                value: 'id'
24
            },
25
            { text: 'Название', value: 'name', align: 'right' },
26
            { text: 'Управление', value: '', align: 'right' },
27

28
        ],
29

30
        max50chars: (v) => v.length <= 50 || 'Слишком длинное наименование!',
31

32
        dataTables: [],
33

34
        createForm: false,
35

36
        categoryFormType: 'create',
37

38
        categoryFormData: {
39
            category_id: 0,
40
            name: '',
41
        },
42

43
    }),
44
    methods: {
45
        getCategories() {
46
            this.$store.commit('setPreloader', true);
47
            axios.get('/pa/categories-list')
48
                .then(response=> {
49
                    this.dataTables = response.data;
50
                    this.$store.commit('setPreloader', false);
51
                })
52
                .catch(error => {
53
                    this.$store.commit('AlertError', error.message);
54
                });
55
        },
56
        editForm(object) {
57
            this.categoryFormData.category_id = object.id;
58
            this.categoryFormData.name = object.name;
59
            this.categoryFormType="update";
60
        },
61
        newForm() {
62
            this.createForm = true;
63
            this.categoryFormType = 'create';
64
            this.categoryFormData.category_id = 0;
65
            this.categoryFormData.name = '';
66
        },
67
        deleteCategory(object) {
68

69
            let confirm = window.confirm('Вы действительно хотите удалить элемент?');
70

71
            if(confirm === true) {
72
                this.categoryFormType="delete";
73
                this.categoryFormData.category_id = object.id;
74
                this.categorySave();
75
            }
76

77
        },
78
        categorySave() {
79
            let url = '/pa/categories';
80
            let method = '';
81

82
            if(this.categoryFormType === 'create') {
83
                method = 'post';
84
            }
85
            else if(this.categoryFormType === 'update') {
86
                method = 'put';
87
            }
88
            else if(this.categoryFormType=== 'delete') {
89
                method = 'delete';
90
            }
91

92
            this.$store.commit('setPreloader', true);
93

94
            axios({
95
                method: method,
96
                url: url,
97
                data: this.categoryFormData,
98
            })
99
                .then(response=> {
100
                    if(response.data.status == 200) {
101
                        this.createForm = false;
102
                        this.getCategories();
103
                        this.$store.commit('setPreloader', false);
104
                    }
105
                    else {
106
                        this.$store.commit('AlertError', 'Ошибка получения данных с сервера');
107
                    }
108

109
                })
110
                .catch(error => {
111
                    this.$store.commit('AlertError', error.message);
112
                });
113
        },
114
    },
115
    computed: {
116

117
    },
118
    watch: {
119

120
    },
121
    mounted() {
122
        this.getCategories();
123
    },
124
}

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.