import Request from '@/common/request';
import ENV_CONFIG from '@/config/env.js';
import ApiConstant from "../ApiConstant";
let request = new Request()
export default {
    //调试vip信息
    checkVipInfo(e){
        if (e && e.skuCode) {
            e.vipFlag = true
            uni.setStorageSync('vipInfo',e)
        }else{
            uni.setStorageSync('vipInfo',{vipFlag:false})
        }
    },
    //刷新vip信息
	reloadVipInfo() {
		request.get(ApiConstant.VIP.vipInfo,{},{showLoad:false}).then(r => {
			console.log(r)
			if (r.success) {
				this.checkVipInfo(r.result)
			}
		}).catch(err => {
		}).finally(() => {
		});
	},
    async loadStaticConfig(key){
        return request.post('/api/static/data/getJson',{key:key},{showLoad:false}).then(r => {
            console.log(r)
            if (r.success) {
                return r.result
            }
        }).catch(err => {
            return {}
        }).finally(() => {
        });
    },
    async loadStaticConfigParams(key,params){
        return request.post('/api/static/data/getJson',{key:key,...params},{showLoad:false}).then(r => {
            console.log(r)
            if (r.success) {
                return r.result
            }
        }).catch(err => {
            return {}
        }).finally(() => {
        });
    },
    //格式化处理
    dateFormatYYYYMMDD(time) {
    let date = new Date(time.replace(/-/g,'/'));
    let year = date.getFullYear();
    // 在日期格式中，月份是从0开始的，因此要加0，使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
    let month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
    let day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
    let hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
    let minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
    let seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
    // 拼接
    // return year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
    return year + "-" + month + "-" + day;
    },
    getSystemName(){
        return ENV_CONFIG[process.env.NAME].name
    },
    getPlayerType(){
        return this.getSystemName()==='体育志愿宝'?'体育类':'艺术类'
    },
}
