import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		picTitle:"",
		hasLogin: false,
		userInfo: {},
		myConfList:[],
		leavelist:[],
		vest:{},
		bagNote:"",
		alreadysublist:[],
		allwords:[],
		seleImage:[],
		// config:[
		// 	{
		// 		confAlias: "DNS_URl",
		// 		confNote: "oss图片访问前缀",
		// 		confNum: "https://cdn.pailiying.com/",
		// 	},
		// 	{
		// 	confAlias: "ANIMATION_IMG_ONE",
		// 	confNote: "动画图1",
		// 	confNum: "https://cdn.pailiying.com/confResource/animation_img_one_202105251328.gif",
		// },
		// {
		// 	confAlias: "ANIMATION_IMG_TWO",
		// 	confNote: "动画图2",
		// 	confNum: "https://cdn.pailiying.com/confResource/animation_img_two_202105261605.gif"
		// },
		// {
		// 	confAlias: "BUBBLE_IMG_LIST",
		// 	confNote: "点赞气泡配置图集合",
		// 	confNum: "https://cdn.pailiying.com/confResource/2021_05_27_16_34_1拍.png,https://cdn.pailiying.com/confResource/2021_05_27_16_34_2立.png,https://cdn.pailiying.com/confResource/2021_05_27_16_34_3映.png,https://cdn.pailiying.com/confResource/2021_05_27_16_34_4照.png,https://cdn.pailiying.com/confResource/2021_05_27_16_34_5片.png,https://cdn.pailiying.com/confResource/2021_05_27_16_34_6直.png,https://cdn.pailiying.com/confResource/2021_05_27_16_34_7播.png"
		// }]
		config:[]
	},
	mutations: {
		setconfig(state, provider){
			state.picTitle = provider.find((i)=>{return i.confAlias=='DNS_URl'}).confNum
			uni.setStorageSync('h5_address', provider.find((i)=>{return i.confAlias=='H5_URL'}).confNum)
			state.config = provider
		},
		clearImage(state, provider){
			state.seleImage = []
		},
		changseleImage(state, provider){
			if(provider.key=="add"){
				state.seleImage.push(provider.item)
			}else{
				state.seleImage.splice(provider.item,1)
			}
			
		},
		setallwords(state, provider){
			state.allwords = provider;
		},
		deletesublist(state, provider){
			let idx = state.alreadysublist.findIndex((i)=>{return i.id == provider.id})
			state.alreadysublist.splice(idx,1)
		},
		setsublist(state, provider){
			if(provider){
				let idx = state.alreadysublist.findIndex((i)=>{return i.id == provider.id})
				if(idx!=-1){
					state.alreadysublist[idx] = provider
				}else{
					state.alreadysublist.push(provider);
				}
				
			}else{
				state.alreadysublist = []
			}
		   
		},
		deleteSublist(state, index){
			state.alreadysublist.splice(index, 1);
		},
		setbagNote(state, provider){
			state.bagNote = provider;
		},
		setleavelist(state, provider){
			state.leavelist = provider;
		},
		setmyConfList(state, provider){
			state.myConfList = provider;
		},
		login(state, provider) {
			
			if(provider=="" || !provider){
				state.hasLogin = false;
				return;
			}

			state.hasLogin = true;
			state.userInfo = provider;
			uni.setStorage({//缓存用户登陆状态
			    key: 'userInfo',  
			    data: provider  
			}) 
			//uni.setStorageSync('userInfo', provider);
		},
		acylogin(state, provider){
			if(provider=="" || !provider){
				state.hasLogin = false;
				return;
			}
			
			state.hasLogin = true;
			state.userInfo = provider;
			// uni.setStorage({//缓存用户登录状态
			//     key: 'userInfo',  
			//     data: provider  
			// }) 
			uni.setStorageSync('userInfo', provider);
		},
		logout(state) {
			state.hasLogin = false;
			state.userInfo = {};
			uni.removeStorageSync("userInfo")
			// uni.removeStorage({  
   //              key: 'userInfo'  
   //          })
		},
		setVest(state, provider){
			state.vest = provider;
		},
	},
	actions: {
	
	}
})

export default store
