import {
  setStore,
  getStore,
  removeStore
} from '@/util/store'
import website from '@/config/website'
import {routesCompany} from '@/api/help/common'
const common = {

  state: {
    language: getStore({name: 'language'}) || 'zh',
    isCollapse: false,
    isFullScren: false,
    isMenu: true,
    isShade: false,
    screen: -1,
    isLock: getStore({name: 'isLock'}) || false,
    helpShow: getStore({name: 'jlHelpShow'}) || false,
    helpTag: getStore({name: 'jlHelpTag'}) || false,
    helpSwitch: getStore({name: 'jlHelpSwitch'}) || 1,
    showTag: true,
    showDebug: true,
    showCollapse: true,
    showSearch: true,
    showLock: true,
    showFullScren: true,
    showTheme: true,
    showMenu: true,
    showColor: true,
    colorName: getStore({name: 'colorName'}) || '#409EFF',
    themeName: getStore({name: 'themeName'}) || 'theme-default',
    lockPasswd: getStore({name: 'lockPasswd'}) || '',
    website: website,
    helpList: ['SDSFSDFSDFDSF']
  },
  actions: {
    // row： 点击路由获取路由参数，根据此参数调用接口请求侧边栏数据
    jlHelpList({state, commit}, row){
      // 每次进入接口请求侧边栏数据
      var helpTag = state.showTag
      if (helpTag) {
        var obj = JSON.parse(getStore({name: 'queryHelp'}))
        var pcSource = process.env.VUE_APP_SITE === 'default' ? 3 : 4;
        routesCompany(obj.id, pcSource).then(res => {
          commit('SET_HELPLIST', res.data.data);
        })
      }
    },
    jlHelpTag({commit, dispatch}, helpTag){
      commit('SET_HELPTAG', helpTag);
      if (helpTag) {
        dispatch('jlHelpList');
      }
    },
    jlHelpShow({commit}, helpShow){
      commit('SET_HELPSHOW', helpShow);
      commit('SET_HELPTAG', helpShow);
    },
    jlHelpSwitch({commit}, helpSwitch){
      commit('SET_HELPSWITCH', helpSwitch);
    }
  },
  mutations: {
    SET_HELPSWITCH: (state, helpSwitch) => {
      state.helpSwitch = helpSwitch
      setStore({
        name: 'jlHelpSwitch',
        content: state.helpSwitch
      })
    },
    SET_HELPLIST: (state, helpList) => {
      state.helpList = helpList
    },
    SET_HELPSHOW: (state, helpShow) => {
      state.helpShow = helpShow
      setStore({
        name: 'jlHelpShow',
        content: state.helpShow
      })
    },
    SET_HELPTAG: (state, helpTag) => {
      state.helpTag = helpTag
      setStore({
        name: 'jlHelpTag',
        content: state.helpTag
      })
    },
    SET_LANGUAGE: (state, language) => {
      state.language = language
      setStore({
        name: 'language',
        content: state.language
      })
    },
    SET_SHADE: (state, active) => {
      state.isShade = active;
    },
    SET_COLLAPSE: (state) => {
      state.isCollapse = !state.isCollapse;
    },
    SET_FULLSCREN: (state) => {
      state.isFullScren = !state.isFullScren;
    },
    SET_IS_MENU: (state, menu) => {
      state.isMenu = menu;
    },
    SET_LOCK: (state) => {
      state.isLock = true;
      setStore({
        name: 'isLock',
        content: state.isLock,
        type: 'session'
      })
    },
    SET_SCREEN: (state, screen) => {
      state.screen = screen;
    },
    SET_COLOR_NAME: (state, colorName) => {
      state.colorName = colorName;
      setStore({
        name: 'colorName',
        content: state.colorName,
      })
    },
    SET_THEME_NAME: (state, themeName) => {
      state.themeName = themeName;
      setStore({
        name: 'themeName',
        content: state.themeName,
      })
    },
    SET_LOCK_PASSWD: (state, lockPasswd) => {
      state.lockPasswd = lockPasswd;
      setStore({
        name: 'lockPasswd',
        content: state.lockPasswd,
        type: 'session'
      })
    },
    CLEAR_LOCK: (state) => {
      state.isLock = false;
      state.lockPasswd = '';
      removeStore({
        name: 'lockPasswd',
        type: 'session'
      });
      removeStore({
        name: 'isLock',
        type: 'session'
      });
    },
  }
}
export default common
