<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="keywords" content="">
    <meta name="description" content="">
    <title text="机构列表"></title>
    <link rel="stylesheet" href="../../../component/pear/css/pear.css"/>
    <link rel="stylesheet" href="../../../admin/css/other/user.css"/>
</head>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">统一代码：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="idCard"
                               placeholder="请输入社会统一信用代码搜索" class="layui-input">
                    </div>
                    <label class="layui-form-label">机构名称：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="name"
                               placeholder="请输入机构名称搜索" class="layui-input">
                    </div>
                </div>
                <button class="pear-btn pear-btn-md-0 pear-btn-primary"
                        lay-submit lay-filter="query">
                    <i class="layui-icon layui-icon-search"></i> 查询
                </button>
                <button type="reset" class="pear-btn pear-btn-md-0">
                    <i class="layui-icon layui-icon-refresh"></i> 重置
                </button>
            </div>
        </form>
    </div>
</div>
<div class="layui-card">
    <div class="layui-card-body">
        <table id="table" lay-filter="table"></table>
    </div>
</div>
</body>
<script type="text/html" id="toolbar">
   <!-- <div permission="bfyw:bfhk:add" style="display: inline-block;">
        <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
            <i class="pear-icon pear-icon-add"></i>
            添加
        </button>
    </div>-->
</script>
<script type="text/html" id="bar">
    {{#if (d.isBind == 1 ) { }}
    <a class="cool-line-btn cool-bg-blue" lay-event="jc">解除</a>
    <div class="cool-line-divider"></div>
    {{# } }}
    {{#if (d.examineStatus == 0 ) { }}
    <a class="cool-line-btn cool-bg-blue" lay-event="detail">审批</a>
    {{# } else { }}
    <a class="cool-line-btn cool-bg-blue" lay-event="detail">详情</a>
    {{# } }}
</script>
<script type="text/html" id="createTimeTpl">
    {{layui.util.toDateString(d.createTime, 'yyyy-MM-dd HH:mm:ss')}}
</script>
<script src="../../../component/layui/layui.js"></script>
<script src="../../../component/pear/pear.js"></script>
<script>
    layui.use(['request', 'table', 'form', 'popup', 'common'], function () {
        var request = layui.request,
            table = layui.table,
            form = layui.form,
            popup = layui.popup,
            common = layui.common;

        var MODULE_PATH = "/business/corp/v1/";
        request.tableRender({
            url: MODULE_PATH,
            cols: [
                [
                    {type: 'checkbox'},
                    {title: '机构类型', field: 'type', align: 'center', templet: function (d) {
                            return d.type == 0 ? '其他' : '房地产中介机构';
                        }
                    },
                    {title: '区县名称', field: 'districtName', align: 'center', width: '10%'},
                    {title: '机构名称', field: 'name', align: 'center', width: '10%'},
                    {title: '社会统一信用代码', field: 'idCard', align: 'center', width: '11%'},
                    {title: '公司地址', field: 'address', align: 'center'},
                    {title: '法人', field: 'legalPerson', align: 'center'},
                    {title: '是否绑定', field: 'isBind', align: 'center', templet: function (d) {
                            return d.isBind == 1 ? '<span class="layui-badge-dot success"></span>已绑定' : '<span class="layui-badge-dot warning"></span>未绑定';
                        }
                    },
                    {title: '审批状态', field: 'examineStatus', align: 'center', templet: function (d) {
                            if (d.examineStatus == 2) {
                                return '<span class="layui-badge-dot failure"></span>已驳回';
                            } else if (d.examineStatus == 1) {
                                return '<span class="layui-badge-dot success"></span>已审批';
                            } else {
                                return '<span class="layui-badge-dot warning"></span>待审批';
                            }
                        }
                    },
                    {title: '申请时间', field: 'createTime', templet: '#createTimeTpl'},
                    {title: '操作', toolbar: '#bar', align: 'center', width: 160}
                ]
            ]
        });

        table.on('tool(table)', function (obj) {
            if (obj.event === 'detail') {
                window.location.href = 'view.html?id=' + obj.data.id;
            } else if (obj.event === 'jc') {
                jc(obj.data);
            }else if (obj.event === 'refresh') {
                refresh();
            }
        });

        table.on('toolbar(table)', function (obj) {
            if (obj.event === 'add') {
                add();
            }
        });

        form.on('submit(query)', function (data) {
            refresh(data.field);
            return false;
        });

        window.add = function () {
            window.location.href = 'add.html?dyzt=1';
        };

        window.edit = function (data) {
            var status = parseInt(data.ywzt);
            if (status === 1 || status === 2) {
                popup.warning("已发起申请，请等待审核。");
                return false;
            }
            if (status === 3) {
                popup.warning("已完成申请。");
                return false;
            }
            window.location.href = 'add.html?id=' + data.id + '&dyzt=1';
        };

        window.jc = function (data) {
            var isBind = parseInt(data.isBind);
            if (isBind === 0) {
                popup.warning("解绑失败，已解绑");
                return false;
            }
            layer.confirm("是否确认解除绑定微信？", function () {
                request.http({
                    type: "get",
                    url: MODULE_PATH + "remove/" + data.id,
                    loading: true,
                    success: function (result) {
                        refresh();
                        if (result.success) {
                            popup.success(result.msg);
                        } else {
                            popup.failure(result.msg);
                        }
                    }
                })
            });
        };

        window.refresh = function (param) {
            table.reload('table', {where: param}, true);
        };
    })
</script>
</html>
