import router from '../../router/index'

const state = {
    baseUrl: '',
    isReady: false,
    aId: '',
    cId: '',
    gId: '',
    riskPointType: '',  // 风险点类型
}

const mutations = {
    SET_BASEURL: (state, url) => {
        // if (process.env.NODE_ENV == 'development') {
        //     state.baseUrl = ''
        // } else {
        state.baseUrl = 'http://' + url
        // }
    },
    SET_ISREADY: (state) => {
        if (!state.isReady) {
            state.isReady = true
            // location.reload(true)
            router.go(0)
        }
    },
    SET_AID: (state, aId) => {
        state.aId = aId
    },
    SET_CID: (state, cId) => {
        state.cId = cId
    },
    SET_GID: (state, gId) => {
        state.gId = gId
    },
    SET_riskPointType: (state, riskPointType) => {
        state.riskPointType = riskPointType
    },
}

const actions = {
    /**
     * @Author: NanKeYang
     * @Description: 设置请求参数
     * @Data: 2020/1/9 10:14
     */
    setReqConfig({commit}, reqConfig) {
        const {aId, cId, gId, riskPointType} = reqConfig
        if (aId) {
            commit('SET_AID', aId)
        }
        if (cId) {
            commit('SET_CID', cId)
        }

        if (gId) {
            commit('SET_GID', gId)
        }

        if (riskPointType) {
            commit('SET_riskPointType', riskPointType)
        }
    },
    // 设置请求参数
    setBaseUrl({commit}, url) {
        commit('SET_BASEURL', url)
        commit('SET_ISREADY')
    },
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}
