<!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">
    <div class="row">
        <div class="col-sm-12 search-collapse" style="display: none">
            <form id="formId">
                <input type="text" th:value="${flag}" hidden name="flag" id="flag"/>
                <div class="select-list">
                    <ul>
                        <li>
                            <p>统一社会信用代码：</p>
                            <input type="text" name="uniformSocialCreditCode"/>
                        </li>
                        <li>
                            <p>单位名称：</p>
                            <input type="text" name="companyName"/>
                        </li>
                        <li>
                            <p>注册号：</p>
                            <input type="text" name="registrationNumber"/>
                        </li>
                        <li>
                            <p>经营者：</p>
                            <input type="text" name="operatorName"/>
                        </li>
                        <li>
                            <p>经营者身份证号：</p>
                            <input type="text" name="operatorIdCard"/>
                        </li>
                        <li>
                            <p>经营者手机号：</p>
                            <input type="text" name="operatorPhone"/>
                        </li>
                        <li>
                            <p>组成形式：</p>
                            <select name="organizationType" th:with="type=${@dict.getType('')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <!--                        <li>-->
                        <!--                            <p>状态 0未审核 1审核通过 2退回 3删除：</p>-->
                        <!--                            <input type="text" name="flag"/>-->
                        <!--                        </li>-->
                        <li>
                            <p>审核人：</p>
                            <input type="text" name="archiveBy"/>
                        </li>
                        <li class="select-time">
                            <p>核准日期：</p>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginCheckTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="params[endCheckTime]"/>
                        </li>
                        <li class="select-time">
                            <p>审核通过日期：</p>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginArchiveTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="params[endArchiveTime]"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="system:zx:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:zx: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:zx:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:zx:remove')}]];
    var prefix = ctx + "system/ytj/zx";
    var sortName = '';
    var sortOrder = '';
    var aTitle='';
    var isvisible=true;
    if ($("#flag").val() == '0') {
        aTitle="";
        sortName = 'createTime';
        sortOrder = 'asc';
        isvisible=false;
    } else if ($("#flag").val() == '1') {
        aTitle="核准日期"
        sortName = 'createTime';
        sortOrder = 'asc';
    } else if ($("#flag").val() == '2') {
        aTitle="审核通过日期"
        sortName = 'archiveTime';
        sortOrder = 'desc';
    } else if ($("#flag").val() == '3') {
        aTitle="审核通过日期"
        sortName = 'archiveTime';
        sortOrder = 'desc';
    }

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "个体工商注销",
            sortName: sortName,
            sortOrder: sortOrder,
            flag: $("#flag").val(),
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'applyForSource',
                    title: '申请来源'
                },
                {
                    field: 'companyName',
                    title: '单位名称'
                },
                {
                    field: 'uniformSocialCreditCode',
                    title: '统一社会信用代码'
                },
                {
                    field: 'operatorName',
                    title: '经营者'
                },
                // {
                //     field: 'operatorIdCard',
                //     title: '经营者身份证号'
                // },
                // {
                //     field: 'operatorPhone',
                //     title: '经营者手机号'
                // },
                // {
                //     field: 'organizationType',
                //     title: '组成形式'
                // },
                {
                    field: 'createTime',
                    title: '申请日期'
                },
                // {
                //     field: 'checkTime',
                //     title: '核准日期'
                // },
                {
                    field: 'archiveBy',
                    title: '审核人',
                    visible: isvisible
                },
                {

                    title: aTitle,
                    visible:isvisible,
                    formatter: function (value, row, index) {
                        if ($("#flag").val() == '0') {
                            return""
                        } else if ($("#flag").val() == '1') {
                            return row.checkTime
                        } else if ($("#flag").val() == '2') {
                            return row.archiveTime
                        } else if ($("#flag").val() == '3') {
                            return row.archiveTime
                        }
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        var flag = $("#flag").val();
                        if (flag == '0' || flag == '1') {
                            actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="checkZx(\'' + row.id + '\')"><i class="fa fa-edit"></i>审核</a> ');
                            actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        } else {
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="viewZx(\'' + row.id + '\')"><i class="fa fa-edit"></i>查看</a> ');
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="downloadZx(\'' + row.id + '\')"><i class="fa fa-edit"></i>下载档案</a> ');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function downloadZx(id) {
        var data = new FormData();
        data.append("id", id);
        $.ajax({
            type: "POST",
            url: prefix + "/download",
            data: data,
            cache: false,
            contentType: false,
            processData: false,
            dataType: 'json',
            success: function (result) {
                $.modal.closeLoading();
                if (result.code == web_status.SUCCESS) {
                    $.modal.msgSuccess('下载成功');
                    window.location.href = result.msg;
                    // $.modal.msgSuccess(result.msg);
                } else {
                    $.modal.msgError(result.msg);
                }
            },
            error: function (error) {
                $.modal.closeLoading();
                $.modal.msgWarning(result.msg);
            }
        });
    }

    function viewZx(id) {
        layer.open({
            type: 2,
            area: ['100%', '100%'],
            fix: false,
            maxmin: true,
            shade: 0.3,
            title: "查看",
            content: prefix + "/view/" + id,
            btn: ['关闭',],
            shadeClose: false,
            cancel: function (index) {
                return true;
            }
        });
    }

    function checkZx(id) {
        layer.open({
            type: 2,
            area: ['100%', '100%'],
            fix: false,
            maxmin: true,
            shade: 0.3,
            title: "审核",
            content: prefix + "/check/" + id,
            btn: ['关闭'],
            shadeClose: false,
            yes: function (index, layero) {
                $.table.refresh();
                layer.close(index);
            }
        });
    }

    function changeFlag(id, flag) {
        $.modal.loading("请求中，请稍后...");
        var data = new FormData();
        data.append("id", id);
        data.append("flag", flag);
        $.ajax({
            type: "POST",
            url: prefix + "/tg",
            data: data,
            cache: false,
            contentType: false,
            processData: false,
            dataType: 'json',
            success: function (result) {
                $.modal.closeLoading();
                if (result.code == web_status.SUCCESS) {
                    layer.closeAll();
                    $.modal.alertSuccess("操作成功");
                } else {
                    $.modal.alertError(result.msg);
                }
                $.table.refresh();
            },
            error: function (error) {
                $.modal.closeLoading();
                $.modal.alertWarning("网络请求错误");
            }
        });
    }
</script>
</body>
</html>
