import Vue from 'vue'
import Vuex from 'vuex'
// @ts-ignore
import { queryfmapID, queryFloor } from '@/api/login.js'
// @ts-ignore
import { queryBrand } from '@/api/public.js'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        ssoToken: 'admin:liujiandong',
        appTitle: '管理说明书', //顶部标题
        // ssoToken: null,
        // plazaId: '1000772', //项目Id 北京通州
        plazaId: '1000423', //项目Id 大连高新
        fmapID: '',
        haveFengMap: -1, //是否有蜂鸟地图的数据 -1为等待 0 为失败 1 为成功
        isMessage: true, //是否有发布的图
        bunkObj: {}, // 铺位名称
        floorsArr: [], //楼层数组
        categoryId: "", //系统类型
        smsxt: "", //设备设施系统编码
        // 事件类型字典
        objtypeDict: {
            1: '重要维保',
            3: '综合事项',
            4: '重要维修',
            5: '其他事项',
        },
    },
    getters: {
        ssoToken: (state) => state.ssoToken,
        appTitle: (state) => state.appTitle,
        plazaId: (state) => state.plazaId,
        fmapID: (state) => state.fmapID,
        haveFengMap: (state) => state.haveFengMap,
        isMessage: (state) => state.isMessage,
        bunkObj: (state) => state.bunkObj,
        objtypeDict: (state) => state.objtypeDict,
        floorsArr: (state) => state.floorsArr,
        categoryId: (state) => state.categoryId,
        smsxt: (state) => state.smsxt,
    },
    mutations: {
        SETSSOTOKEN(state, data) {
            state.ssoToken = data
        },
        SETAPPTITLE(state, data) {
            state.appTitle = data
        },
        SETPLAZAID(state, data) {
            state.plazaId = data
        },
        SETMAPID(state, data) {
            state.fmapID = data
        },
        SETHAVEFENGMAP(state, data) {
            state.haveFengMap = data
        },
        SETISMESSAGE(state, data) {
            state.isMessage = data
        },
        SETBUNKOBJ(state, data) {
            state.bunkObj = data
        },
        // 设置楼层列表
        SETFLOORS(state, data) {
            state.floorsArr = data
        },
        // 设置系统类型
        SETCATEGORYID(state, data) {
            state.categoryId = data
        },
        // 设置设备设施系统编码
        SETSMSXT(state, data) {
            state.smsxt = data
        },
    },
    actions: {
        async getfmapID(context) {
            await queryfmapID({
                mapId: context.state.plazaId,
            }).then((res) => {
                context.commit('SETMAPID', `${context.state.plazaId}_${res.mapVersion}`)
            })
        },
        async getBrand(context) {
            let data = {
                plazaId: `${context.state.plazaId}`,
            }
            await queryBrand({
                data,
            }).then((res) => {
                let obj = {}
                if (res.data.data) {
                    let Data = res.data.data
                    Data.forEach((i) => {
                        obj[i.bunkdesc] = i
                    })
                }
                context.commit('SETBUNKOBJ', obj)
            })
        },
        /**
         * 获取楼层列表
         * @param context
         */
        async getFloors(context) {
            await queryFloor({
                plazaId: context.state.plazaId,
            }).then((res: any) => {
                if (res.result == 'success') {
                    context.commit('SETFLOORS', res.data)
                }
            })
        },
    },
    modules: {},
})
