<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>项目管理-信息授权书</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="decorator" content="base"/>
    <link rel="stylesheet" type="text/css" href="${ctxPlugin}/static/css/reset.css"/>
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/style/formSelects-v4.css" media="all">
    <link rel="stylesheet" type="text/css" href="${ctxPlugin}/lib/font/iconfont.css"/>
    <style>
        .inline-block {
            display: inline-block
        }
    </style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-form layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <sfTags:pagePermission authFlag="XMGL_XMGL_XILR_ADD_T_${partner}"
                                       html='<a href="${ctx}/customerEntry/temporaryStorageList/${partner}"><li>信息登记</li></a>'/>
                <sfTags:pagePermission authFlag="XMGL_XMGL_XXSQS_T_${partner}"
                                       html='<a href="${ctx}/customerEntry/infoAuthorizationList/${partner}"><li class="layui-this">信息授权书</li></a>'/>
                <button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10 " type="reset" onclick="reset()">
                    <i class="layui-icon fs-12">&#xe9aa;</i>
                    重置
                </button>
                <button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10" id="searchBtn" lay-submit
                        lay-filter="LAY-user-back-search"><i class="layui-icon fs-12">&#xe615;</i>查询
                </button>
            </ul>
        </div>
        <div class="layui-card-body layuiadmin-card-header-auto">
            <form class="layui-form layui-card" action="" id="searchForm">
                <div class="layui-form-item">

                    <div class="layui-col-lg2 layui-col-sm2">
                        <label class="layui-form-label">授权状态：</label>
                        <div class="layui-input-block">
                            <select name="authorization">
                                <option value="">请选择</option>
                                <option value="2">已发起</option>
                                <option value="3">已授权</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-lg2 layui-col-sm2">
                        <label class="layui-form-label">业主姓名：</label>
                        <div class="layui-input-block">
                            <input type="text" name="tenantName" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-lg2 layui-col-sm3">
                        <label class="layui-form-label">联系方式：</label>
                        <div class="layui-input-block">
                            <input type="text" name="mobile" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-lg4 layui-col-sm6">
                        <label class="layui-form-label">创建时间：</label>
                        <div class="layui-input-block">
                            <div class="layui-col-xs5">
                                <input type="text" name="createTimeMin" class="layui-input" id="createEndStartTime"
                                       placeholder="开始日期">
                            </div>
                            <div class="layui-col-xs2 text-c lh-30">
                                —
                            </div>
                            <div class="layui-col-xs5">
                                <input type="text" name="createTimeMax" class="layui-input" id="createEndEndTime"
                                       placeholder="结束日期">
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-hide" lay-skin="row" id="test" lay-filter="test"></table>
            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-sm" lay-event="export" id="exportBtn"><i class="layui-icon layui-icon-export"></i>导出列表</button>
                </div>
            </script>
        </div>
    </div>
