<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>编辑页面</title>
</head>
<body>
<script type="text/html" id="form">
    <input type="hidden" name="id" value="{{= d.id }}" />
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
            				<div class="layui-form-item">
    				<label class="layui-form-label" title="所属分类"> <text title="必填项" style="color:red;">*</text> 所属分类</label>
    				<div class="layui-input-block">
        				<div class="xmSelect"
                data-name="category_id"
                data-sourceType="route"
                data-source="/admin.files.category/index"
                data-sourceTree="true"
                data-paging="false"
                data-radio="true"
                data-valueField="id"
                data-selected="{{=d.category_id}}"
				data-textField="name"
				data-placeholder="请选择所属分类"
				data-layVerify="required"
                ></div>
    				</div>
				</div>

				<div class="layui-form-item">
    				<label class="layui-form-label" title="文件名称"> <text title="必填项" style="color:red;">*</text> 文件名称</label>
    				<div class="layui-input-block">
        				<input autocomplete="off" type="text" name="name" id="name" placeholder="请输入文件名称" value="{{=d.name}}" class="layui-input" lay-verify="required">
    				</div>
				</div>

				<div class="layui-form-item">
    				<label class="layui-form-label" title="文件类型"> <text title="必填项" style="color:red;">*</text> 文件类型</label>
    				<div class="layui-input-block">
        				<input type="radio" name="file_type" id="file_type-image" value="image" title="图片" {{#if (d.file_type == 'image'){ }}checked="checked"{{# } }} />
			<input type="radio" name="file_type" id="file_type-video" value="video" title="视频" {{#if (d.file_type == 'video'){ }}checked="checked"{{# } }} />
			<input type="radio" name="file_type" id="file_type-music" value="audio" title="音频" {{#if (d.file_type == 'audio'){ }}checked="checked"{{# } }} />
			<input type="radio" name="file_type" id="file_type-file" value="file" title="文件" {{#if (d.file_type == 'file'){ }}checked="checked"{{# } }} />
    				</div>
				</div>

				<div class="layui-form-item">
    				<label class="layui-form-label" title="文件路径">文件路径</label>
    				<div class="layui-input-block">
        				<div class="laytpUpload"
                data-name="path"
                data-accept="file"
                data-multi="false"
                data-max="0"
                data-dir=""
                data-url=""
                data-mime=""
                data-size=""
                data-layVerify=""
                data-uploaded="{{=d.path}}"
            ></div>
    				</div>
				</div>

				<div class="layui-form-item">
    				<label class="layui-form-label" title="上传方式"> <text title="必填项" style="color:red;">*</text> 上传方式</label>
    				<div class="layui-input-block">
        				<input type="radio" name="upload_type" id="upload_type-local" value="local" title="本地上传" {{#if (d.upload_type == 'local'){ }}checked="checked"{{# } }} />
			<input type="radio" name="upload_type" id="upload_type-ali-oss" value="ali-oss" title="阿里云OSS" {{#if (d.upload_type == 'ali-oss'){ }}checked="checked"{{# } }} />
			<input type="radio" name="upload_type" id="upload_type-qiniu-kodo" value="qiniu-kodo" title="七牛云KODO" {{#if (d.upload_type == 'qiniu-kodo'){ }}checked="checked"{{# } }} />
    				</div>
				</div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="laytp-btn laytp-btn-primary laytp-btn-sm" lay-submit="" lay-filter="laytp-form">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="laytp-btn laytp-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</script>
<form class="layui-form" lay-filter="layui-form"></form>
<script>
    if(localStorage.getItem("staticDomain")){
        document.write("<link rel='stylesheet' href='" + localStorage.getItem("staticDomain") + "/component/laytp/css/laytp.css?v=" + localStorage.getItem("version") + "'>");
        document.write("<script src='" + localStorage.getItem("staticDomain") + "/component/layui/layui.js?v="+localStorage.getItem("version")+"'><\/script>");
        document.write("<script src='" + localStorage.getItem("staticDomain") + "/component/laytp/layuiConfig.js?v="+localStorage.getItem("version")+"'><\/script>");
    }else{
        document.write("<link rel='stylesheet' href='/static/component/laytp/css/laytp.css?v=" + localStorage.getItem("version") + "'>");
        document.write("<script src='/static/component/layui/layui.js?v="+localStorage.getItem("version")+"'><\/script>");
        document.write("<script src='/static/component/laytp/layuiConfig.js?v="+localStorage.getItem("version")+"'><\/script>");
    }
</script>
<script>
    layui.use(['laytp'],function(){
        let form = layui.form;
        let $ = layui.jquery;
        //获取参数ID
        var id = facade.getUrlParam('id');
        if(!id){
            facade.error('参数ID不能为空');
            return false;
        }

        //获取数据，渲染到对应的节点上
        facade.ajax({
            route: "/admin.files/info",
            data: {id: id},
            successAlert: false,
            showLoading: true
        }).done(function(res){
            if(res.code === 0){
                layui.laytpl($("#form").html()).render(res.data,function(string){
                    $("form").html(string);
                    layui.laytpForm.render();
                    form.render();
                });
            }
        });

        form.on('submit(laytp-form)', function(data){
            var btnAnim = layui.button.load({elem:$(this)});
            try{
                data = facade.setEditorField(data);
            }catch (e) {
                facade.error(e);
                return false;
            }
            facade.ajax({
                route:'/admin.files/edit',
                data:data.field
            }).done(function(res){
                if(res.code === 0){
                    parent.layui.layer.close(parent.layui.layer.getFrameIndex(window.name));//关闭当前页
                    parent.layui.table.reloadData("laytp-table");
                }
                btnAnim.stop();
            }).fail(function(){
                btnAnim.stop();
            });
            return false;
        });
    })
</script>
</body>
</html>