<%@ 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" href="${ctxPlugin}/static/css/reset.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/dist/viewer.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/style/formSelects-v4.css" media="all">
    <style>
        .layui-form-select dl{
            max-height:200px;
            width: 80%;
        }
        .w-130{width: 130px}
        .ml120 .layui-input-block{margin-left: 130px}
        .ml-130{margin-left:  130px}
        .border-grey{border: 1px solid #DDD; border-radius: 10px;}
        .table-input{width: 90%; border: none; text-align: center; height: 30px; line-height: 30px}
        .layui-elem-field legend{font-size: 16px}
        .img-80{display: flex; justify-content: center;}
        .img-80 .bj-img{margin-right: 0}
        .layui-table th {
            text-align: center;
        }                                                                                                                                             table thead {    width: calc(100% - 1em)}
    </style>
</head>
<body>
<div class="aaa" id="LAY_app">
    <div class="layui-form layui-card">
        <div class="layui-card-body over pt-20 pb-40 h-350" action="" id="detailSet">
            <blockquote class="layui-elem-quote">项目信息</blockquote>
            <div class="layui-row ml120 mt-20">
                <div class="layui-col-xs9">
                    <div class="layui-col-xs12 mb-15 pr-30">
                        <label class="layui-form-label w-130"><i class="red">*</i>代理商名称：</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" lay-verify="traderName" autocomplete="off" placeholder="请输入代理商名称" class="layui-input" value="${trader.name}">
                        </div>
                    </div>

                    <div class="layui-col-xs12 mb-10 pr-30">
                        <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" name="contacts" lay-verify="required" autocomplete="off" placeholder="请输入法定代表人" class="layui-input" value="${trader.contacts}">
                            </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 w-200" >
                                <input type="text" name="mobile" lay-verify="telephone" autocomplete="off" placeholder="请填写联系电话" class="layui-input" value="${trader.mobile}">
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-xs12 mb-10 pr-30">
                        <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" name="actualContacts" lay-verify="required" autocomplete="off" placeholder="请输入实控人" class="layui-input" value="${trader.actualContacts}">
                            </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 w-200" >
                                <input type="text" name="telephone" lay-verify="telephone" autocomplete="off" placeholder="请填写企业负责人电话" class="layui-input" value="${trader.telephone}">
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-xs12 mb-10 pr-30">
                        <div class="layui-inline layui-col-xs6">
                            <label class="layui-form-label w-130"><i class="red">*</i>实控人身份证号：</label>
                            <div class="layui-input-block w-200" >
                                <input type="text" name="actualIdCode" lay-verify="idcode" autocomplete="off" placeholder="请填写实控人身份证号" class="layui-input" value="${trader.actualIdCode}">
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-xs12 mb-10 pr-30">
                        <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" name="bankName" lay-verify="required" autocomplete="off" placeholder="请输入开户银行" class="layui-input" value="${trader.bankName}">
                            </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 w-200" >
                                <input type="text" name="bankCode" lay-verify="required" autocomplete="off" placeholder="请填写银行账号" class="layui-input" value="${trader.bankCode}">
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-xs12 mb-10 pr-30">
                        <div class="layui-inline layui-col-xs6">
                            <label class="layui-form-label w-130"><i class="red">*</i>统一信用代码：</label>
                            <div class="layui-input-block w-200" >
                                <input type="text" name="taxNumber" lay-verify="required" autocomplete="off" placeholder="请填写统一信用代码" class="layui-input" value="${trader.taxNumber}">
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-xs12 mt-10 pr-30">
                        <label class="layui-form-label w-130"><i class="red">*</i>代理商地址：</label>
                        <div class="layui-input-block ml-130">
                            <div class="layui-col-xs4 pr-20">
                                <select class="province" id="province" name="province" lay-verify="province" lay-filter="province" lay-search>
                                    <option value="">请选择省</option>
                                    <c:forEach items="${province}" var="pro">
                                        <option value="${pro.columns.ProvinceName}" title="${pro.columns.ProvinceID}" <c:if test="${trader.province == pro.columns.ProvinceName}">selected</c:if>>${pro.columns.ProvinceName}</option>
                                    </c:forEach>
                                </select>
                            </div>
                            <div class="layui-col-xs4 pr-20">
                                <select class="city" name="city" id="city" lay-verify="city" lay-filter="city" lay-search>
                                    <option value="">请选择市</option>
                                    <c:forEach items="${city}" var="cityList">
                                        <option value="${cityList.columns.CityName}" title="${cityList.columns.CityID}" <c:if test="${trader.city==cityList.columns.CityName}">selected</c:if>>${cityList.columns.CityName}</option>
                                    </c:forEach>
                                </select>
                            </div>
                            <div class="layui-col-xs4">
                                <select class="area" name="area" id="area" lay-verify="area" lay-filter="area" lay-search>
                                    <option value="">请选择县/区</option>
                                    <c:forEach items="${area}" var="areaList">
                                        <option value="${areaList.columns.DistrictName}" <c:if test="${trader.area==areaList.columns.DistrictName}">selected</c:if>>${areaList.columns.DistrictName}</option>
                                    </c:forEach>
                                </select>
                            </div>
                            <div class="layui-col-xs12 mt-20">
                                <input type="text" id="address" name="address" lay-verify="address" class="layui-input layui-col-lg2"
                                       value="${trader.address}">
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-xs12 mt-20 pr-30">
                        <label class="layui-form-label w-130"><i class="red">*</i>收货地址：</label>
                        <div class="layui-input-block ml-130">
                            <div class="layui-col-xs4 pr-20">
                                <select class="province" id="takeDeliveryProvince" name="takeDeliveryProvince" lay-verify="province" lay-filter="takeDeliveryProvince" lay-search>
                                    <option value="">请选择省</option>
                                    <c:forEach items="${province}" var="pro">
                                        <option value="${pro.columns.ProvinceName}" title="${pro.columns.ProvinceID}" <c:if test="${trader.takeDeliveryProvince == pro.columns.ProvinceName}">selected</c:if>>${pro.columns.ProvinceName}</option>
                                    </c:forEach>
                                </select>
                            </div>
                            <div class="layui-col-xs4 pr-20">
                                <select class="city" name="takeDeliveryCity" id="takeDeliveryCity" lay-verify="city" lay-filter="takeDeliveryCity" lay-search>
                                    <option value="">请选择市</option>
                                    <c:forEach items="${city2}" var="cityList">
                                        <option value="${cityList.columns.CityName}" title="${cityList.columns.CityID}" <c:if test="${trader.takeDeliveryCity == cityList.columns.CityName}">selected</c:if>>${cityList.columns.CityName}</option>
                                    </c:forEach>
                                </select>
                            </div>
                            <div class="layui-col-xs4">
                                <select class="area" name="takeDeliveryArea" id="takeDeliveryArea" lay-verify="area" lay-filter="takeDeliveryArea" lay-search>
                                    <option value="">请选择县/区</option>
                                    <c:forEach items="${area2}" var="areaList">
                                        <option value="${areaList.columns.DistrictName}" <c:if test="${trader.takeDeliveryArea == areaList.columns.DistrictName}">selected</c:if>>${areaList.columns.DistrictName}</option>
                                    </c:forEach>
                                </select>
                            </div>
                            <div class="layui-col-xs12 mt-20">
                                <input type="text" id="takeDeliveryAddress" name="takeDeliveryAddress" lay-verify="takeDeliveryAddress" class="layui-input layui-col-lg2"
                                       value="${trader.takeDeliveryAddress}">
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-xs12 mt-20 pr-30">
                        <label class="layui-form-label w-130">备注：</label>
                        <div class="layui-input-block ml-130">
                            <input type="text" name="remarks" autocomplete="off" placeholder="" class="layui-input" value="${trader.remarks}">
                        </div>
                    </div>
                    <div class="layui-col-xs12 mb-20 pr-30" style="margin-top: 10px !important">
                        <div class="layui-inline layui-col-xs6">
                            <label class="layui-form-label w-130"> <i class="red">*</i>项目：</label>
                            <div class="layui-input-block w-200" >
                                <select  id="qqProjectCode" name="qqProjectCode"  lay-filter="qqProjectCode" lay-verify="required" xm-select="qqProjectCode"  xm-select-type="1" xm-select-height="40px" xm-select-show-count="6" xm-select-search>
                                    <option value="">请选择</option>
                                    <c:forEach items="${qqProjectCodes}" var="qqProject">
                                        <option value="${qqProject.columns.code}" title="${qqProject.columns.name}" <c:if test="${trader.qqProjectCode == qqProject.columns.code}">selected</c:if>>${qqProject.columns.name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs3">
                    <div class="layui-input-block" style="margin-left: 50px">
                        <div id="imgsDiv" class="img-80">
                            <c:if test="${not empty trader.licenseImg}">
                                <div class="bj-img imgSpan"><span class="layui-icon-close layui-icon" onclick="delImg(this,'uploader','licenseImg')"></span>
                                    <img src="${commonStaticImgPath}${trader.licenseImg}" height="700" width="1200"/>
                                    <input type="hidden" class="imgPicker" value="${trader.licenseImg}"/> </div>
                            </c:if>
                        </div>
                        <div class="upload-container <c:if test="${not empty trader.licenseImg}">hide </c:if>" id="uploader" style="margin: 0 auto;">
                            <img src="" alt="img placeholder" id="imgsAdd">
                        </div>
                         <div style="width: 100%; text-align: center; color: #144856"><i class="mark">*</i>营业执照</div>
                    </div>
                    <div class="layui-input-block" style="margin-left: 50px">
                        <div id="qqjyglwtsImgDiv" class="img-80">
                            <c:if test="${not empty trader.qqjyglwtsImg}">
                                <div class="bj-img imgSpan"><span class="layui-icon-close layui-icon"  onclick="delImg(this,'qqjyglwtsImguploader','qqjyglwtsImg')"></span>
                                    <img src="${commonStaticImgPath}${trader.qqjyglwtsImg}" height="700" width="1200"/>
                                    <input type="hidden" class="imgPicker" value="${trader.qqjyglwtsImg}"/> </div>
                            </c:if>
                        </div>
                        <div class="upload-container  <c:if test="${not empty trader.qqjyglwtsImg}">hide </c:if>" id="qqjyglwtsImguploader" style="margin: 0 auto;">
                            <img src="" alt="img placeholder" id="qqjyglwtsImgAdd">
                        </div>
                        <div style="width: 100%; text-align: center; color: #144856">全权经营管理委托书</div>
                    </div>


                    <div class="layui-input-block" style="margin-left: 50px">
                        <div id="sfzfmfyjImgDiv" class="img-80">
                            <c:if test="${not empty trader.sfzfmfyjImg}">
                                <div class="bj-img imgSpan"><span class="layui-icon-close layui-icon"  onclick="delImg(this,'sfzfmfyjImguploader','sfzfmfyjImg')"></span>
                                    <img src="${commonStaticImgPath}${trader.sfzfmfyjImg}" height="700" width="1200"/>
                                    <input type="hidden" class="imgPicker" value="${trader.sfzfmfyjImg}"/> </div>
                            </c:if>
                        </div>
                        <div class="upload-container  <c:if test="${not empty trader.sfzfmfyjImg}">hide </c:if>" id="sfzfmfyjImguploader" style="margin: 0 auto;">
                            <img src="" alt="img placeholder" id="sfzfmfyjImgAdd">
                        </div>
                        <div style="width: 100%; text-align: center; color: #144856"><i class="mark">*</i>法定代表人身份证正反面<p>复印件(加盖公章)</p></div>
                    </div>
                    <div class="layui-input-block" style="margin-left: 50px">
                        <div id="sfzzmfyjImgDiv" class="img-80">
                            <c:if test="${not empty trader.sfzzmfyjImg}">
                                <div class="bj-img imgSpan"><span class="layui-icon-close layui-icon"  onclick="delImg(this,'sfzzmfyjImguploader','sfzzmfyjImg')"></span>
                                    <img src="${commonStaticImgPath}${trader.sfzzmfyjImg}" height="700" width="1200"/>
                                    <input type="hidden" class="imgPicker" value="${trader.sfzzmfyjImg}"/> </div>
                            </c:if>
                        </div>
                        <div class="upload-container  <c:if test="${not empty trader.sfzzmfyjImg}">hide </c:if>" id="sfzzmfyjImguploader" style="margin: 0 auto;">
                            <img src="" alt="img placeholder" id="sfzzmfyjImgAdd">
                        </div>
                        <div style="width: 100%; text-align: center; color: #144856"><i class="mark">*</i>实控人身份证正反面<p>复印件(加盖公章)</p></div>
                    </div>

                    <div class="layui-input-block" style="margin-left: 50px">
                        <div id="dlszrsqbImgDiv" class="img-80">
                            <c:if test="${not empty trader.dlszrsqbImg}">
                                <div class="bj-img imgSpan"><span class="layui-icon-close layui-icon"  onclick="delImg(this,'dlszrsqbImguploader','dlszrsqbImg')"></span>
                                    <img src="${commonStaticImgPath}${trader.dlszrsqbImg}" height="700" width="1200"/>
                                    <input type="hidden" class="imgPicker" value="${trader.dlszrsqbImg}"/> </div>
                            </c:if>
                        </div>
                        <div class="upload-container  <c:if test="${not empty trader.dlszrsqbImg}">hide </c:if>" id="dlszrsqbImguploader" style="margin: 0 auto;">
                            <img src="" alt="img placeholder" id="dlszrsqbImgAdd">
                        </div>
                        <div style="width: 100%; text-align: center; color: #144856">代理商准入申请表</div>
                    </div>
                </div>
            </div>

            <input type="hidden" name="traderId" id="traderId" value="${trader.id}">
            <input type="hidden" name="licenseImg" id="licenseImg" value="${trader.licenseImg}" lay-verify="imgsLs">
            <input type="hidden" name="qqjyglwtsImg" id="qqjyglwtsImg" value="${trader.qqjyglwtsImg}">
            <input type="hidden" name="sfzzmfyjImg" id="sfzzmfyjImg" value="${trader.sfzzmfyjImg}" lay-verify="imgsLs">
            <input type="hidden" name="sfzfmfyjImg" id="sfzfmfyjImg" value="${trader.sfzfmfyjImg}" lay-verify="imgsLs">
            <input type="hidden" name="dlszrsqbImg" id="dlszrsqbImg" value="${trader.dlszrsqbImg}">
            <div class="layui-col-xs12 mb-20 pr-30 mt-20">
            </div>
        </div>
        <div class="layui-form-item operate-footer" style="text-align: center;">
            <input type="button" lay-submit lay-filter="confirm" id="confirm" class="layui-btn " value="确认">
            <input type="button"   value="取消" class="layui-btn layui-btn-primary " onclick="closeDiv();" >
        </div>
    </div>
</div>
<div id="lookImg" class="hide pos-r">
    <div style="position:relative;width:90%;height:450px;">
        <div class="w-500 h-450 lookImg">
            <img src="" width="80%" id="image">
        </div>
    </div>
</div>

<fieldset class="layui-elem-field border-grey layui-field-title entryList hide copyfieldset" style="margin-top: 20px;">
    <legend>代理区域</legend>
    <div class="layui-col-xs12 mb-10 mt-20 pr-30">
        <label class="layui-form-label"><i class="red">*</i>代理区域：</label>
        <div class="layui-input-block">
            <div class="layui-col-xs3 pr-20">
                <select class="province agentProvince" lay-verify="province" lay-filter="agentProvince" lay-search>
                    <option value="">请选择省</option>
                    <c:forEach items="${province}" var="pro">
                        <option value="${pro.columns.ProvinceName}" title="${pro.columns.ProvinceID}" <c:if test="${trader.province == pro.columns.ProvinceName}">selected</c:if>>${pro.columns.ProvinceName}</option>
                    </c:forEach>
                </select>
            </div>
            <div class="layui-col-xs3 pr-20">
                <select class="city agentCity" lay-verify="city" lay-filter="agentCity" lay-search>
                    <option value="">请选择市</option>
                    <c:forEach items="${city}" var="cityList">
                        <option value="${cityList.columns.CityName}" title="${cityList.columns.CityID}" <c:if test="${trader.city==cityList.columns.CityName}">selected</c:if>>${cityList.columns.CityName}</option>
                    </c:forEach>
                </select>
            </div>
            <div class="layui-col-xs3">
                <select class="area agentArea" lay-verify="area" lay-filter="agentArea" lay-search>
                    <option value="">请选择县/区</option>
                    <c:forEach items="${area}" var="areaList">
                        <option value="${areaList.columns.DistrictName}" <c:if test="${trader.area==areaList.columns.DistrictName}">selected</c:if>>${areaList.columns.DistrictName}</option>
                    </c:forEach>
                </select>
            </div>
            <div class="layui-col-xs3">
                <input type="button" class="layui-btn layui-btn-danger ml-10 deleteBut" value="删除">
                <input type="button"  class="layui-btn addDaili" value="新增代理区域">
            </div>
        </div>
    </div>
    <div class="layui-col-xs12 mb-10 pr-30">
        <label class="layui-form-label"><i class="red">*</i>年度任务：</label>
        <div class="layui-input-block">
            <table lay-filter="parse-table-demo" >
                <thead>
                <tr>
                    <th lay-data="{field:'username', width:125}">2023年</th>
                    <th lay-data="{field:'joinTime', width:62}">1月</th>
                    <th lay-data="{field:'january', minWidth: 63}">2月</th>
                    <th lay-data="{field:'february', minWidth: 62}">3月</th>
                    <th lay-data="{field:'march', minWidth: 63}">4月</th>
                    <th lay-data="{field:'april', minWidth: 64}">5月</th>
                    <th lay-data="{field:'may', minWidth: 64}">6月</th>
                    <th lay-data="{field:'june', minWidth: 64}">7月</th>
                    <th lay-data="{field:'august', minWidth: 64}">8月</th>
                    <th lay-data="{field:'september', minWidth: 64}">9月</th>
                    <th lay-data="{field:'october', minWidth: 64}">10月</th>
                    <th lay-data="{field:'november', minWidth: 62}">11月</th>
                    <th lay-data="{field:'december', minWidth: 63}">12月</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td>装机容量(MW)</td>
                    <td><input type="text" class="table-input january"/></td>
                    <td><input type="text" class="table-input february"/></td>
                    <td><input type="text" class="table-input march"/></td>
                    <td><input type="text" class="table-input april"/></td>
                    <td><input type="text" class="table-input may"/></td>
                    <td><input type="text" class="table-input june"/></td>
                    <td><input type="text" class="table-input july" /></td>
                    <td><input type="text" class="table-input august"/></td>
                    <td><input type="text" class="table-input september"/></td>
                    <td><input type="text" class="table-input october"/></td>
                    <td><input type="text" class="table-input november"/></td>
                    <td><input type="text" class="table-input december"/></td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
</fieldset>
<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/dist/viewer.js"></script>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/lib/formSelects-v4.js"></script>
<script type="text/javascript">
    var viewer = new Viewer(document.getElementById('LAY_app'));
    //初始数据
    var $form;
    var form;
    var upload;
    var $;
    var imgs='';
    var myreg=/^[1][3,4,5,6,7,8,9][0-9]{9}$/;
    var reg = /^(\d{2})(\d{4})(\d{4})(\d{2})(\d{2})\d{2}(\d)(\d|X)$/;
    var shuzi = /^\d+(\.\d+)?$/;
    var icReg=/^((-?)(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2}))|0))$/;
    var icReg2=/^[/]$/;
    layui.use(['form', 'table', 'upload', 'jquery','formSelects'], function () {
        $ = layui.jquery;
        form = layui.form;
        formSelects = layui.formSelects;
        upload = layui.upload;
        $form = $('form');
        var table = layui.table;

        var qqProjectCode = "${trader.qqProjectCode}";
        formSelects.value('qqProjectCode', qqProjectCode.split(","), true);

        var qqProjectName = "${trader.qqProjectName}";
        formSelects.value('qqProjectName', qqProjectName.split(","), true);

        table.init('parse-table-demo',{
            height: 75
        })
        form.verify({
            traderName:function(value,item){
                if(!$.trim(value)){
                    return "代理商名称不能为空,请输入代理商名称！";
                }
            },
            loginName:function(value,item){
                if(!$.trim(value)){
                    return "登录账号不能为空,请输入登录账号！";
                }
                if($.trim(value).length<4){
                    return "登录账号不得小于4位,请重新输入！";
                }
                if($.trim(value).length>12){
                    return "登录账号不得大于12位,请重新输入！";
                }
            },
            password:function(value,item){
                if(!$.trim(value)){
                    return "登录密码不能为空,请输入密码后保存！";
                }
            },
            userName:function(value,item){
                if(!$.trim(value)){
                    return "联系人不能为空,请输入联系人！";
                }
            },
            telephone:function(value,item){
                if(!$.trim(value)){
                    return "手机号码不能为空,请输入手机号码后保存！";
                }
                if(!myreg.test($.trim(value))){
                    return "请输入正确的手机号码后保存！";
                }
            },
            idcode:function(value,item){
                if(!$.trim(value)){
                    return "身份证号不能为空,请输入身份证号！";
                }
                if(!reg.test($.trim(value))){
                    return "请输入正确的身份证号！";
                }
            },
            bond:function(value,item){
                if(!$.trim(value)){
                    return "保证金不能为空,请输入保证金！";
                }
                if(!shuzi.test($.trim(value))){
                    return "请输入正确的保证金！";
                }
            },

            province:function(value,item){
                if(!$.trim(value)){
                    return "省份不能为空,请选择省份！";
                }
            },
            city:function(value,item){
                if(!$.trim(value)){
                    return "城市不能为空,请选择城市！";
                }
            },
            area:function(value,item){
                if(!$.trim(value)){
                    return "区县不能为空,请选择区县！";
                }
            },
            address:function(value,item){
                if(!$.trim(value)){
                    return "详细地址不能为空,请输入地址后保存！";
                }
            },
            imgsLs:function(value,item){
                if(!$.trim(value)){
                    return "请上传证件信息！";
                }
            },
        });


        form.on('select(province)', function (data) {
            var province = $(data.elem).find("option:selected").attr("title");
            $("#address").val("");
            if (isBlank(province)) {
                $("#city").empty();
                $("#city").append("<option value=''>请选择市</option>");
                return "";
            }
            takeDeliveryProvince($(this),province,"city","area");
        });

        form.on('select(city)', function (data) {
            var city = $(data.elem).find("option:selected").attr("title");
            $("#area").empty();
            $("#address").val("");
            if (isBlank(city)) {
                $("#area").append("<option value=''>请选择县/区</option>");
                return "";
            }
            cityHtml($(this),city,"area")
        });

        form.on('select(takeDeliveryProvince)', function (data) {
            var province = $(data.elem).find("option:selected").attr("title");
            $("#takeDeliveryAddress").val("");
            if (isBlank(province)) {
                $("#city").empty();
                $("#city").append("<option value=''>请选择市</option>");
                return "";
            }
            takeDeliveryProvince($(this),province,"takeDeliveryCity","takeDeliveryArea");
        });

        form.on('select(takeDeliveryProvince)', function (data) {
            var province = $(data.elem).find("option:selected").attr("title");
            $("#takeDeliveryAddress").val("");
            if (isBlank(province)) {
                $("#city").empty();
                $("#city").append("<option value=''>请选择市</option>");
                return "";
            }
            takeDeliveryProvince($(this),province,"takeDeliveryCity","takeDeliveryArea");
        });

        form.on('select(takeDeliveryCity)', function (data) {
            var city = $(data.elem).find("option:selected").attr("title");
            $("#area").empty();
            $("#takeDeliveryAddress").val("");
            if (isBlank(city)) {
                $("#area").append("<option value=''>请选择县/区</option>");
                return "";
            }
            cityHtml(city,"takeDeliveryArea")
        });

        form.on('select(agentProvince)', function (data) {
            var province = $(data.elem).find("option:selected").attr("title");
            $(this).parents("fieldset").find(".agentCity").empty();
            if (isBlank(province)) {
                $(this).parents("fieldset").find(".agentCity").append("<option value=''>请选择市</option>");
                return "";
            }
            takeDeliveryProvince($(this),province,"agentCity","agentArea");
        });

        form.on('select(agentCity)', function (data) {
            var city = $(data.elem).find("option:selected").attr("title");
            $(this).parents("fieldset").find(".agentArea").empty();
            if (isBlank(city)) {
                $(this).parents("fieldset").find(".agentArea").append("<option value=''>请选择县/区</option>");
                return "";
            }
            cityHtml($(this),city,"agentArea")
        });

        form.on('submit(confirm)', function(data){
            var postData = data.field;

            var emptyFlag = false;
            var msgStr = '';
            var arr1 = new Array();


            var  qqProjectName =  formSelects.value('qqProjectCode', 'nameStr');
            postData.qqProjectName = qqProjectName;

            var  qqProjectCode =  formSelects.value('qqProjectCode', 'valStr');
            postData.qqProjectCode = qqProjectCode;

            //var qqProjectName= $("#qqProjectCode").find('option:selected').text();
            $("#tb_table").find(".entryList").each(function(){
                var january = $(this).find(".layui-table").find(".january").val();
                if (isBlank(january)) {
                    emptyFlag = true;
                    msgStr = '装机容量不能为空';
                    return false;
                } else if (!icReg.test(january) && !icReg2.test(january)) {
                    emptyFlag = true;
                    msgStr = '装机容量仅支持两位小数，或 /';
                    return false;
                }
                //let qqProjectCode= $("#qqProjectCode").val();
                if (isBlank(qqProjectCode)) {
                    emptyFlag = true;
                    msgStr = '项目编码不能为空';
                    return false;
                }
               /* let qqCompanyCode=   $("#qqCompanyCode").val();
                if (isBlank(qqCompanyCode)) {
                    emptyFlag = true;
                    msgStr = '外部编码不能为空';
                    return false;
                }*/
                var february = $(this).find(".layui-table").find(".february").val();
                if (isBlank(february)) {
                    emptyFlag = true;
                    msgStr = '装机容量不能为空';
                    return false;
                } else if (!icReg.test(february) && !icReg2.test(january)) {
                    emptyFlag = true;
                    msgStr = '装机容量仅支持两位小数，或 /';
                    return false;
                }
                var march = $(this).find(".layui-table").find(".march").val();
                if (isBlank(march)) {
                    emptyFlag = true;
                    msgStr = '装机容量不能为空';
                    return false;
                } else if (!icReg.test(march) && !icReg2.test(january)) {
                    emptyFlag = true;
                    msgStr = '装机容量仅支持两位小数，或 /';
                    return false;
                }
                var april = $(this).find(".layui-table").find(".april").val();
                if (isBlank(april)) {
                    emptyFlag = true;
                    msgStr = '装机容量不能为空';
                    return false;
                } else if (!icReg.test(april) && !icReg2.test(january)) {
                    emptyFlag = true;
                    msgStr = '装机容量仅支持两位小数，或 /';
                    return false;
                }
                var may = $(this).find(".layui-table").find(".may").val();
                if (isBlank(may)) {
                    emptyFlag = true;
                    msgStr = '装机容量不能为空';
                    return false;
                } else if (!icReg.test(may) && !icReg2.test(january)) {
                    emptyFlag = true;
                    msgStr = '装机容量仅支持两位小数，或 /';
                    return false;
                }
                var june = $(this).find(".layui-table").find(".june").val();
                if (isBlank(june)) {
                    emptyFlag = true;
                    msgStr = '装机容量不能为空';
                    return false;
                } else if (!icReg.test(june) && !icReg2.test(january)) {
                    emptyFlag = true;
                    msgStr = '装机容量仅支持两位小数，或 /';
                    return false;
                }
                var july = $(this).find(".layui-table").find(".july").val();
                if (isBlank(july)) {
                    emptyFlag = true;
                    msgStr = '装机容量不能为空';
                    return false;
                } else if (!icReg.test(july) && !icReg2.test(january)) {
                    emptyFlag = true;
                    msgStr = '装机容量仅支持两位小数，或 /';
                    return false;
                }
                var august = $(this).find(".layui-table").find(".august").val();
                if (isBlank(august)) {
                    emptyFlag = true;
                    msgStr = '装机容量不能为空';
                    return false;
                } else if (!icReg.test(august) && !icReg2.test(january)) {
                    emptyFlag = true;
                    msgStr = '装机容量仅支持两位小数，或 /';
                    return false;
                }
                var september = $(this).find(".layui-table").find(".september").val();
                if (isBlank(september)) {
                    emptyFlag = true;
                    msgStr = '装机容量不能为空';
                    return false;
                } else if (!icReg.test(september) && !icReg2.test(january)) {
                    emptyFlag = true;
                    msgStr = '装机容量仅支持两位小数，或 /';
                    return false;
                }
                var october = $(this).find(".layui-table").find(".october").val();
                if (isBlank(october)) {
                    emptyFlag = true;
                    msgStr = '装机容量不能为空';
                    return false;
                } else if (!icReg.test(october) && !icReg2.test(january)) {
                    emptyFlag = true;
                    msgStr = '装机容量仅支持两位小数，或 /';
                    return false;
                }
                var november = $(this).find(".layui-table").find(".november").val();
                if (isBlank(november)) {
                    emptyFlag = true;
                    msgStr = '装机容量不能为空';
                    return false;
                } else if (!icReg.test(november) && !icReg2.test(january)) {
                    emptyFlag = true;
                    msgStr = '装机容量仅支持两位小数，或 /';
                    return false;
                }
                var december = $(this).find(".layui-table").find(".december").val();
                if (isBlank(december)) {
                    emptyFlag = true;
                    msgStr = '装机容量不能为空';
                    return false;
                } else if (!icReg.test(december) && !icReg2.test(january)) {
                    emptyFlag = true;
                    msgStr = '装机容量仅支持两位小数，或 /';
                    return false;
                }
                var agent = {
                    "agentProvince":$(this).find(".agentProvince").val(),
                    "agentCity":$(this).find(".agentCity").val(),
                    "agentArea":$(this).find(".agentArea").val(),
                    "signFlowId":$(this).find(".signFlowId").val(),
                    "january":january,
                    "february":february,
                    "march":march,
                    "april":april,
                    "may":may,
                    "june":june,
                    "july":july,
                    "august":august,
                    "september":september,
                    "october":october,
                    "november":november,
                    "december":december
                }
                arr1.push(agent)
            })
            if (emptyFlag) {
                layer.msg(msgStr);
                return;
            }
            data.field.agentList = arr1;
            data.field.status=1;
            //data.field.qqProjectName=qqProjectName;
            console.log(postData)
             $.ajax({
                 url:'${ctx}/flowpath/traderApply/save?from=2',
                method:'post',
                contentType : "application/json;charsetset=UTF-8",
                data:JSON.stringify(postData),
                dataType:'JSON',
                success:function(res){
                    if(res.code=="200"){
                        parent.layer.msg("保存成功",{time:1000});
                        closeDiv();
                        parent.table.reload('test');
                    } else if(res.code=="501") {
                        layer.msg(res.errMsg,{time:1500});
                    } else if(res.code == '422'){
                        layer.msg(res.msg,{time:1500});
                    } else{
                        layer.msg("保存失败",{time:1000});
                    }
                },
                error:function (data) {
                }
            })
        });

        var uploadInst = upload.render({
            elem: '#uploader' //绑定元素
            , url: '${ctx}/common/uploadFile' //上传接口
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {

                });
            }
            , done: function (res) {
               /* imgs+=res.path+',';
                $("#imgs").val(imgs);*/
                //上传完毕回调
                addImg(res.path,"imgsDiv","licenseImg","uploader");
            }
            , error: function () {
                //请求异常回调
            }
        });



        upload.render({
            elem: '#qqjyglwtsImguploader' //绑定元素
            , url: '${ctx}/common/uploadFile' //上传接口
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                });
            }
            , done: function (res) {
                //上传完毕回调
                addImg(res.path,"qqjyglwtsImgDiv","qqjyglwtsImg","qqjyglwtsImguploader");
            }
            , error: function () {
                //请求异常回调
            }
        });

        upload.render({
            elem: '#bzjdkpzImguploader' //绑定元素
            , url: '${ctx}/common/uploadFile' //上传接口
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                });
            }
            , done: function (res) {
                //上传完毕回调
                addImg(res.path,"bzjdkpzImgDiv","bzjdkpzImg","bzjdkpzImguploader");
            }
            , error: function () {
                //请求异常回调
            }
        });

        upload.render({
            elem: '#sfzzmfyjImguploader' //绑定元素
            , url: '${ctx}/common/uploadFile' //上传接口
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                });
            }
            , done: function (res) {
                //上传完毕回调
                addImg(res.path,"sfzzmfyjImgDiv","sfzzmfyjImg","sfzzmfyjImguploader");
            }
            , error: function () {
                //请求异常回调
            }
        });

        upload.render({
            elem: '#sfzfmfyjImguploader' //绑定元素
            , url: '${ctx}/common/uploadFile' //上传接口
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                });
            }
            , done: function (res) {
                //上传完毕回调
                addImg(res.path,"sfzfmfyjImgDiv","sfzfmfyjImg","sfzfmfyjImguploader");
            }
            , error: function () {
                //请求异常回调
            }
        });

        upload.render({
            elem: '#dlszrsqbImguploader' //绑定元素
            , url: '${ctx}/common/uploadFile' //上传接口
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                });
            }
            , done: function (res) {
                //上传完毕回调
                addImg(res.path,"dlszrsqbImgDiv","dlszrsqbImg","dlszrsqbImguploader");
            }
            , error: function () {
                //请求异常回调
            }
        });

        var dlcoount =1;
        $(".addDaili").click(function(){
            dlcoount ++;
            $("#tb_table").append($(".copyfieldset").clone(true));
            $(this).prev().removeClass("hide");
            $(this).addClass("hide");
            $("#tb_table").find(".copyfieldset").find(".installedCapacity").attr("lay-verify","installedCapacity")
            $("#tb_table").find(".copyfieldset").removeClass("hide");
            $("#tb_table").find(".copyfieldset").removeClass("copyfieldset");
            form.render('select');
        });


        $(".deleteBut").click(function(){
            $(this).parents("fieldset").prev().find(".addDaili").removeClass("hide");
            $(this).parents("fieldset").remove();
        })
    })

    function takeDeliveryProvince(that,province,cityhtml,areahtml){
        $("#"+cityhtml).empty();
        var agentCity = '';
        var _thisCity = '';
        $.ajax({
            type: "POST",
            url: "${ctx}/main/redirect/getCitysByProId",
            data: {
                province: province
            },
            success: function (result) {
                if (result == "205") {
                    layer.msg("暂无数据!")
                    return
                }
                var html = "";
                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>';
                    if (i==0) {
                        agentCity = city.columns.CityID;
                    }
                }
                if("agentCity"==cityhtml){
                    that.parents("fieldset").find("."+cityhtml).append(html);
                    _thisCity = that.parents("fieldset").find("."+cityhtml);
                }else{
                    $("#"+cityhtml).append(html);
                }
                form.render('select');
            },
            complete: function () {
                var city = $("#city").find("option:selected").attr("title");
                if("agentArea"==areahtml){
                    city = agentCity;
                    _thisCity.parents("fieldset").find("."+areahtml).empty()
                }else{
                    $("#"+areahtml).empty()
                }
                if (isBlank(city)) {
                    $("#"+areahtml).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 = "";
                        for (var i = 0; i < result.length; i++) {
                            var area = result[i];
                            html = html + '<option value="' + area.columns.DistrictName + '" >' + area.columns.DistrictName + '</option>';
                        }
                        if("agentArea"==areahtml){
                            _thisCity.parents("fieldset").find("."+areahtml).append(html);
                        }else{
                            $("#"+areahtml).append(html);
                        }

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

        });
    }

    function cityHtml(that,city,areahtml){
        $.ajax({
            type: "POST",
            url: "${ctx}/main/redirect/getAreaByCityId",
            data: {
                city: city
            },
            success: function (result) {
                if (result == "205") {
                    layer.msg("暂无数据!")
                    return
                }
                var html = "";
                for (var i = 0; i < result.length; i++) {
                    var area = result[i];
                    html = html + '<option value="' + area.columns.DistrictName + '" >' + area.columns.DistrictName + '</option>';
                }
                if("agentArea"==areahtml){
                    that.parents("fieldset").find("."+areahtml).append(html);
                }else{
                    $("#"+areahtml).append(html);
                }
                form.render('select');
            }
        });
    }


    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;
    }

    function addImg(data,imgshtml,imgs,uploader){

        $("#"+uploader).hide();
        var html = '<div class="bj-img imgSpan"><span class="layui-icon-close layui-icon" onclick="delImg(this,\''+uploader+'\',\''+imgs+'\')"></span>';
        html += '<img src="${commonStaticImgPath}'+data+'" height="700" width="1200"/>';
        html += '<input type="hidden" class="imgPicker" value="'+data+'"/> </div>';
        $("#"+imgshtml).append(html);
        console.log(data);
        $("#"+imgs).val(data);
    }

    function delImg(that,uploader,imgs){
       $("#"+uploader).show();
        $(that).parent().remove();
     /*   var imgSelector = $(".imgPicker");
        imgSelector.each(function (index) {
            var img = $(this).val();
            if (!isBlank(img)) {
                imgs += img + ",";
            }
        });*/
        $("#"+imgs).val('');
    }

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