// store/index.js
import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);
import {
	getConfigByKey
} from '@/api/index.js'
export default new Vuex.Store({
  state: {
	  coureLogin: uni.getStorageSync('coureLogin') || 0,
	 webviewUrl: '',
	 wsDanmuUrl: 'wss://userapp.cqsft.vip', // 弹幕评论接口地址
	 //红包领取规则:
	 answerType: 1, //红包领取规则 0：完课且最后一分钟（第二次无需最后一分钟）， 1:按完课百分比答题领红包
	 isSpare:1, // 0，主要小程序，1：备选
	 isDrug:1,//0隐藏药品1显示药品
	 uploadFile: 'https://userapp.cqsft.vip',
	imgpath: 'https://zlwh.obs.cn-southwest-2.myhuaweicloud.com',//惠 康商城图片请求地址
	// https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop  惠 康商城图片链接
	logoname:'盛世生活工具A',
	// appid:'wxbb4a813dea1774d7',//泽林文化
	// appid:'wxdf14438a85585494',//泽林文化
	// appid:'wx45cf09091aead547',//测试
	// appid:'wx4c5b965e6392faf3',//韵 鹏笑笑助手
	appid:'wx17f5dc470c3c565a',//泽 林生活助手A
	
  },
  getters: {
    coureLogin: (state) => state.coureLogin,
  },
  mutations: {
    setCount(state, value) {
      state.count = value;
    },
    setUserInfo(state, info) {
      state.userInfo = info;
    },
	setWebviewUrl(state, value) {
		state.webviewUrl = value;
	},
	setCoureLogin(state, payload) {
		uni.setStorageSync('coureLogin', payload);
		state.coureLogin = payload;
	}
  },
  actions: {
    fetchUser({ commit }) {
      // const res = await uni.request({ url: '/api/user' });
      commit('setUserInfo', 'noe');
    },
	getWebviewUrl({commit}) {
		var that = this;
		var data = {
			key: 'course.config'
		}
		return new Promise((resolve, reject) => {
			getConfigByKey(data).then(res => {
				if (res.code == 200) {
					console.log("getConfigByKey====", JSON.parse(res.data))
					let data = JSON.parse(res.data)
					commit('setWebviewUrl', data.userCourseAuthDomain);
					resolve()
				}
			}).catch(error => {
				reject(error)
			});
		})
	}
  }
});