<!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">
<input type="hidden"  id="id" th:value="${state}" class="form-control" readonly/>

<div class="container-div" id="listPrint">
    <div class="row">
        <!--            <div class="col-sm-12 search-collapse">-->
        <!--                <form id="formId">-->
        <!--                    <div class="select-list">-->
        <!--                        <ul>-->
        <!--                            <li>-->
        <!--                                <p>申请来源：</p>-->
        <!--                                &lt;!&ndash;<input type="text" name="shenqinglaiyuan"/>&ndash;&gt;-->
        <!--                                <select  name="shenqinglaiyuan">-->
        <!--                                    <option></option>-->
        <!--                                    <optgroup  th:each="dict:${diction}">-->
        <!--                                        <option  th:tips="${dict}" th:text="${dict}"></option>-->
        <!--                                    </optgroup>-->
        <!--                                </select>-->
        <!--                            </li>-->
        <!--                            <li>-->
        <!--                            </li>-->
        <!--                        </ul>-->
        <!--                    </div>-->
        <!--                </form>-->
        <!--            </div>-->
        <div class="btn-group-sm" id="toolbar" role="group">

            <a class="btn btn-primary btn-rounded btn-sm" onclick="addAll()"><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:gtgsyw:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:gtgsyw:remove')}]];
    var auditFlag = [[${@permission.hasPermi('system:gtgsyw:audit')}]];
    var giveupFlag = [[${@permission.hasPermi('system:gtgsyw:giveup')}]];
    var prefix = ctx + "system/cprint";
    var type=[[${type}]];
    var typeid=[[${typeid}]];
    // var synUrl = "http://192.168.28.156:5000/getList";
    var synUrl = "http://localhost:8080/data.json";

    function getList(){
        $.modal.openFull(prefix + "/getList");;
    }
    // $.operate.post(prefix+"/requestList",function (e) {
    // 	console.log(e);
    // })
    $(function() {

        var options = {
            url: prefix + "/requestList?type="+type+"&typeid="+typeid,
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/addAll",
            exportUrl: prefix + "/export",
            giveupUrl: prefix + "/export/{id}",
            pageSize: 20,
            search:false,
            pageList: [20],
            showSearch: false,
            modalName: "证照打印",
            columns: [{
                checkbox: true
            },
                {
                    title: '序号',
                    formatter: function (value, row, index) {
                        return "<span shenqingdate='"+row.shenqingdate+"' bsid="+row.bsid+" appno="+row.appno+">"+$.table.serialNumber(index)+"</span>";
                    }
                },
                {
                    field : 'id',
                    title : 'ID',
                    visible: false,
                    formatter: function(value, row, index) {
                        console.log(row);
                        return row.bsid;
                    }
                },
                {
                    field : 'jingyingren',
                    title : '经营者'
                },
                {
                    field : 'zwzh',
                    title : '个体工商户名称'
                },   {
                    field : 'shenqingdate',
                    title : '申请时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        /**  编辑删除原始按钮 **/
                        var a = btoa(row.toUrl);
                        actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="getInfo(\'' + row.appno + '\')"><i class="fa fa-edit"></i>详细</a> ');

                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="addData(\''+ row.shenqingdate.replace(/[\r\n]/g,"") +'\',\'' + row.bsid + '\',\''+ a +'\',\''+ row.appno +'\')"><i class="fa fa-download"></i> 下载</a> ');
                        /*  actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                         actions.push('<a class="btn btn-danger btn-xs ' + giveupFlag + '" href="javascript:void(0)" onclick="$.operate.giveup(\'' + row.id + '\')"><i class="fa fa-remove"></i>不予受理</a>');*/
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);

    });

    function addData(shenqingdate,bsid,url,appNo) {
        url = atob(url);

        console.log(shenqingdate,bsid,url,appNo);
        $.post(prefix+"/add",{bsid:bsid,shenqingdate:shenqingdate,url:url,appNo:appNo,typeid:typeid,type:type},function (data) {
            if(data.code==0){
                $.modal.msgSuccess("下载成功")
            }else {
                $.modal.msgError("请勿重复下载")
            }

            console.log(data.msg);
        })
    }


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


    function addAll(){
        var checkbox = $("#listPrint input:checkbox:checked").splice(5);
        if(checkbox.length<=0){
            return $.modal.msgWarning("请勾选一条数据");
        }
        var arr = [];
        for (var i = 0 ; i < checkbox.length ; i++) {
            var nw = $(checkbox[i]).parent().siblings().eq(0).children();
            arr.push({
                "shenqingdate": nw.attr("shenqingdate"),
                "bsid": nw.attr("bsid"),
                "appno": nw.attr("appno"),
                "typeid":typeid,
                "type":type,
            })
        }
        console.log(arr);
        $.operate.post(prefix+"/addAll",{data:JSON.stringify(arr)},function (msg) {
            console.log(msg);
        })
    }
</script>



</body>
</html>
