<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE HTML>
<html>
<head>
    <meta name="decorator" content="base"/>
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/static/css/reset.css">
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/dist/viewer.css" media="all">
    <style>
        html {background-color: #fff;padding-bottom: 50px;}td, th {text-align: center !important;}
        .layui-btn-danger {
            background-color: #0a6597;
        }
        .layui-tab{position: relative}
        a.gl-btn{position: absolute; top: 10px; right: 20px; background: #0a6597; padding: 0 10px; color: #FFF;}
        .layui-card{margin-bottom: 0px}
        .layui-form-select dl{max-height: 230px}
    </style>
</head>

<body>
<div class="layui-form">
    <div class="layui-card-body layui-col-xs12" id="LAY_app">
        <div class="layui-card zizhuOrder">
            <blockquote class="layui-elem-quote">发票信息</blockquote>
            <div class="layui-card-body ">
                <div class="layui-row layui-col-space12 layui-form-item">
                    <input type="hidden" id="releCode" class="layui-input" value="${releCode}">
                    <div class="layui-col-xs12 mb-10 pr-30 pl-30">
                        <button class="layui-btn layui-btn-sm" id="add"></i>新增</button>
                        <table class="layui-table">
                            <thead>
                            <tr>

                                <th style="width: 20%">发票代码</th>
                                <th>发票号码</th>
                                <th>发票名称</th>
                                <th>开票时间</th>
                                <th style="width: 15%">发票金额</th>
                                <th style="width: 15%">开票税率</th>
                                <th>是否提交</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <c:forEach items="${invoiceList}" varStatus="vs" var="invoice">
                            <tr>
                                <td>${invoice.invoiceCode}</td>
                                <td>${invoice.invoiceNumber}</td>
                                <td>${invoice.invoiceName}</td>
                                <td>${invoice.invoiceDate}</td>
                                <td>${invoice.invoiceAmount}</td>
                                <td>${invoice.invoiceTax}</td>
                                <c:if test="${invoice.isSubmit eq '0'}"><td>未提交</td></c:if>
                                <c:if test="${invoice.isSubmit eq '1'}"><td>已提交</td></c:if>
                                <td>
                                    <button type="button" class="layui-btn layui-btn-sm layui-btn-danger <c:if test="${invoice.isSubmit eq '1'}">hide</c:if>" onclick="editInvoice('${invoice.id}')">编辑</button>
                                    <button type="button" class="layui-btn layui-btn-sm layui-btn-danger" onclick="look('${invoice.id}')">查看</button>
                                </td>
                            </tr>
                            </c:forEach>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item operate-footer" style="text-align: center;">
            <input type="button" lay-submit lay-filter="templeSave" id="templeSave" class="layui-btn" value="提交">
            <input type="button"  class="layui-btn layui-btn-primary" value="返回" onclick="closeDiv();">
        </div>
    </div>
</div>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/xm-select.js"></script>
<script src="${ctxPlugin}/lib/base64.js"></script>
<script type="text/javascript">
    //初始数据
    var $form;
    var form;
    var $;
    var imgs = '';
    var myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
    var matypeList ;
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['form', 'layedit', 'laydate', 'jquery', 'upload','layer'], function () {
        $ = layui.jquery;
        form = layui.form;
        $form = $('form');
        var upload = layui.upload;

        var tepChec = false;
        form.on('submit(templeSave)', function (data) {
            if(tepChec){
                return;
            }
            var releCode = $("#releCode").val();
            tepChec = true;
            $.ajax({
                url: '${ctx}/rele/submitInvoiceData',
                type: 'post',
                data: {
                    releCode:releCode
                },
                success: function (res) {
                    if (res.code === "200") {
                        layer.msg("保存成功", {time: 1000}, function(){
                            parent.location.reload(true);
                        });
                    } else if (res.code === '501') {
                        layer.msg(res.errMsg);
                        tepChec = false;
                    } else {
                        layer.msg("保存失败", {time: 1000});
                    }
                },
                error: function (data) {
                }
            });
        });

        $('#add').on('click',function(){
            var releCode = $("#releCode").val();
            layer.open({
                type: 2
                , title: '发票信息'
                , content: '${ctx}/rele/invoiceInfoAdd?releCode=' + releCode
                , area: ['100%', '100%']
                , yes: function(index, layero){

                }
            });
        });
    })


    function editInvoice(id) {
        var releCode = $("#releCode").val();
        layer.open({
            type: 2
            , title: '编辑'
            , content: '${ctx}/rele/invoiceInfoEdit?releCode=' + releCode+"&id="+id
            , area: ['100%', '100%']
            , yes: function(index, layero){

            }
        });
    }

    function look(id) {
        var releCode = $("#releCode").val();
        layer.open({
            type: 2
            , title: '查看'
            , content: '${ctx}/rele/invoiceInfoDetail?releCode=' + releCode+"&id="+id
            , area: ['100%', '100%']
            , yes: function(index, layero){

            }
        });
    }


    function closeDiv() {
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index);
    }

    function isBlank(val) {
        if (val == null || val == '' || val == undefined) {
            return true;
        }
        return false;
    }
    function delImg(that, id) {
        $("#" + id).show();
        $(that).parent().remove();
    }

    function previewUrl(_url) {
        if (!checkUrl(_url)) {
            return false;
        }
        var base = new Base64();
        var b64Encoded = base.encode(_url);
        if(_url.endsWith('pdf')){
            window.open('http://47.98.203.224:8012/onlinePreview?url=' + encodeURIComponent(b64Encoded)+'&officePreviewType=pdf');
        }else{
            window.open('http://47.98.203.224:8012/onlinePreview?url=' + encodeURIComponent(b64Encoded));
        }
    }

    function checkUrl(url) {
        //url= 协议://(ftp的登录信息)[IP|域名](:端口号)(/或?请求参数)
        var strRegex = '^((https|http|ftp)://)'//(https或http或ftp)
            + '(([\\w_!~*\'()\\.&=+$%-]+: )?[\\w_!~*\'()\\.&=+$%-]+@)?' //ftp的user@  可有可无
            + '(([0-9]{1,3}\\.){3}[0-9]{1,3}' // IP形式的URL- 3位数字.3位数字.3位数字.3位数字
            + '|' // 允许IP和DOMAIN（域名）
            + '(localhost)|'	//匹配localhost
            + '([\\w_!~*\'()-]+\\.)*' // 域名- 至少一个[英文或数字_!~*\'()-]加上.
            + '\\w+\\.' // 一级域名 -英文或数字  加上.
            + '[a-zA-Z]{1,6})' // 顶级域名- 1-6位英文
            + '(:[0-9]{1,5})?' // 端口- :80 ,1-5位数字
            + '((/?)|' // url无参数结尾 - 斜杆或这没有
            + '(/[\\w_!~*\'()\\.;?:@&=+$,%#-]+)+/?)$';//请求参数结尾- 英文或数字和[]内的各种字符
        var re = new RegExp(strRegex, 'i');//i不区分大小写
        //将url做uri转码后再匹配，解除请求参数中的中文和空字符影响
        if (re.test(encodeURI(url))) {
            return (true);
        } else {
            return (false);
        }
    }
</script>
</body>
</html>
