<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>上传信息授权书</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="decorator" content="base"/>
    <link rel="stylesheet" type="text/css" href="${ctxPlugin}/static/css/reset.css" />
    <style>html{background-color: #fff;padding-bottom: 50px;}</style>
</head>
<body>
<div class="layui-form">
    <div class="layui-card-body">
        <div id="textDiv">
            <div class="layui-row">
                <div class="layui-col-lg9 layui-col-sm9 ">
                    <label class="layui-form-label"><i class="mark">*</i>信息授权书：</label>
                    <div class="layui-input-block img-box ml-120">
                        <div style="display: flex">
                            <div id="authorizationDiv">
                                <div id="authorizationUploader">
                                    <input type="hidden" id="entryId" value="${entryId}">
                                <span style="color:blue;cursor: pointer"id="authorization">上传</span>
                                </div>
<%--                                <c:if test="${not empty entry.designDrawings}">--%>
<%--                                    <c:forEach items="${entry.designDrawings}" var="file"  varStatus="vs">--%>
<%--                                        <div style="margin-top: 5px">--%>
<%--                                             <span style="color: red" class="layui-icon-close layui-icon" onclick="delImg(this,'authorizationUploader')"></span>--%>
<%--                                            <a style="color:#2890ac;" target="_blank" onclick="previewUrl('${commonStaticImgPath}${file}')" class="download-link">${fns:substringAfterLast(file, '/')}</a>--%>
<%--                                            <input type="hidden" class="authorization"  value="${file}">--%>
<%--                                        </div>--%>
<%--                                    </c:forEach>--%>
<%--                                </c:if>--%>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="operate-footer">
        <input type="button" value="确定" class="layui-btn " onclick="confirm()">
        <input type="button" value="取消" class="layui-btn layui-btn-primary" onclick="cancel()">
    </div>
</div>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/xm-select.js"></script>
<script>
    var materialCode = null;
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'layedit', 'laydate', 'jquery', 'upload', 'layer'], function () {
        $ = layui.$
            , element = layui.element
            , form = layui.form
            , layer = layui.layer
            , laydate = layui.laydate;
        var upload = layui.upload;
        upload.render({
            elem: '#authorizationUploader',
            url: '${ctx}/common/uploadFile3',
            multiple:true,
            accept: 'file',
            // exts: 'pdf',
            before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                });
            },
            done: function (res) {
                //上传完毕回调
                let path = res.path;
                let index = path.lastIndexOf('/');
                let name = path.substring(index + 1);
                $("#authorizationUploader").hide();
                let html = '<div style="margin-top: 5px"><span style="color:red;" class="layui-icon-close layui-icon" onclick="delImg(this,\'authorizationUploader\')"></span>';
                html += '<a style="color:#2890ac;" target="_blank"  onclick="previewUrl(' + "\'" + '${commonStaticImgPath}' + path + "\'" + ')"    class="download-link">' + name + '</a>';
                html += '<input type="hidden" id="authorizationPath" value="' + path + '"/> </div>';
                $("#authorizationDiv").append(html);
            },
            error: function () {
                //请求异常回调
            }
        });

    });
    function delImg(that, id) {
        $("#" + id).show();
        $(that).parent().remove();
    }
    function confirm(){
        let authorization = $("#authorizationPath").val();
        if (isBlank(authorization)){
            layer.msg("请上传授权书", {icon: 2});
            return;
        }
        let entryId = $("#entryId").val();
        var ss = layer.load(2, {shade: [0.5, '#fff'], content: ''});
        $.ajax({
            url: '${ctx}/customerEntry/uploadAuthorization',
            type: 'POST',
            data: {entryId: entryId, authorization: authorization},
            dataType: 'json',
            success: function (result) {
                console.log("结果："+result)
                if (result.code == '200') {
                    var index = parent.layer.getFrameIndex(window.name);
                    layer.msg("操作成功", {icon: 1, time: 1000}, function () {
                        parent.layer.close(index);
                        parent.table.reload('test');
                    })
                }else {
                    layer.close(ss);
                    layer.msg(result.errMsg, {icon: 2});
                }
            }, error: function () {
                layer.close(ss);
                layer.msg("操作失败", {icon: 2});
            }, complete: function () {
                layer.close(ss);
            }
        });


    }

    function isBlank(val) {
        if (val == null || val == '' || val == undefined) {
            return true;
        }
        return false;
    }

    function cancel(){
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }
</script>
</body>
</html>