<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('企业打印列表列表')" />
</head>
<body class="gray-bg">
<div class="container-div" id="listPrint">
    <div class="row">


        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-primary btn-rounded btn-sm" onclick="qyDownloads()" >
                <i class="fa fa-download"></i> 批量下载
            </a>
            <!--  <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:pritn:export">
                <i class="fa fa-download"></i> 导出
             </a>-->
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:pritn:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:pritn:remove')}]];
    var prefix = ctx + "system/qypritn";

    $(function() {
        var options = {
            url: prefix + "/index?type="+[[${type}]]+"&typeid="+[[${typeid}]],
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "企业打印列表",
            pageSize: 20,
            search:false,
            pageList: [20],
            showSearch: false,
            columns: [{
                checkbox: true
            },
                {
                    title: '序号',
                    formatter: function (value, row, index) {
                        return "<span>"+$.table.serialNumber(index)+"</span>";
                    }
                },
                {
                    field : 'zhucehao',
                    title : '申请号'
                },
                {
                    field : 'qyname',
                    title : '企业名称'
                },
                {
                    field : 'qylx',
                    title : '企业类型'
                },
                {
                    field : 'createdate',
                    title : '审请时间',
                    sortable: true,
                    sortOrder:"asc"
                },
                {
                    field : 'laiyuan',
                    title : '信用代码'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="getinfo(\'' + row.zhucehao + '\',\''+row.qylx+'\')"><i class="fa fa-edit"></i>详细</a> ');
                        actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="addinfo(\'' + row.zhucehao + '\',this)"><i class="fa fa-remove"></i>下载</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });


    //批量下载
    function qyDownloads(){
        var checkbox = $("#listPrint input:checkbox:checked").splice(7);

        if(checkbox.length<=0){
            return $.modal.msgWarning("请勾选一条数据");
        }
        var arr = [];
        for (var i = 0 ; i < checkbox.length ; i++) {
            var nw = $(checkbox[i]).parent();
            arr.push({
                "sqh": nw.siblings().eq(1).text(),
                "sqrq": nw.siblings().eq(4).text(),
                "sqly": nw.siblings().eq(5).text(),
                "qylx": nw.siblings().eq(3).text(),
                "typeid": [[${typeid}]],
                "type": [[${type}]],
            })
        }
        console.log(arr);
        $.post(prefix+"/downQyinfo",{data:JSON.stringify(arr)},function (data) {
            if(data.code==0){
                $.modal.msgSuccess("下载成功"+data.data+"条数据,失败"+(arr.length-data.data)+"条数据")
            }else {
                $.modal.msgError("请勿重复下载")
            }
            console.log(data.msg);
        })
    }
    //详细信息
    function getinfo(url,qylx){
        console.log(prefix + "/getQyInfo?sqh=" + url+"&type=1&typeid="+[[${typeid}]]);
        options = {
            url: prefix + "/getQyInfo?sqh=" + url+"&type=1&typeid="+[[${typeid}]]+"&qylx="+qylx,
            title: "证照信息",
            btn: ['关闭'],
            yes: function (index, layero) {
                $.table.refresh();
                layer.close(index);
            }
        }
        $.modal.openOptions(options);
    }

    function addinfo(sqh,e) {
        var arr = [];
        arr.push({
            "sqh": $(e).parent().siblings().eq(2).text(),
            "sqrq": $(e).parent().siblings().eq(5).text(),
            "qylx": $(e).parent().siblings().eq(4).text(),
            "sqly": $(e).parent().siblings().eq(6).text(),
            "typeid": [[${typeid}]],
            "type": [[${type}]],
        })
        console.log(sqh);
        $.post(prefix+"/downQyinfo",{data:JSON.stringify(arr)},function (data) {
            if(data.code==0){
                $.modal.msgSuccess("下载成功");
            }else {
                $.modal.msgError("请勿重复下载")
            }
        })
    }

/*
    function getInfo(url){
        console.log(prefix + "/getQyInfo?url=" + url);
        options = {
            url: prefix + "/getQyInfo?url=" + url,
            title: "证照信息",
            btn: ['关闭'],
            yes: function (index, layero) {
                layer.close(index);
            }
        }
        $.modal.openOptions(options);
    }*/

</script>
</body>
</html>
