/**
 * @author lishuwen
 * @time 2016-5-18:22:16
 * @describe 一些常用的工具类
 */

/**
 * 弹出一个提示信息
 * @param content
 */
function showMessage(content) {
    layer.alert(content, {
        skin: 'layui-layer-molv', // 样式类名
        closeBtn: 0,
        shade: 0.5,
    });
}

/**
 * 关闭弹出框
 */
function closeView(time = 0) {
    let index = parent.layer.getFrameIndex(window.name); // 先得到当前iframe层的索引
    if (time == 0) {
        setTimeout(() => {
            parent.layer.close(index); // 再执行关闭
        }, 700)
    } else {
        parent.layer.close(index); // 再执行关闭
    }
}

/**
 * 显示loading动画
 */
function showLoding() {
    layer.msg('请稍等!', {icon: 16, shade: 0.3, time: false});
}

/**
 * 隐藏loading动画
 */
function cancelLoding() {
    let index = layer.msg('请稍等!', {icon: 16, shade: 0.2});//换了种风格
    setTimeout(()=>{
        layer.close(index);
    },300)
}
/**
 * 弹出一个成功吐司
 * @param title
 */
function showToast(title) {
    layer.msg(title, {time: 1500, shade: 0.3, icon: 1});
}

/**
 * 弹出一个错误吐司
 * @param title
 */
function showToastError(title) {
    layer.msg(title, {
        time: 1500,
        icon: 2,
        shade: 0.3
    });
}
function sendAjax(url, param, callback) {
    showLoding();
    $.ajax({
        type: "post",
        url: url,
        data: param,
        dataType: "json",
        success: callback,
        error: function () {
            showMessage("服务异常")
            cancelLoding();
        }
    });
}
var chart_option = function() {
    return {
        toolbox: {
            show: true,
            iconStyle: {
                borderColor: "rgba(255,255,255,.8)",
            },
            feature: {
                magicType: {
                    type: ['line', 'bar']
                },
            }
        },
        yAxis: {
            nameTextStyle: {
                color: "rgba(255,255,255,.6)",
            },
            splitLine: {
                show: false
            },
            axisLine: { //坐标轴线
                show: true,
                lineStyle: {
                    color: "rgba(255,255,255,.6)",
                    width: 2,
                    type: "solid"
                },
            },
            splitNumber: 3,
            axisLabel: {
                //formatter: '{value} %',
                show: true,
                textStyle: {
                    color: "rgba(255,255,255,.6)",
                    fontSize: '13',
                },
            }
        },
        lineStyle: {
            normal: {
                color: '#23abca',
                width: 2
            }
        },
        symbolSize: 5,
        areaStyle: {
            normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                    offset: 0,
                    color: '#23abcabd'
                }, {
                    offset: 0.8,
                    color: 'rgba(0, 216, 135, 0.1)'
                }], false),
                shadowColor: 'rgba(0, 0, 0, 0.1)',
            }
        },
        itemStyle: {
            normal: {
                color: 'white',
                borderColor: 'rgba(221, 220, 107, .1)',
                borderWidth: 12,
                lineStyle: {
                    width: 5
                }
            }
        }
    }
}
let t = null;
function time() {
    clearTimeout(t);
    dt = new Date();
    var y = dt.getFullYear();
    var mt = dt.getMonth() + 1;
    var day = dt.getDate();
    var h = dt.getHours();
    var m = dt.getMinutes();
    var s = dt.getSeconds();
    document.getElementById("showTime").innerHTML = y + "年" + mt + "月" + day + "-" + h + "时" + m + "分" + s + "秒";
    t = setTimeout(time, 1000);
}
function start_time (){
    t = setTimeout(time, 1000);
}