<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <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" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/style/admin.css" media="all">
    <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">
    <style>
        html{
            background-color: #fff;
        }
        .hide{
            display: none;
        }
        td .layui-form-select{
            width: 150px;
            margin-right: 15px;
            float: left;
        }
        .load-icon{background: url('${ctxPlugin}/static/img/shili_img.png') center center no-repeat; width: 12px; height: 12px; display: inline-block; border-radius: 50%;
            vertical-align: text-bottom;transform: translate(0px, -1px);margin-right: 2px;}

        .w-130{width: 110px;}
        .w-130+.layui-input-block{margin-left: 140px;}
    </style>
</head>
<body>
<div class="layui-form">
    <div class="layui-card">
        <div class="layui-card-body pt-20 pb-40 over-auto">
            <div class="layui-col-xs12 form-box">
                <div class="layui-inline layui-col-xs4">
                    <label class="layui-form-label w-130">电站编码：</label>
                    <div class="layui-input-block ">
                        <input type="text"  placeholder="请输入" class="layui-input" value="${insurance.columns.power_station_code}" disabled>
                        <input type="text" name="id" class="layui-input hide" value="${insurance.columns.id}">
                    </div>
                </div>
                <div class="layui-inline layui-col-xs4">
                    <label class="layui-form-label w-130">产品名称：</label>
                    <div class="layui-input-block ">
                        <input type="text"   class="layui-input" value="${insurance.columns.project_name}" disabled>
                    </div>
                </div>
                <div class="layui-inline layui-col-xs4">
                    <label class="layui-form-label w-130">代理商：</label>
                    <div class="layui-input-block ">
                        <input type="text"  class="layui-input" value="${insurance.columns.trader_name}" disabled>
                    </div>
                </div>
                <div class="layui-inline layui-col-xs4">
                    <label class="layui-form-label w-130">项目公司：</label>
                    <div class="layui-input-block ">
                        <input type="text"   class="layui-input" value="${insurance.columns.project_company_name}" disabled>
                    </div>
                </div>
                <div class="layui-inline layui-col-xs4">
                    <label class="layui-form-label w-130">备案类型：</label>
                    <div class="layui-input-block ">
                        <c:if test="${insurance.columns.filing_type eq '1'}">
                            <input type="text" class="layui-input" value="农户备案" disabled>
                        </c:if>
                        <c:if test="${insurance.columns.filing_type eq '2'}">
                            <input type="text" class="layui-input" value="项目公司备案" disabled>
                        </c:if>
                    </div>
                </div>
                <div class="layui-inline layui-col-xs4">
                    <label class="layui-form-label w-130">创建时间：</label>
                    <div class="layui-input-block ">
                        <input type="text"  class="layui-input" value="${insurance.columns.create_time}" disabled>
                    </div>
                </div>
                <div class="layui-inline layui-col-xs4">
                    <label class="layui-form-label w-130">业主姓名：</label>
                    <div class="layui-input-block ">
                        <input type="text"   class="layui-input" value="${insurance.columns.tenant_name}" disabled>
                    </div>
                </div>
                <div class="layui-inline layui-col-xs4">
                    <label class="layui-form-label w-130">联系电话：</label>
                    <div class="layui-input-block ">
                        <input type="text"  class="layui-input" value="${insurance.columns.mobile}" disabled>
                    </div>
                </div>
                <div class="layui-inline layui-col-xs4">
                    <label class="layui-form-label w-130">身份证号：</label>
                    <div class="layui-input-block ">
                        <input type="text" class="layui-input" value="${insurance.columns.id_code}" disabled>
                    </div>
                </div>
                <div class="layui-inline layui-col-xs8">
                    <label class="layui-form-label w-130">安装地址：</label>
                    <div class="layui-input-block ">
                        <c:choose>
                            <c:when test="${insurance.columns.province eq insurance.columns.city}">
                                <input type="text"  name="adr" class="layui-input" value="${insurance.columns.province}${insurance.columns.area}${insurance.columns.address}" disabled>
                            </c:when>
                            <c:otherwise>
                                <input type="text"  name="adr" class="layui-input" value="${insurance.columns.province}${insurance.columns.city}${insurance.columns.area}${insurance.columns.address}" disabled>
                            </c:otherwise>
                        </c:choose>
                    </div>
                </div>
            </div>
        </div>
        <div>
            <p class="layui-elem-quote" style="margin: 0px 0px 0px 10px">批改信息</p>
            <div class="layui-form mt-20 pr-20">
                <div class="layui-col-xs12 form-box">
                    <div class="layui-inline layui-col-xs6">
                        <label class="layui-form-label w-130"><i class="red">*</i>批改类型：</label>
                        <div class="layui-input-block ">
                            <select name="changeType" id="changeType" lay-verify="changeType" lay-filter="changeType"  lay-search>
                                <option value="">请选择</option>
                                <option value="1">基本信息</option>
                                <option value="3">保额</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline layui-col-xs6 hide" id="baseInfo">
                        <label class="layui-form-label w-130"><i class="red">*</i>基本信息：</label>
                        <div class="layui-input-block ">
                            <select name="baseSelect" lay-filter="baseSelect"  xm-select="baseSelect" xm-select-type="1" xm-select-height="30px" xm-select-show-count="6" xm-select-search>
                                <option value="">请选择</option>
                                <option value="1">投保人/被投保人</option>
                                <option value="2">标的地址</option>
                                <option value="5">第一受益人</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs12 form-box peopleDiv hide">
                    <div class="layui-inline layui-col-xs6">
                        <label class="layui-form-label w-130">原投保人：</label>
                        <div class="layui-input-block ">
                            <input type="text"  class="layui-input" value="${insurance.columns.policyholder}" disabled>
                        </div>
                    </div>
                    <div class="layui-inline layui-col-xs6">
                        <label class="layui-form-label w-130">批改投保人：</label>
                        <div class="layui-input-block ">
                            <input type="text" class="layui-input" value="${insuranceSet.columns.policyholder}" disabled>
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs12 form-box peopleDiv hide">
                    <div class="layui-inline layui-col-xs6">
                        <label class="layui-form-label w-130"><i class="red">*</i>原被保人：</label>
                        <div class="layui-input-block ">
                            <input type="text"  class="layui-input" value="${insurance.columns.insurant}" disabled>
                        </div>
                    </div>
                    <div class="layui-inline layui-col-xs6">
                        <label class="layui-form-label w-130"><i class="red">*</i>批改被保人：</label>
                        <div class="layui-input-block ">
                            <input type="text" class="layui-input" value="${insuranceSet.columns.insurant},${entry.projectCompanyName}" disabled>
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs12 form-box addressDiv hide">
                    <div class="layui-inline layui-col-xs6">
                        <label class="layui-form-label w-130"><i class="red">*</i>原地址：</label>
                        <div class="layui-input-block ">
                            <input type="text" class="layui-input"  value="${insurance.columns.insuranceAddress}" disabled>
                        </div>
                    </div>
                    <div class="layui-inline layui-col-xs6">
                        <label class="layui-form-label w-130"><i class="red">*</i>批改地址：</label>
                        <div class="layui-input-block ">
                            <c:choose>
                                <c:when test="${entry.province eq entry.city }">
                                    <input type="text"  class="layui-input" value="${entry.province}${entry.area}${entry.address}" disabled>
                                </c:when>
                                <c:otherwise>
                                    <input type="text"  class="layui-input" value="${entry.province}${entry.city}${entry.area}${entry.address}" disabled>
                                </c:otherwise>
                            </c:choose>
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs12 form-box beneficiaryDiv hide">
                    <div class="layui-inline layui-col-xs6">
                        <label class="layui-form-label w-130"><i class="red">*</i>原第一受益人：</label>
                        <div class="layui-input-block ">
                            <input type="text"  class="layui-input" value="${insurance.columns.insurant}" disabled>
                        </div>
                    </div>
                    <div class="layui-inline layui-col-xs6">
                        <label class="layui-form-label w-130"><i class="red">*</i>批改第一受益人：</label>
                        <div class="layui-input-block ">
                            <input type="text"  class="layui-input" value="${insuranceSet.columns.insurant},${entry.projectCompanyName}" disabled>
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs12 form-box totalMoneyDiv hide">
                    <div class="layui-inline layui-col-xs6">
                        <label class="layui-form-label w-130"><i class="red">*</i>原总保额：</label>
                        <div class="layui-input-block ">
                            <input type="text"   class="layui-input" value="${insurance.columns.insurance_money}" disabled>
                        </div>
                    </div>
                    <div class="layui-inline layui-col-xs6">
                        <label class="layui-form-label w-130"><i class="red">*</i>批改总保额：</label>
                        <div class="layui-input-block ">
                            <input type="text"   class="layui-input" value="${nowSumMoney}" disabled>
                            <span class="pos-a h-32 lh-32 layui-span-unit">元</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="operate-footer">
        <button type="button" lay-submit lay-filter="confirm" id="confirm" class="layui-btn">提交</button>
        <button type="button" class="layui-btn layui-btn-primary " onclick="closeDiv();" >关闭</button>
    </div>
