import {
	getValidateCode
} from '@/api/index/index.js'
export default {
	namespaced: true, //命名空间必须写
	state: {
		// 第一个页面参数
		testInfo: '',
		testInfo2: '',

		// 持久化常用参数
		// token: uni.getStorageSync('vuex').token, // token
	},
	getters: {
		testInfo(state) {
			return state.testInfo;
		},
		testInfo2(state) {
			return state.testInfo2;
		},
		testInfo3(state) {
			return state;
		}
	},
	//唯一修改state值的方法 
	// commit
	mutations: {
		testMut(state, data) {
			state.testInfo = data
		},
		testMut2(state, data) {
			state.testInfo2 = data
		},
		testMut3(state) {
			state.testInfo = '',
				state.testInfo2 = ''
		}
	},
	// 异步的操作
	// dispatch
	actions: {
		testAct({
			commit
		}, payload) {
			commit('testMut', payload)
		},
		// 登陆，持久化存储token，id
		testAct2(context, payload) {
			return new Promise(async (resolve, reject) => {
				// let res = await getValidateCode(data) 
				getValidateCode(payload).then(res => {
					const {
						code,
						msg,
						data
					} = res
					if (code == 0) {
						context.commit('testMut2', data)
						resolve(res)
					} else {
						reject(res)
					}
				}).catch(err => {
					reject(err)
				})
			})
		},
		testAct3({
			commit
		}) {
			console.log('jinrul-------------testAct3 ');
			commit('testMut3')
		},
	},
}