import Vue from 'vue';
import Vuex from 'vuex';
import http from '../plugins/http';

Vue.use(Vuex);

export default new Vuex.Store({
    state: {
        chooseMenu: 0,
        menus: [],
    },
    mutations: {
        updateChooseMenu(state, chooseMenu) {
            state.chooseMenu = chooseMenu;
        },
        updateMenus(state, menus) {
            state.menus = menus;
        },
    },
    actions: {
        getMenus(context) {
            return http.axios
                .get('/category/all', {
                    params: {
                        page: 0,
                        size: 7,
                    },
                })
                .then((res) => {
                    let list = [
                        {
                            name: '重点企业',
                            img: require('../assets/svgs/tab_but_01.svg'),
                            preImg: require('../assets/svgs/tab_but_01_pre.svg'),
                            active: false,
                        },
                        {
                            name: '项目分布',
                            img: require('../assets/svgs/tab_but_02.svg'),
                            preImg: require('../assets/svgs/tab_but_02_pre.svg'),
                            active: false,
                        },
                        {
                            name: '示范区',
                            img: require('../assets/svgs/tab_but_03.svg'),
                            preImg: require('../assets/svgs/tab_but_03_pre.svg'),
                            active: false,
                        },
                        {
                            name: '基地分布',
                            img: require('../assets/svgs/tab_but_04.svg'),
                            preImg: require('../assets/svgs/tab_but_04_pre.svg'),
                            active: false,
                        },
                        {
                            name: '科技产值',
                            img: require('../assets/svgs/tab_but_05.svg'),
                            preImg: require('../assets/svgs/tab_but_05_pre.svg'),
                            active: false,
                        },
                        {
                            name: '民参军数量',
                            img: require('../assets/svgs/tab_but_06.svg'),
                            preImg: require('../assets/svgs/tab_but_06_pre.svg'),
                            active: false,
                        },
                        {
                            name: '军转民数量',
                            img: require('../assets/svgs/tab_but_07.svg'),
                            preImg: require('../assets/svgs/tab_but_07_pre.svg'),
                            active: false,
                        },
                    ];
                    list.forEach((item, index) => {
                        item.name = res.data.content[index].name;
                        item.id = res.data.content[index].id;
                    });
                    // console.log(list);
                    // context.commit('updateChooseMenu', res.data.content[0].id);
                    context.commit('updateMenus', list);
                });
        },
    },
});