</div>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/lib/formSelects-v4.js"></script>
<script>
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer', 'laypage', 'laydate', 'form'], function () {
        $ = layui.$;
        tableExt = layui.tableExt;
        layer = layui.layer;
        laypage = layui.laypage;
        laydate = layui.laydate;
        form = layui.form;
        table = tableExt.getLayTable();

        <%--var type = "${user.userType}";--%>

        //开始日期
        var endStartTime = laydate.render({
            elem: '#createEndStartTime'
            /* ,type: 'datetime'*/
            , done: function (value, date) {
                //更新结束日期的最小日期
                endEndTime.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });
                //自动弹出结束日期的选择器
                endEndTime.config.elem[0].focus();
            }
        });
        //结束日期
        var endEndTime = laydate.render({
            elem: '#createEndEndTime'
            /* ,type: 'datetime'*/
            , done: function (value, date) {
                //更新开始日期的最大日期
                endStartTime.config.max = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });

        var editFg = '${fns:checkPagePermission(request, editBthPermission)}';


        tableExt.render({
            elem: '#test'
            , title: '信息授权书'
            , height: 'full-190'
            , toolbar: '#toolbarDemo'
            , defaultToolbar: false
            , limits: [20, 50, 100]
            , limit: 20
            , page: true //开启分页
            , url: '${ctx}/customerEntry/ajaxForInfoAuthorizationData?partner=' + '${partner}'
            , method: "post"
            , cols: [[
                {type: 'numbers', fixed: 'left', title: '序号'}
                , {type: 'checkbox', fixed: 'left'}
                , {
                    field: 'id',
                    title: '操作',
                    minWidth: '230',
                    align: 'center',
                    fixed: 'left',
                    templet: function (d) {
                        var html = "";
                        if (d.authorization === '2'){
                            html += "<a href=\"#\" class=\"layui-table-link layui-icon  \" style='font-size:14px;' onclick=\"getSignUrl('" + d.id_code + "', '"+d.mobile+"')\">授权链接</a>&nbsp;&nbsp;";
                        }
                        if (d.authorization === '3' && d.old_flag === '0') {
                            html += "<a href=\"#\" class=\"layui-table-link layui-icon   \" style='font-size:14px;' onclick=\"reauthorization('" + d.id_code + "', '"+d.mobile+"', '"+d.id+"')\">重新授权</a>&nbsp;&nbsp;";
                        }

                        if (!isBlank(html)) {
                            return html;
                        } else {
                            return "--";
                        }
                    }
                }
                ,
                {field: 'name',title: '业主姓名',minWidth: '200',sort: false,align: 'center',exportable: true}
                ,{field: 'authorization',title: '授权状态',minWidth: '100', sort: false,align: 'center', exportable: true,
                    templet: function (d) {
                        if (d.tenant_type === '2') {
                            return "-"
                        }
                        //1.未授权 2.已发起 3.已授权
                        if (d.authorization === '2') {
                            return "已发起";
                        } else if (d.authorization === '3') {
                            return "已授权";
                        } else if ((d.authorization === '4')) {
                            return "无授权";
                        } else {
                            return "未授权";
                        }
                    },
                    expFormat: function (d) {
                        if (d.tenant_type === '2') {
                            return "-"
                        }
                        if (d.authorization === '2') {
                            return "已发起";
                        } else if (d.authorization === '3') {
                            return "已授权";
                        } else {
                            return "未授权";
                        }
                    }
                }
<%--                <c:if test="${partner eq '04'}">--%>
<%--                    ,{field:'filing_type', title: '备案类型',align: 'center',exportable:true--%>
<%--                        ,templet:function(d){--%>
<%--                            if(d.filing_type == 1){--%>
<%--                                return "农户备案";--%>
<%--                            } else if(d.filing_type == 2){--%>
<%--                                return "项目公司备案";--%>
<%--                            }--%>
<%--                            return "";--%>
<%--                        },--%>
<%--                        expFormat:function(d){--%>
<%--                            if(d.filing_type == 1){--%>
<%--                                return "农户备案";--%>
<%--                            } else if(d.filing_type == 2){--%>
<%--                                return "项目公司备案";--%>
<%--                            }--%>
<%--                            return "";--%>
<%--                        }--%>
<%--                    }--%>
<%--                </c:if>--%>
                , {field: 'mobile', title: '联系方式', minWidth: '100', sort: false, align: 'center', exportable: true}
                , {field: 'id_code', title: '身份证号', minWidth: '100', sort: false, align: 'center', exportable: true}
                , {field: 'create_time', title: '创建时间', minWidth: '100', sort: false, align: 'center', exportable: true}
                , {field: 'sign_time', title: '签署时间', minWidth: '100', sort: false, align: 'center', exportable: true}

            ]], done: function (res, cuss, count) {
                $('span[data-pass="passed"]').parent().parent().parent().css('background-color', '#ffeaf2');
            }
            , exportOpt: {                           //导出选项配置
                ele: '#exportBtn',                   //导出的Dom元素
                headerTitle: '信息登记',             //excel表格的标题
                pageData: false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                maxAmount: 5000,                    //当pageData为false生效
                fileName: '信息登记',
                where: function () {                 //当pageData为false时生效，过滤的条件
                    return _serializeJson($("#searchForm"));
                }
            }
        });

        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var ids = [];
            switch (obj.event) {

            }

        });

        form.on('select(province)', function (data) {
            var province = $(data.elem).find("option:selected").attr("title");
            provinceOrder(province);
        });
        form.on('select(city)', function (data) {
            var city = $(data.elem).find("option:selected").attr("title");
            cityOrder(city);

        });

        function provinceOrder(province) {
            $("#city").empty();
            $("#area").empty();
            if (isBlank(province)) {
                $("#city").append("<option value=''>市</option>");
                return "";
            }
            $.ajax({
                type: "POST",
                url: "${ctx}/main/redirect/getCitysByProId",
                data: {
                    province: province
                },
                success: function (result) {

                    if (result == "205") {
                        layer.msg("暂无数据!")
                        return
                    }
                    var html = " <option value=''>市</option>";
                    for (var i = 0; i < result.length; i++) {
                        var city = result[i];
                        html = html + '<option value="' + city.columns.CityName + '" title="' + city.columns.CityID + '">' + city.columns.CityName + '</option>';
                    }
                    $("#city").append(html);
                    form.render('select');
                }
            });

        }

        function cityOrder(city, arean) {
            $("#area").empty()
            if (isBlank(city)) {
                $("#area").append("<option value=''>区/县</option>");
                return "";
            }
            $.ajax({
                type: "POST",
                url: "${ctx}/main/redirect/getAreaByCityId",
                data: {
                    city: city
                },
                success: function (result) {
                    if (result == "205") {
                        layer.msg("暂无数据!")
                        return
                    }
                    var html = "<option value=''>区/县</option>";
                    for (var i = 0; i < result.length; i++) {
                        var area = result[i];
                        html = html + '<option value="' + area.columns.DistrictName + '" value="' + area.columns.DistrictId + '">' + area.columns.DistrictName + '</option>';
                    }
                    $("#area").append(html);
                    if (!isBlank(arean)) {
                        $("#area").val(arean)
                    }

                    form.render('select');
                }
            });

        }


        //监听搜索
        form.on('submit(LAY-user-back-search)', function (data) {
            var field = data.field;
            //执行重载
            tableExt.reload('test', {
                where: field,
                page: {
                    curr: 1
                }
            });
        });

        document.addEventListener('keydown', function (event) {
            if (event.keyCode === 13) {
                //执行相关操作
                $("#searchBtn").click();
            }
        });
    })


    function searchOrder() {
        layer.closeAll()
        //执行重载
        var wherobj = _serializeJson($("#searchForm"));
        tableExt.reload('test', {
            where: wherobj
        });
    }
    function getSignUrl(idCode,mobile){
        var patnerId = `${partner}`;
        var loadingIndex = layer.load(2, {shade: [0.5,'#fff']});
        $.ajax({
            type: 'post',
            url: '${ctx}/customerEntry/getEsignUrl',
            data: {
                idCode: idCode,
                mobile: mobile,
                patnerId: patnerId
            },
            success: function (result) {
                layer.close(loadingIndex);
                if (result.code === '200') {
                    layer.confirm('授权签约短链接：' + result.data.shortUrl, {
                        icon: 3,
                        btn: ['确定', '取消']
                    })
                } else {
                    layer.msg(result.errMsg);
                }
            },complete: function () {
                layer.close(loadingIndex);
            }
        })
    }

    function reauthorization(idCode,mobile,id){
        layer.confirm('确定重新授权？', {
            icon: 3,
            btn: ['确定', '取消']
        }, function (index) {
            layer.close(index);
            var loadingIndex = layer.load(2, {shade: [0.5,'#fff']});
            var patnerId = `${partner}`;
            $.ajax({
                type: 'post',
                url: '${ctx}/customerEntry/reAuthorization',
                data: {
                    idCode: idCode,
                    mobile: mobile,
                    patnerId: patnerId,
                    id:id
                },
                success: function (result) {
                    if (result.code === '200') {
                        layer.msg('操作成功！', {icon: 1, time: 1000}, function () {
                            searchOrder();
                        });
                    } else {
                        layer.msg("操作失败，"+result.errMsg);
                    }
                    layer.close(loadingIndex);
                },
                error: function(err) {
                    layer.close(loadingIndex);
                    console.log("err",err);
                    layer.msg("系统错误，请联系管理员")
                }
            })
        })
    }

    function isBlank(val) {
        if (val == null || val == '' || val == undefined) {
            return true;
        }
        return false;
    }

    function reset() {
        layui.form.render();
        $("#searchForm").find("select").val("");
        $("#searchForm").find("input").val("");
    }
</script>
</body>
</html>

