// 网站基本信息
companyInfo = {
    url: 'http://www.beswell.com/',
    main: 'alloutlong',
    year: new Date().getFullYear(),
};

// APP类型  0: beswell  1: 小飞龙  2: 健身馆
// appType = 0;
// appType = 1;
appType = 1;

// 默认值为beswell的设置
serverUrl = 'http://bswlt.beswell.com:9002/';           // 数据源地址
updateUrl = 'http://bcal.beswell.com:85/v1/Sensors/';   // 版本更新源地址

if (appType == 1) {    // 1: 小飞龙
    serverUrl = 'http://bswlt.beswell.com:9000/';
    updateUrl = 'http://cal.beswell.com:85/v1/Sensors/';
}
// else if (appType == 2) {    // 2: 健身馆
//     // serverUrl = 'http://bswlt.beswell.com:9000/';
//     // updateUrl = 'http://cal.beswell.com:85/v1/Sensors/';
// }


// 本机测试 TV端映射到本机进行测试
// runVersion = 'localtest';    //tmp mod

// 当前版本   演示版
// runVersion = 'test';

// 户外版本
// runVersion = 'outDoor';

// 正式版 normal
runVersion = 'normal';

// headapi = process.env.NODE_ENV === 'development' ? '/api/' : '../';
// headapi = 'http://127.0.0.1/';           //从本机获得数据源
headapi = 'http://192.168.0.22/';        //从本机获得数据源
// headapi = 'http://192.168.0.62:9000/';   //从郑伟那里获得数据源
// headapi = 'http://192.168.0.3:9000/';    //从测试服务器那里获得数据源 tmp mod

if (runVersion == 'normal')
    headapi = serverUrl;   //实际场馆默认数据源 

// 七牛云imgsrc
imgUrl = "http://qjzpcd34v.hb-bkt.clouddn.com";

timer_headclock = null;

// 常用选项
globalQuipState = function () {
    let option = [
        {
            value: '',
            label: '全部'
        }, {
            value: '0',
            label: '新入库'
        }, {
            value: '1',
            label: '未售'
        },
    ];
    return option
};

// 开始时间
globalBt = function () {
    const et = new Date();
    const bt = new Date("2019-01-01 00:00:01");
    return [bt, et];
};

globalBt2 = function (days) {
    const et = new Date();
    const bt = new Date();
    days = days ? days : 0;
    bt.setTime(bt.getTime() - 3600 * 1000 * 24 * days);
    return [bt, et];
};

// 格式化时间
globalfmtDate = function (datetime, length) {
    if ((datetime == '') || (datetime == undefined))
        return '';
    if ((datetime == '1900-01-01') || (datetime == '1900-01-01 00:00:00.000'))
        return '';
    length = !length ? 10 : length;//缺省参数
    return (datetime != null) ? datetime.substr(0, length) : '';
};

getHoursAndMin = function (datetime) {
    let date = new Date(datetime);
    h = date.getHours() < 10 ? '0' + date.getHours() + ':' : date.getHours() + ':';
    m = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
    return h + m;
};

getHoursAndMinAndSec = function (date='') {
    if (date == '') date = new Date();

    h = date.getHours() < 10 ? '0' + date.getHours() + ':' : date.getHours() + ':';
    m = date.getMinutes() < 10 ? '0' + date.getMinutes() + ':' : date.getMinutes() + ':';
    s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
    return h + m + s;
};

// 格式化时间去掉T
nonTfmtDate = function (datetime, length) {
    if ((datetime == '') || (datetime == undefined))
        return '';
    if ((datetime == '1900-01-01') || (datetime == '1900-01-01 00:00:00.000'))
        return '';
    length = !length ? 10 : length;//缺省参数
    datetime = new Date(+new Date(datetime) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '');
    return datetime
};

// 格式化时间去掉T
nonTfmtDatetoLength = function (datetime, length) {
    if ((datetime == '') || (datetime == undefined))
        return '';
    if ((datetime == '1900-01-01') || (datetime == '1900-01-01 00:00:00.000'))
        return '';
    length = !length ? 10 : length;//缺省参数
    datetime = new Date(+new Date(datetime) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '').substr(0, length);
    return datetime
};

// 获取当前日期
globalcurrent = function (date='') {
    if (date == '') date = new Date();

    let seperator1 = "-";
    let year = date.getFullYear();
    let month = date.getMonth() + 1;
    let strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    let thisdata = year + seperator1 + month + seperator1 + strDate;
    return thisdata;
};

// 获取当前时间
globalGetCurrentTime = function (date='') {
    if (date == '') date = new Date();

    let h = date.getHours();
    h = h < 10 ? '0' + h + ':' : h + ':';

    let m = date.getMinutes();
    m = m < 10 ? '0' + m + ':' : m + ':';

    let s = date.getSeconds();
    s = s < 10 ? '0' + s : s;

    let curTime = h + m + s;
    return curTime;
};