</div>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/data.js"></script>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/lib/formSelects-v4.js"></script>
<script type="text/javascript">
    //初始数据
    var $form;
    var form;
    var $;
    layui.use(['form', 'table', 'upload', 'jquery','laydate','formSelects'], function () {
        $ = layui.jquery;
        form = layui.form;
        upload = layui.upload;
        laydate = layui.laydate;
        $form = $('form');
        formSelects = layui.formSelects;

        form.on('submit(confirm)', function (data) {
            var changeType = $("#changeType").val();
            let baseSelect = formSelects.value('baseSelect', 'valStr');
            if (isBlank(changeType)) {
                layer.msg("请选择要批改的数据");
                return;
            }
            if (changeType == "1" && isBlank(baseSelect)) {
                layer.msg("请选择要批改的数据");
                return;
            }
            if (changeType == "1") {//基本信息
                baseSelect = baseSelect.replaceAll(",", "|");
            } else {
                baseSelect = changeType;
            }
            var data={
                id: '${insurance.columns.id}',
                type: baseSelect
            }

            $.ajax({
                url: '${ctx}/customerEntry/insurance/correctOrder',
                method: 'post',
                data: JSON.stringify(data) ,
                dataType: 'JSON',
                contentType:"application/json",
                success: function (res) {
                    if (res.code == "200") {
                        parent.layer.msg("保存成功", {time: 2000});
                        closeDiv();
                        parent.table.reload('test');
                    } else {
                        layer.msg(res.errMsg, {time: 1000});
                    }
                },
                error: function (data) {
                }
            });
        });

        form.on('select(changeType)', function (data) {
            var changeType = $(data.elem).val();
            if (changeType == '1') {
                $("#baseInfo").removeClass("hide");
                $(".totalMoneyDiv").addClass("hide");
            } else if (changeType == '3') {
                $("#baseInfo").addClass("hide");
                $(".peopleDiv").addClass("hide");
                $(".addressDiv").addClass("hide");
                $(".beneficiaryDiv").addClass("hide");
                $(".totalMoneyDiv").removeClass("hide");
                formSelects.render("baseSelect");
            } else {
                $("#baseInfo").addClass("hide");
                $(".peopleDiv").addClass("hide");
                $(".addressDiv").addClass("hide");
                $(".beneficiaryDiv").addClass("hide");
                $(".totalMoneyDiv").addClass("hide");
                formSelects.render("baseSelect");
            }
        });

        formSelects.on('baseSelect', function(id, vals, val, isAdd, isDisabled){
            let baseSelect = formSelects.value('baseSelect', 'valStr');
            if (baseSelect.includes("1")) {
                $(".peopleDiv").removeClass("hide");
            } else{
                $(".peopleDiv").addClass("hide");
            }
            if (baseSelect.includes("2")) {
                $(".addressDiv").removeClass("hide");
            } else {
                $(".addressDiv").addClass("hide");
            }
            if (baseSelect.includes("5")) {
                $(".beneficiaryDiv").removeClass("hide");
            } else {
                $(".beneficiaryDiv").addClass("hide");
            }
        },true);


    })

    function  closeDiv() {
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index);
    }

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

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