import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'

Vue.use(Vuex)
const store = new Vuex.Store({
    state: {
        /** 人脸检测验证状态 ["0": 未完成人脸认证; "1": 已完成人脸认证] */
        verification: "0",
        userInfo: {
            CORPINFO_ID: '',
            DEPARTMENT_ID: '',
            NAME: "",
            ROLEID: "",
            ROLE_NAME: "",
            USERBZ: "",
            USERNAME: "",
            USER_ID: "",
			PHOTO: "",
            token: ""
        },
		// 这里是存储学员信息的数据，直接存储到 localStore 中的
		studentInfo: {
            name: "" ,// 学员姓名，
            phone: "", // 联系电话
            userIdCard: "", // 身份证号
            sex: "", // 学员性别
            degreeOfEducation: "", // 学历
		}
    },
    getters: {
        getUserInfo: state => state.userInfo,
		getStudentInfo: state => state.studentInfo,
        getVerification: state => state.verification,
    },
    mutations: {
        setUserInfo(state, userInfo) {
            state.userInfo = userInfo
        },
		setStudentInfo(state, studentInfo) {
            state.studentInfo = studentInfo
        },
        setVerification(state, verification) {
            state.verification = verification
        },
    },
    actions: {
        setUserInfo({commit}, userInfo) {
            commit('setUserInfo', userInfo)
        },
		setStudentInfo({commit}, studentInfo) {
            commit('setStudentInfo', studentInfo)
		},
        setVerification({commit}, verification) {
            commit('setVerification', verification)
        },
    },
    plugins: [
        createPersistedState({
            storage: {
                getItem: (key) => uni.getStorageSync(key), // 获取
                setItem: (key, value) => uni.setStorageSync(key, value), // 存储
                removeItem: (key) => uni.removeStorageSync(key) // 删除
            }
        })
    ]
})
export default store
