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

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

// 左侧隐藏
left_panel_state = function (state) {
    return state
};
// 常用选项
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 () {
    const et = new Date();
    const bt = new Date();
    bt.setTime(bt.getTime() - 3600 * 1000 * 24 * 7);
    return [bt, et];
};

globalBt3 = function (days) {
    const et = new Date(new Date(new Date().toLocaleDateString()).getTime()+24*60*60*1000-1);
    const bt = new Date();
    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) : '';
};

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

// 获取当前时间
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|7|8|9][0-9]\d{8}$/;
    if (val.search(re) == -1) {
        return false;
    } else {
        return true;
    }
};

//格式化日期  年月日
globaltime2String = function (time) {
    let datetime = new Date();
    datetime.setTime(time);
    let year = datetime.getFullYear();
    let month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
    let date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
    return year + "-" + month + "-" + date;
};

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
};


// 校验MAC地址
checkMac = function (val) {
    var regex = "(([A-Fa-f0-9]{2}-){5}[A-Fa-f0-9]{2})|(([A-Fa-f0-9]{2}:){5}[A-Fa-f0-9]{2})"; // 含冒号
    var regexp = new RegExp(regex);
    if (!regexp.test(val)) {
        return false;
    }
    return true;
};

// 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
};

// 协议选项
WirelessType = function () {
    let option = [
        {
            value: 1,
            label: '移动GSM'
        }, {
            value: 2,
            label: '联通GSM'
        }, {
            value: 3,
            label: '电信CDMA'
        }, {
            value: 4,
            label: '移动3G'
        }, {
            value: 5,
            label: '联通3G'
        }, {
            value: 6,
            label: '移动4G'
        }, {
            value: 7,
            label: '联通4G'
        }, {
            value: 8,
            label: '电信4G'
        }, {
            value: 9,
            label: '433M/315M'
        }, {
            value: 10,
            label: 'WIFI2.4G'
        }, {
            value: 11,
            label: 'ISM2.4G'
        }, {
            value: 12,
            label: '800M'
        }, {
            value: 13,
            label: '0-6G扫描'
        },
    ];
    return option
};

filterWirelessType = function (value) {
    switch (parseInt(value)) {
        case 0:
            return "未知";
            break;
        case 1:
            return "移动GSM";
            break;
        case 2:
            return "联通GSM";
            break;
        case 3:
            return "电信CDMA";
            break;
        case 4:
            return "移动3G";
            break;
        case 5:
            return "联通3G";
            break;
        case 6:
            return "移动4G";
            break;
        case 7:
            return "联通4G";
            break;
        case 8:
            return "电信4G";
            break;
        case 9:
            return "433M/315M";
            break;
        case 10:
            return "WIFI2.4G";
            break;
        case 11:
            return "ISM2.4G";
            break;
        case 12:
            return "800M";
            break;
        case 13:
            return "0-6G";
            break;
    }
};

filterAllType = function (value) {
    switch (parseInt(value)) {
        case 0:
            return "未知";
            break;
        case 1:
            return "移动GSM";
            break;
        case 2:
            return "联通GSM";
            break;
        case 3:
            return "电信CDMA";
            break;
        case 4:
            return "移动3G";
            break;
        case 5:
            return "联通3G";
            break;
        case 6:
            return "移动4G";
            break;
        case 7:
            return "联通4G";
            break;
        case 8:
            return "电信4G";
            break;
        case 9:
            return "433M/315M";
            break;
        case 10:
            return "WIFI2.4G";
            break;
        case 11:
            return "ISM2.4G";
            break;
        case 12:
            return "800M";
            break;
        case 13:
            return "0-6G";
            break;
        case 20:
            return "其他";
            break
        case 21:
            return "摄像头";
            break
        case 22:
            return "热点";
            break
        case 23:
            return "手机";
            break
        case 24:
            return "其他";
            break

    }
};

