layui.use(["layer", "form", "laydate", "upload"], function(){
    $ = layui.$;
    form = layui.form;
    layer = layui.layer;
    laydate = layui.laydate;
    upload = layui.upload;
    //视频
    upload.render({
        elem: '.file_videos' //绑定元素
        ,url: '/upload/uploadFile' //上传接口
        ,method: 'post'  //可选项。HTTP类型，默认post
        ,accept: 'video'
        ,acceptMime: 'video/*'
        ,headers: {token: token}
        ,done: function(res){
            $(this.item[0]).parent().next().append("<video src="+ res.data +" controls=\"\" data-v-400c2eb9=\"\"></video>");
        }
        ,error: function(){
            //请求异常回调
        }
    });

    //图片上传
    upload.render({
        elem: '.file_img' //绑定元素
        ,url: '/upload/uploadFile' //上传接口
        ,method: 'post'  //可选项。HTTP类型，默认post
        ,accept: 'images'
        ,acceptMime: 'image/*'
        ,headers: {token: token}
        ,done: function(res){
            $(this.item[0]).parent().next().append("<div class=\"editor-assets-content-info\" data-v-400c2eb9=\"\">\n" +
                "                                    <div class=\"el-image\" data-v-400c2eb9=\"\"><img style='width: 100px;height: 100px;' alt=\"upload-assets\"\n" +
                "                                                                                  src="+ res.data +"\n" +
                "                                                                                  class=\"el-image__inner el-image__preview\"\n" +
                "                                                                                  style=\"object-fit: cover;\"><!--v-if-->\n" +
                "                                    </div>\n" +
                "                                    <svg viewBox=\"0 0 1024 1024\" xmlns=\"http://www.w3.org/2000/svg\" onclick=\"closeSvg(this)\" data-v-400c2eb9=\"\">\n" +
                "                                        <path fill=\"currentColor\"\n" +
                "                                              d=\"M512 64a448 448 0 1 1 0 896 448 448 0 0 1 0-896zm0 393.664L407.936 353.6a38.4 38.4 0 1 0-54.336 54.336L457.664 512 353.6 616.064a38.4 38.4 0 1 0 54.336 54.336L512 566.336 616.064 670.4a38.4 38.4 0 1 0 54.336-54.336L566.336 512 670.4 407.936a38.4 38.4 0 1 0-54.336-54.336L512 457.664z\"></path>\n" +
                "                                    </svg>\n" +
                "                                </div>");
        }
        ,error: function(){
            //请求异常回调
        }
    });

    //合同上传
    upload.render({
        elem: '.file_contract' //绑定元素
        ,url: '/upload/uploadFile' //上传接口
        ,method: 'post'  //可选项。HTTP类型，默认post
        ,accept: 'file'
        // ,acceptMime: 'file/pdf'
        ,headers: {token: token}
        ,done: function(res){
            contractFile = res.data;
            console.log(contractFile)
        }
        ,choose: function(obj){
            obj.preview(function(index, file, result){
                console.log(index)
                console.log(file)
                console.log(result)
            })
        }
        ,error: function(){
            //请求异常回调
        }
    });

    //封面上传
    upload.render({
        elem: '.cover_img' //绑定元素
        ,url: '/upload/uploadFile' //上传接口
        ,method: 'post'  //可选项。HTTP类型，默认post
        ,accept: 'file'
        // ,acceptMime: 'file/pdf'
        ,headers: {token: token}
        ,done: function(res){
            titleImg = res.data;
        }
        ,error: function(){
            //请求异常回调
        }
    });

    $(".list_div").scroll(function(e){
        $(".day_column").scrollTop($(".list_div").scrollTop());
    });

    laydate.render({
        elem: '.select_date_input'
        ,format: 'yyyy.MM.dd'
    });
    laydate.render({
        elem: '.date_hours_content_input'
        ,type: 'time'
        ,format: 'HH:mm'
    });
    //选择模板
    $(".select_template").click(function(e){
        loadTemplate(null);//渲染
        layer.open({
            title: false,
            type: 1,
            anim: 5,
            closeBtn: 0,
            content: $(".van-pop-transparent")
        });
    });
    //选择模板确定
    $(".confirm-button").click((e) => {
        let uuidTemplate = $(".order-selected").attr("uuidTemplate");
        selectTemplate(uuidTemplate);
    });

    getPrivateOrder(); //数据渲染
    getData();//内容渲染
});