layui.use(['jquery', 'laydate','layer'], function () {
    var laydate = layui.laydate;
    var layer = layui.layer;
    $("input[class*=ydatetime]").each(function () {
        laydate.render({
            elem: this,
            format: 'yyyy/MM/dd'
        });
    });
    $("input[class*=ysdatetime]").each(function () {
        laydate.render({
            elem: this,
            type: 'datetime',
            format:'yyyy/MM/dd HH:mm:ss'
        });
    });
    $("input[data-time='ydatetime']").each(function () {
        laydate.render({
            elem: this,
            range: '~',
            calendar: false,
            format: 'yyyy/MM/dd'
        });
    });
    $("input[data-time='ysdatetime']").each(function () {
        laydate.render({
            elem: this,
            range: '~',
            calendar: false,
            type:'datetime',
            format: 'yyyy/MM/dd HH:mm:ss'
        });
    });
    $("body").on("click", "img[data-src='preview']", function () {
        preview(this);
    });
    //图片预览
    function preview(obj) {
        layer.photos({
            photos: {
                "title": "图片预览",
                "id": 1,
                "start": 0,
                "data": [
                    {
                        "alt": "",
                        "pid": 1,
                        "src": obj.src,
                        "thumb": ""
                    }
                ]
            }
        })
    }

    function previewimg(src) {
        layer.photos({
            photos: {
                "title": "图片预览",
                "id": 1,
                "start": 0,
                "data": [
                    {
                        "alt": "",
                        "pid": 1,
                        "src": src,
                        "thumb": ""
                    }
                ]
            }
        });
    }

    $("body").on("click", "video[data-src='preview']", function () {
        layer.open({
            type: 1,
            title:"视频播放",
            offset:'15px',
            content: '<video src="' + this.src +'" controls="controls">您的浏览器不支持</video>'
        });
    });

    function getImageWidth(url, callback) {
        var img = new Image();
        img.src = url;
        //如果图片被缓存，则直接返回缓存数据
        if (img.complete) {
            callback(img.width, img.height);
        } else {
            img.onload = function () {
                callback(img.width, img.height);
            }
        }
    }

})