globalcurrentByCN = function (date='') {
    if (date == '') date = new Date();

    let month = date.getMonth() + 1;
    let strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    let thisdata = month + '月' + strDate + '日';
    return thisdata;
}

// 校验内容长度
globalValid = function (data, mins, maxs, text, that) {
    let thisVal = data;
    let thisLeng = thisVal.length;
    let min = parseInt(mins);
    let max = parseInt(maxs);
    let dispalyMin = min + 1;
    let title = '警告';
    if (thisVal == '') {
        that.$message({
            message: text + '不能为空！',
            type: 'warning'
        });
        return false
    } else if (thisLeng <= min) {
        that.$message({
            message: text + '最少' + dispalyMin + '字符！',
            type: 'warning'
        });
        return false
    } else if (thisLeng > max) {
        that.$message({
            message: text + '超出限制数量！',
            type: 'warning'
        });
        return false
    } else {
        return true
    }
};

// 手机号码格式
globalCheckPhone = function (val) {
    let re = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/;
    val = val.toString();
    if (val.search(re) == -1) {
        return false;
    } else {
        return true;
    }
};

getNowDate = function (date='') {
    if (date == '') date = new Date();

    let y = date.getFullYear();
    let m = date.getMonth() + 1;
    let d = date.getDate();
    let H = date.getHours();
    let mm = date.getMinutes();
    let s = date.getSeconds()
    m = m < 10 ? "0" + m : m;
    d = d < 10 ? "0" + d : d;
    // H = H < 10 ? "0" + H : H;
    return y + "年" + m + "月" + d + "日";
}

globalcurrentWeek = function (date='') {
    if (date == '') date = new Date();

    let weeks = date.getDay();
    let d = date.getDate();
    return getNowDate() + ' ' + numberToWeekdays(weeks) + ' 第' + getWeekOfYear() + '周';
}

getWeekOfYear = function (today='') {
    if (today == '') today = new Date();

    var firstDay = new Date(today.getFullYear(), 0, 1);
    var dayOfWeek = firstDay.getDay();
    var spendDay = 1;
    if (dayOfWeek != 0) {
        spendDay = 7 - dayOfWeek + 1;
    }
    firstDay = new Date(today.getFullYear(), 0, 1 + spendDay);
    var d = Math.ceil((today.valueOf() - firstDay.valueOf()) / 86400000);
    var result = Math.ceil(d / 7);
    return result + 1;
};

// table配置项目

// 每页选项
pageOptions = function () {
    let option = [
        {
            value: 10,
            label: '10'
        }, {
            value: 25,
            label: '25'
        }, {
            value: 50,
            label: '50'
        }, {
            value: 100,
            label: '100'
        }, {
            value: 2000,
            label: '2000'
        },
    ];
    return option
};

// 到期日
endTypeOptions = function () {
    let option = [
        {
            value: '',
            label: '全部'
        }, {
            value: 1,
            label: '当天'
        }, {
            value: 7,
            label: '一周'
        }, {
            value: 30,
            label: '一个月'
        }, {
            value: 90,
            label: '一季度'
        }, {
            value: 180,
            label: '半年'
        },
    ];
    return option
}
//会员类型
vipOptions = function (i) {
    let option = [];
    if (i == 0) {
        option = [
            {
                value: '',
                label: '全部'
            }, {
                value: 1,
                label: '年费会员'
            }, {
                value: 2,
                label: '充值会员'
            },
        ];
    } else {
        option = [
            {
                value: 1,
                label: '年费会员'
            }, {
                value: 2,
                label: '充值会员'
            },
        ];
    }
    return option
}

turnResToOption = function (data) {
    if (!data) return false
    let ids = data.map(item => {
        return {
            label: item.UserInfo.Name + ' ' + item.UserInfo.Phone,
            key: parseInt(item.UserInfo.Id),
            value: parseInt(item.UserInfo.Id),
        }
    })
    return ids
}

turnResToOptionByViper = function (data) {
    if (!data) return false;
    let ids = data.map(item => {
        return {
            label: item.Name + ' ' + item.Phone,
            key: parseInt(item.Id),
            value: parseInt(item.Id),
        }
    });
    return ids
};
turnResToOptionBySimViper = function (data) {
    if (!data) return false;
    let ids = data.map(item => {
        return {
            label: item.Name + ' ' + item.Usercode,
            key: parseInt(item.Id),
            value: parseInt(item.Id),
            RemainHour: parseInt(item.RemainHour),
        }
    });
    return ids
};
turnResToOptionByCoach = function (data) {
    if (!data) return false;
    let ids = data.map(item => {
        return {
            label: item.Name + ' ' + item.Phone,
            key: parseInt(item.TeacherId),
            value: parseInt(item.TeacherId),
        }
    });
    return ids
};
turnResToOptionByUsers = function (data) {
    if (!data) return false;
    let ids = data.map(item => {
        return {
            label: item.Name + ' ' + item.Phone,
            key: parseInt(item.Id),
            value: parseInt(item.Id),
        }
    });
    return ids
};