// 设备类型
AllTypeOption = function () {
    let option = [
        {
            value: '',
            label: '全部'
        }, {
            value: 0,
            label: '未知'
        }, {
            value: 1,
            label: '移动GSM'
        }, {
            value: 2,
            label: '联通GSM'
        }, {
            value: 3,
            label: '电信CDMA'
        }, {
            value: 4,
            label: '移动3G'
        }, {
            value: 5,
            label: '联通3G'
        }, {
            value: 6,
            label: '移动4G'
        }, {
            value: 7,
            label: '联通4G'
        }, {
            value: 8,
            label: '电信4G'
        }, {
            value: 9,
            label: '433M/315M'
        }, {
            value: 10,
            label: 'WIFI2.4G'
        }, {
            value: 11,
            label: 'ISM2.4G'
        }, {
            value: 12,
            label: '800M'
        }, {
            value: 13,
            label: '0-6G扫描'
        }, {
            value: 20,
            label: '其他'
        }, {
            value: 21,
            label: '摄像头'
        }, {
            value: 22,
            label: '热点'
        }, {
            value: 23,
            label: '手机'
        }, {
            value: 24,
            label: '其他'
        },
    ];
    return option
};

// 安全等级
levelOptions = function () {
    let option = [
        {
            value: 0,
            label: '全部'
        }, {
            value: 1,
            label: '可信设备'
        }, {
            value: 2,
            label: '安全'
        }, {
            value: 3,
            label: '可疑'
        }, {
            value: 4,
            label: '危险'
        },
    ];
    return option
};


WirelessRange = function () {
    let option = [
        {
            value: 1,
            label: '20cm'
        }, {
            value: 2,
            label: '50cm'
        }, {
            value: 3,
            label: '1M'
        }, {
            value: 4,
            label: '3M'
        }, {
            value: 5,
            label: '5M'
        },
    ];
    return option
};


filterWirelessRangeText = function (value) {
    switch (parseInt(value)) {
        case 1:
            return "20cm";
            break;
        case 2:
            return "50cm";
            break;
        case 3:
            return "1M";
            break;
        case 4:
            return "3M";
            break;
        case 5:
            return "5M";
            break;
    }
};

filterDetctorType = function (value) {
    switch (parseInt(value)) {
        case 0:
            return "未知设备";
            break;
        case 1:
            return "摄像头";
            break;
        case 2:
            return "wifi热点";
            break;
        case 3:
            return "手机";
            break;
        case 4:
            return "其他设备";
            break;
    }
};
// 时间戳
filterTimeToString = function (value,len) {
    let date = new Date(value);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
    let year = date.getFullYear(),
        month = ("0" + (date.getMonth() + 1)).slice(-2),
        sdate = ("0" + date.getDate()).slice(-2),
        hour = ("0" + date.getHours()).slice(-2),
        minute = ("0" + date.getMinutes()).slice(-2),
        second = ("0" + date.getSeconds()).slice(-2);
    // 拼接
    let result;
    if(len == 11){
        result = year + "-" + month + "-" + sdate;
    }else{
        result = year + "-" + month + "-" + sdate + " " + hour + ":" + minute + ":" + second;
    }
    // 返回
    return result;
};

// 时间显示
filterTimeToShortString = function (value) {
    let date = new Date(value - 8 * 60 * 60 * 1000);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
    let year = date.getFullYear(),
        month = ("0" + (date.getMonth() + 1)).slice(-2),
        sdate = ("0" + (date.getDate() - 1)).slice(-2),
        hour = ("0" + date.getHours()).slice(-2),
        minute = ("0" + date.getMinutes()).slice(-2),
        second = ("0" + date.getSeconds()).slice(-2);
    // 拼接
    let result = '';
    if (date.getDate() > 1) {
        result = sdate + '天 ' + hour + ":" + minute + ":" + second;
    } else {
        result = hour + ":" + minute + ":" + second;
    }

    // 返回
    return result;
};

// handle = function(row, column, event) {
//     // list -- 已选的数据
//     let index = this.list.findIndex(item => {
//         // 判断已选数组中是否已存在该条数据
//         return item.id == row.id
//     })
//     if (index == -1) {
//         // 如果未存在，设置已选状态，并在list中添加这条数据
//         this.$refs.multipleTable.toggleRowSelection(row, true); //设置复选框为选中状态
//         this.list.push(row)
//     } else {
//         // 如果已存在，设置未选状态，并在list中删除这条数据
//         this.$refs.multipleTable.toggleRowSelection(row, false); //设置复选框为未选状态
//         this.list.splice(index, 1)
//     }
//
// }
