// 网站基本信息
companyInfo = {
    url: 'http://det.shandongewall.com/',
    main: 'E-WALL',
    year: new Date().getFullYear(),
};

headapi = process.env.NODE_ENV === 'development' ? '/api/' : '../';


// 常用选项
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;
}

// 格式化时间去掉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 () {
    let 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;
};

// 校验内容长度
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 () {
    let 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 + "日";
}

// 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),
        }
    })
    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
}

turnClassResToOption = function (data) {
    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;
    }
}