turnClassResToOption = function (data) {
    if (data == null) return false;
    if (!data) return false;
    let ids = data.map(item => {
        return {
            label: item.ClassSelf.ClassName,
            key: parseInt(item.ClassSelf.ClassId),
            value: parseInt(item.ClassSelf.ClassId),
            ClassColor: item.ClassSelf.ClassColor,
        }
    });
    return ids
};

turnShopResToOption = function (data) {
    if (!data) return false
    let ids = data.map(item => {
        return {
            label: item.ShopName,
            key: parseInt(item.ShopID),
            value: parseInt(item.ShopID)
        }
    });
    return ids
};

turnStdToOption = function (data) {
    if (!data) return false;
    let ids = data.map(item => {
        return {
            label: item.ClassName + '(' + item.BeginStr + '-' + item.EndStr + ')',
            key: parseInt(item.StdId),
            value: parseInt(item.StdId),
            classId: parseInt(item.ClassId),
        }
    });
    return ids
};

numberToWeekdays = function (val) {
    switch (parseInt(val)) {
        case 1:
            return '周一';
            break;
        case 2:
            return '周二';
            break;
        case 3:
            return '周三';
            break;
        case 4:
            return '周四';
            break;
        case 5:
            return '周五';
            break;
        case 6:
            return '周六';
            break;
        case 0:
            return '周日';
            break;
    }
};

// 随机背景
RandomBg = function () {
    let bgClassNum = parseInt(Math.random() * 4) + 1;
    return 'bgStyle' + 1 + '  pages';
};
RandomBg2 = function () {
    let bgClassNum = parseInt(Math.random() * 4) + 1;
    return 'bg2Style' + 1 + '  pages';
};

// 运动强度
sportLevel = function (val) {
    let colorClass = '';
    let per = parseInt(val);
    switch (true) {
        case per >= 90:
            colorClass = 'red';
            break;
        case per <= 89 && per > 79:
            colorClass = 'brown';
            break;
        case per <= 79 && per > 69:
            colorClass = 'yellow';
            break;
        case per <= 69 && per > 54:
            colorClass = 'green';
            break;
        case per <= 54 && per > 39:
            colorClass = 'violet';
            break;
        case per <= 39:
            colorClass = 'blue';
            break
    }
    return colorClass
};

// 假数据生成器
fakeNews = function (num, team) {
    let item = [];
    let nums = Math.random() * 100 + 1;
    let teamNum = team == 3 ? 3 : 2;
    for (var i = 0; i < num; i++) {
        item.push(
            {
                "SvId": 1,
                "UserId": 1,
                "Cle": parseInt(Math.random() * 100 + 50),
                "realHr1": parseInt(Math.random() * 100 + 50),
                "activePercent": parseInt(Math.random() * 100 + 50),
                "realHr": parseInt(Math.random() * 100 + 50),
                "heartRate": parseInt(Math.random() * 100 + 50),
                "PureCalorieNoVo2": parseInt(Math.random() * 100 + 50),
                "Name": "测试人",
                "name": "测试人",
                "updateTime": 1604568915582,
                "Ck": (nums + i + 1) * 2.2,
                "formatCk": parseInt(Math.random() * 100 + 50),
                "Head": "http://192.168.0.2/gc.png",
                "GroupNo": i % teamNum + 1,
                "Sex": i % 2 + 1,
                "IsBirthday": i % 2
            }
        )
    }
    return item;
};

// 欢迎新同学
OpenStudent = function (msg, that) {
    that.studentInfo.Rs = msg;
    that.studentInfo.dialogVisible = true;
    // 倒计时5秒自动关闭
    let studentTime = 6;
    let clock = window.setInterval(() => {
        studentTime--;
        let num = (6 - studentTime) / 6 * 100;
        this.studentInfo.percent = num > 100 ? 100 : num;
        console.log('num' + num);
        console.log('studentTime' + this.studentTime);
        if (parseInt(studentTime) < 0) {
            that.studentInfo.dialogVisible = false;
            clearInterval(clock);
        }
    }, 1000)
};

// 深拷贝
deepClone = function (obj) {
    let _obj = JSON.stringify(obj),
        objClone = JSON.parse(_obj);
    return objClone
};

