<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE HTML>
<html>
<head>
  <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">
  <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/dist/viewer.css" media="all">
  <style>
    html {
      background-color: #fff;
      padding-bottom: 50px;
    }

    .bj-img {
      margin-right: 0px;
    }
    .bj-img > span{
      z-index: 1;
    }
    .lookBtn{
      color: #2890ac;
      width: 10px;
      padding: 11px;
    }
    .bj-img{width: 80px;
      height: 80px;
      border: 1px solid #ddd;
      float: inherit;
      margin-right: 10px;
      display: inline-block;
      position: relative;
    }
    .layui-radio-disbaled > i {
      color: #000000 !important;
    }
  </style>
</head>
<body>
<div class="layui-form ">
  <div class="layui-card">
    <div class="layui-card-body layui-col-xs12" id="LAY_app">
      <div class="layui-card ">
        <blockquote class="layui-elem-quote">业主信息</blockquote>
        <div class="layui-card-body">
          <div class="layui-row layui-col-space12 layui-form-item">
            <div class="layui-col-lg3 layui-col-sm3">
              <label class="layui-form-label"><i class="mark">*</i>客户类型：</label>
              <div class="layui-input-block">
                <select name="tenantType" id="tenantType" lay-filter="tenantType" lay-verify="tenantType"
                        class="layui-bg-gray layui-disabled" disabled>
                  <option value="1" <c:if test="${entry.columns.tenant_type eq '1'}">selected</c:if>>个人</option>
                  <option value="2" <c:if test="${entry.columns.tenant_type eq '2'}">selected</c:if>>单位</option>
                </select>
              </div>
            </div>
          </div>
          <div class="<c:if test="${entry.columns.tenant_type eq '2'}">hide</c:if>" id="individual">
            <div class="layui-row layui-col-space12 layui-form-item">

                <div class="layui-col-lg4 layui-col-sm4">
                  <label class="layui-form-label"><i class="mark">*</i>身份证：</label>
                  <div class="layui-input-block img-box">
                    <div>
                      <div id="imgsDiv1">
                        <c:if test="${not empty entry.columns.id_card_front}">
                          <div class="bj-img imgSpan">
                            <span class="layui-icon-close layui-icon" onclick="delImg(this,'uploader1')"></span>
                            <img src="${entry.columns.id_card_front}" height="700" width="1200"/>
                            <input type="hidden" class="idCardFront" value="${entry.columns.id_card_front}"/>
                          </div>
                        </c:if>
                      </div>
                      <div class="upload-container <c:if test="${not empty entry.columns.id_card_front}">hide</c:if>" id="uploader1">
                        <img src="" alt="img placeholder" id="imgsAdd1">
                      </div>
                      <div style="width: 80px; text-align: center; color: #FF0000">正面</div>
                    </div>
                    <div>
                      <div id="imgsDiv2">
                        <c:if test="${not empty entry.columns.id_card_back}">
                          <div class="bj-img imgSpan">
                            <span class="layui-icon-close layui-icon" onclick="delImg(this,'uploader2')"></span>
                            <img src="${entry.columns.id_card_back}" height="700" width="1200"/>
                            <input type="hidden" class="idCardBack" value="${entry.columns.id_card_back}"/>
                          </div>
                        </c:if>
                      </div>
                      <div class="upload-container <c:if test="${not empty entry.columns.id_card_back}">hide</c:if>" id="uploader2">
                        <img src="" alt="img placeholder" id="imgsAdd2">
                      </div>
                      <div style="width: 80px; text-align: center; color: #FF0000">反面</div>
                    </div>
                  </div>
                </div>
                <div class="layui-col-lg3 layui-col-sm3">
                  <label class="layui-form-label"><i class="mark">*</i>业主姓名：</label>
                  <div class="layui-input-block">
                    <input type="text" name="tenantName" class="layui-input" disabled value="${entry.columns.tenant_name}">
                  </div>
                </div>
                <div class="layui-col-lg3 layui-col-sm3">
                  <label class="layui-form-label"><i class="mark">*</i>性别：</label>
                  <div class="layui-input-block">
                    <input type="radio" name="gender" disabled title="男"
                           value="MALE" ${entry.columns.gender eq 'MALE' ? 'checked' : ''}/>
                    <input type="radio" name="gender" disabled title="女"
                           value="FEMALE" ${entry.columns.gender eq 'FEMALE' ? 'checked' : ''}/>
                  </div>
                </div>
                <div class="layui-col-lg3 layui-col-sm3">
                  <div>
                    <label class="layui-form-label"><i class="mark">*</i>年龄：</label>
                    <div class="layui-input-block">
                      <input type="text" lay-filter="age" disabled onkeyup="change()" name="age" id="age"
                             class="layui-input age" value="${entry.columns.age}">
                    </div>
                  </div>
                </div>
                <div class="layui-col-lg3 layui-col-sm3" style="position:relative;">
                  <div>
                    <label class="layui-form-label"><i class="mark">*</i>联系电话：</label>
                    <div class="layui-input-block">
                      <input type="text" name="mobile"
                             class="layui-input" value="${entry.columns.mobile}">
                    </div>
                  </div>
                </div>
                <div class="layui-col-lg3 layui-col-sm3">
                  <label class="layui-form-label"><i class="mark">*</i>身份证号：</label>
                  <div class="layui-input-block">
                    <input type="text" name="idCode" disabled class="layui-input" value="${entry.columns.id_code}">
                  </div>
                </div>
                <div class="layui-col-lg9 layui-col-sm9">
                  <label class="layui-form-label"><i class="mark">*</i>安装地址：</label>
                  <div class="layui-input-block">
                    <div class="layui-col-lg2 layui-col-sm2 pr-10">
                      <select name="province" id="province" lay-verify="required"
                              lay-filter="province" lay-search>
                        <option value="">请选择省</option>
                        <c:forEach items="${pros}" var="pro">
                          <option value="${pro.columns.ProvinceName}"
                                  title="${pro.columns.ProvinceID}" rel="${pro.columns.traderId}"
                                  <c:if test="${entry.columns.province eq pro.columns.ProvinceName}">selected</c:if>>${pro.columns.ProvinceName}</option>
                        </c:forEach>
                      </select>
                    </div>
                    <div class="layui-col-lg2 layui-col-sm2 pr-10">
                      <select name="city" id="city" lay-verify="required" lay-filter="city"
                              lay-search>
                        <option value="">请选择市</option>
                        <c:forEach items="${faccitys}" var="cit">
                          <option value="${cit.columns.CityName}"
                                  title="${cit.columns.CityID}" rel="${cit.columns.traderId}"
                                  <c:if test="${entry.columns.city eq cit.columns.CityName}">selected</c:if>>${cit.columns.CityName}</option>
                        </c:forEach>
                      </select>
                    </div>
                    <div class="layui-col-lg2 layui-col-sm2 pr-10">
                      <select name="area" id="area" lay-verify="required" lay-filter="area" lay-search>
                        <option value="">请选择县/区</option>
                        <c:forEach items="${areas}" var="ar">
                          <option value="${ar.columns.DistrictName}"
                                  title="${ar.columns.DistrictID}"
                                  <c:if test="${entry.columns.area eq ar.columns.DistrictName}">selected</c:if>>${ar.columns.DistrictName}</option>
                        </c:forEach>
                      </select>
                    </div>
                    <div class="layui-col-lg6 layui-col-sm6">
                      <div class="layui-inline">
                        <input type="text" name="customerAddress" lay-verify="required"
                               autocomplete="off" class="layui-input layui-col-lg2 "
                               value="${entry.columns.address}">
                      </div>
                    </div>
                  </div>
                </div>
            </div>
            <div class="layui-row layui-col-space12 layui-form-item">
                <div class="layui-col-lg3 layui-col-sm3">
                  <label class="layui-form-label"><i class="mark">*</i>账户名称：</label>
                  <div class="layui-input-block">
                    <input type="text" name="bankName" id="bankName" lay-verify="required"
                           class="layui-input" value="${entry.columns.bank_name}">
                  </div>
                </div>
                <div class="layui-col-lg3 layui-col-sm3">
                  <label class="layui-form-label"><i class="mark">*</i>银行账号：</label>
                  <div class="layui-input-block">
                    <input type="text" name="bankCode" id="bankCode" lay-verify="required"
                           class="layui-input" value="${entry.columns.bank_code}">
                  </div>
                </div>

              <c:if test="${info.columns.tss_bank_num_name.columnType eq '1'}">
                <c:if test="${info.columns.tss_bank_num_name.status eq '1'}">
                  <div class="layui-col-lg4 layui-col-sm4">
                    <label class="layui-form-label"><c:if test="${info.columns.tss_bank_num_name.mustFillFlag eq '1'}"><i class="mark">*</i></c:if>开户行：</label>
                    <div class="layui-input-block">
                      <div id="tssBank"></div>
                    </div>
                  </div>
                </c:if>
              </c:if>
              <c:if test="${info.columns.tss_bank_num_name.columnType eq '2'}">
                <c:if test="${info.columns.tss_bank_num_name.status eq '1'}">
                  <div class="layui-col-lg4 layui-col-sm4">
                    <label class="layui-form-label"><c:if test="${info.columns.tss_bank_num_name.mustFillFlag eq '1'}"><i class="mark">*</i></c:if>开户行：</label>
                    <div class="layui-input-block">
                      <input type="text" name="tssBank" id="tssBank" lay-verify="required"
                             autocomplete="off" class="layui-input " value="${entry.columns.tssBankNumName}">
                    </div>
                  </div>
                </c:if>
              </c:if>
            </div>
            <div class="layui-row layui-col-space12 layui-form-item">
                <div class="layui-col-lg4 layui-col-sm4">
                  <label class="layui-form-label"><i class="mark">*</i>银行卡照片：</label>
                  <div class="layui-input-block img-box">
                    <div>
                      <div id="imgsDiv4">
                        <c:if test="${not empty entry.columns.bank_card}">
                          <div class="bj-img imgSpan">
                            <span class="layui-icon-close layui-icon" onclick="delImg(this,'uploader4')"></span>
                            <img src="${entry.columns.bank_card}" height="700" width="1200"/>
                            <input type="hidden" class="bankCard" value="${entry.columns.bank_card}"/>
                          </div>
                        </c:if>
                      </div>
                      <div class="upload-container <c:if test="${not empty entry.columns.bank_card}">hide</c:if>" id="uploader4">
                        <img src="" alt="img placeholder" id="imgsAdd4">
                      </div>
                    </div>
                  </div>
                </div>
                <div class="layui-col-lg4 layui-col-sm4">
                  <label class="layui-form-label w-120"><i class="mark">*</i>户口本复印件：</label>
                  <div class="layui-input-block img-box ml-120">
                    <div style="display: flex;flex-wrap: wrap;">
                      <div id="imgsDiv3">
                        <c:if test="${not empty entry.columns.residence_booklet}">
                          <c:forEach var="quaim" items="${entry.columns.residence_booklet.split(',')}" varStatus="vs">
                            <div class="bj-img imgSpan">
                              <span class="layui-icon-close layui-icon" onclick="delImg(this,'uploader3')"></span>
                              <img src="${quaim}" height="700" width="1200"/>
                              <input type="hidden" class="residenceBooklet" value="${quaim}"/>
                            </div>
                          </c:forEach>
                        </c:if>
                      </div>
                      <div class="upload-container <c:if test="${not empty entry.columns.residenceBooklet}">hide</c:if>" id="uploader3">
                        <img src="" alt="img placeholder" id="imgsAdd3">
                      </div>
                    </div>
                  </div>
                </div>
            </div>
              <div class="layui-row layui-col-space12 layui-form-item">
                <div class="layui-col-lg11 layui-col-sm11">
                  <label class="layui-form-label"><i class="mark">*</i>房产证明：</label>
                  <div class="layui-input-block img-box">
                    <div style="display: flex">
                      <div id="imgsDiv5">
                        <c:set var="houseOwnershipCount" value="0"/>
                        <c:if test="${not empty surveyRecord.columns.houseOwnership}">
                          <c:forEach var="quaim" items="${surveyRecord.columns.houseOwnership.split(',')}" varStatus="vs">
                            <div class="bj-img imgSpan">
                              <span class="layui-icon-close layui-icon" onclick="delImg(this,'uploader5')"></span>
                              <img src="${quaim}" height="700" width="1200"/>
                              <input type="hidden" class="houseOwnership" value="${quaim}"/>
                            </div>
                            <c:set var="houseOwnershipCount" value="${vs.count}"/>
                          </c:forEach>
                        </c:if>
                      </div>
                      <div class="upload-container <c:if test="${houseOwnershipCount >= 8}">hide</c:if> "  id="uploader5">
                        <img src="" alt="img placeholder" id="imgsAdd5">
                      </div>
                    </div>
                  </div>
                </div>
              </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="operate-footer">
    <button type="button" class="layui-btn saveOrder">保存</button>
    <button type="button" class="layui-btn layui-btn-primary" onclick="cancel()">取消</button>
  </div>
</div>


<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/dist/viewer.js"></script>
<script src="${ctxPlugin}/lib/xm-select.js"></script>
<script>
  //图片查看效果
  var viewer = new Viewer(document.getElementById('LAY_app'));
  var number = /^[1-9]\d*$/;//非0正整数正则
  var assemblyOptionHtml = '';// 组件下拉选html
  var inverterOptionHtml = '';// 逆变器下拉选html
  var gridConnectionOptionHtml = '';// 并网箱下拉选html
  var supportOptionHtml = '';// 支架下拉选html

  // 联行号
  var tssBankNum = '${entry.columns.tssBankNum}';
  // 银行名称
  var tssBankNumName = '${entry.columns.tssBankNumName}';
  // 联行号
  var tssBankNumAnother = '${entry.columns.tssBankNum}';
  // 银行名称
  var tssBankNumNameAnother = '${entry.columns.tssBankNumName}';
  layui.config({
    base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'form', 'layedit', 'laydate', 'jquery', 'upload', 'layer'], function () {
    $ = layui.$
            , element = layui.element
            , form = layui.form
            , layer = layui.layer
            , laydate = layui.laydate;
    var upload = layui.upload;

    //执行实例
    upload.render({
      elem: '#uploader1' //绑定元素
      , url: '${ctx}/common/weChat/uploadImageIden' //上传接口
      , before: function (obj) {
        //预读本地文件示例，不支持ie8
        obj.preview(function (index, file, result) {
        });
      }
      , done: function (res) {
        var obj =  JSON.parse(res.info)
        if (obj.code ==='500'){
          layer.msg("身份信息上传失败,请确认后重试", {icon: 2});
          return;
        }
        var data = obj.data.face.data;
        console.log("data",data);
        $("#tenantName").val(data.name);
        $("#bankName").val(data.name);
        var age = getAge(data.idNumber);
        if(!isBlank(${partner.failCreateAge}) && age>${partner.failCreateAge}){
          layer.msg("年龄大于${partner.failCreateAge}岁，不能建站！", {icon: 2});
          return;
        }
        $("#age").val(age);
        $("#idCode").val(data.idNumber);
        let tenantType = $("#tenantType").val();
        //上传完毕回调
        addImg(res.path, "uploader1", "imgsDiv1", "idCardFront");
        console.log(res.name)
      }
      , error: function () {
        //请求异常回调
      }
    });

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

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

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

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

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

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

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

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

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

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

    function addImg(data, id, imgsDiv, classimg) {
      $("#" + id).hide();
      var html = '<div class="bj-img imgSpan"><span class="layui-icon-close layui-icon" onclick="delImg(this,\'' + id + '\')"></span>';
      html += '<img src="${commonStaticImgPath}' + data + '" height="700" width="1200"/>';
      html += '<input type="hidden" class="' + classimg + '" value="' + data + '"/> </div>';
      $("#" + imgsDiv).append(html);
      //图片查看效果
      viewer.update();
    }

    function addImgTwo(data, id, imgsDiv, classimg,count) {
      var imgCount=$("#" + imgsDiv).find(".imgSpan").length;
      if((imgCount+1)>=count){
        $("#" + id).hide();
      }
      var html = '<div class="bj-img imgSpan"><span class="layui-icon-close layui-icon" onclick="delImg(this,\'' + id + '\')"></span>';
      html += '<img src="${commonStaticImgPath}' + data + '" height="700" width="1200"/>';
      html += '<input type="hidden" class="' + classimg + '" value="' + data + '"/> </div>';
      $("#" + imgsDiv).append(html);
      //图片查看效果
      viewer.update();
    }

    //日期
    laydate.render({
      elem: '#applianceBuyTime'
      , trigger: 'click'
    });
    //预约时间
    laydate.render({
      elem: '#promiseTime'
      , trigger: 'click'
    });
    laydate.render({
      elem: '#repairTime'
      , value: '${data}'
      , type: 'datetime'
      , trigger: 'click'
    });
    form.render(null, 'component-form-element');
    //自定义验证规则
    form.verify({
      title: function (value) {
        if (value.length < 5) {
          return '标题至少得5个字符啊';
        }
      }
      , pass: [
        /^[\S]{6,12}$/
        , '密码必须6到12位，且不能出现空格'
      ]
      , recevierMobile: [/^((0\d{2,3}-\d{7,8})|([1][3,4,5,7,8,8,9][0-9]{9}))$/
        , '请输入正确格式的联系电话！'
      ]
      , content: function (value) {
        layedit.sync(editIndex);
      }
    });

    form.on('select(tenantType)', function (data) {
      let type = $(data.elem).find("option:selected").val();
      console.log(type)
      if (type === "2") {
        $("#individual").addClass("hide");
        $("#workplace").removeClass("hide");
      } else {
        $("#workplace").addClass("hide");
        $("#individual").removeClass("hide");
      }
    })

    form.on('select(projectChange)', function (data) {
      let value = $(data.elem).find("option:selected").val();
      $("#projectCode input").val('');
      $("#payCycle input").val('');
      $("#filingType input").val('');
      //添加业务属性
      $('#ywAttribute input').val('');
      // 清空下拉列表
      // $('#projectCompany').empty();
      form.render('select')
      console.log(value)
      $.ajax({
        type: "GET",
        url: "${ctx}/customerEntry/getProjectInfoById",
        data: {
          projectId: value,
        },
        success: function (result) {
          console.log(result);
          var data = result.data
          if (data != null){
            // 将产品编号设置到目标元素中
            $("#projectCode input").val(data.code);
            //添加备案类型
            if(data.payCycle === '1'){
              $("#payCycle input").val("按月支付");
            }else if(data.payCycle === '2'){
              $("#payCycle input").val("按季支付");
            }else {
              $("#payCycle input").val("按年支付");
            }
            //添加备案类型

            if (data.filingType === '1'){
              $("#filingType input").val("农户备案");
            }else {
              $("#filingType input").val("项目公司备案");
            }
          }

          $.ajax({
            type: "GET",
            url: "${ctx}/customerEntry/getProductLineAttribute",
            data: {
              id: data.productLineId,
            },
            success: function (result1) {
              var val = result1.data
              console.log(val)
              $("#ywAttribute input").val(val);
            }
          })

          //添加项目公司
          <%--$.ajax({--%>
          <%--    type: "GET",--%>
          <%--    url: "${ctx}/customerEntry/getProjectInfo",--%>
          <%--    data: {--%>
          <%--        projectId: value--%>
          <%--    },--%>
          <%--    success: function (result1) {--%>
          <%--        var projectCompanySelect = $("#projectCompany");--%>
          <%--        projectCompanySelect.append('<option value="">请选择项目公司:</option>');--%>
          <%--        var companies = result1.data--%>
          <%--        console.log("companies",companies)--%>
          <%--        // 添加默认选项--%>
          <%--        if (companies.length>0){--%>
          <%--            // 遍历公司信息并添加到下拉列表中--%>
          <%--            for (var i = 0; i < companies.length; i++) {--%>
          <%--                var company = companies[i];--%>
          <%--                projectCompanySelect.append('<option value="' + company.columns.id + '">' + company.columns.name + '</option>');--%>
          <%--            }--%>
          <%--        }--%>
          <%--        // 重新渲染 layui form--%>
          <%--        form.render('select');--%>
          <%--    }--%>
          <%--})--%>

        }
      });

    })

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

    form.on('select(area)', function (data) {
      var area = $(data.elem).find("option:selected").val();
      if (!isBlank(area)){
        getProjectByArea();
      }
      checkSelection();
    });

    form.on('select(provinceAnother)', function (data) {
      let traderId = $(data.elem).find("option:selected").attr("rel");
      let province = $(data.elem).find("option:selected").attr("title");
      provinceOrderAnother(traderId, province);
      checkSelection();
    });

    form.on('select(cityAnother)', function (data) {
      let traderId = $(data.elem).find("option:selected").attr("rel");
      let city = $(data.elem).find("option:selected").attr("title");
      cityOrderAnother(traderId, city);
      checkSelection();
    });

    form.on('select(areaAnother)', function (data) {
      let area = $(data.elem).find("option:selected").val();//区
      if (!isBlank(area)){
        getProjectByArea()
      }
      checkSelection();
    });

    function provinceOrder(traderId, province) {
      $("#city").empty();
      $("#area").empty();
      $("#projectCompany").empty()
      $("#projectCompany").append("<option value=''>请先选择安装地址</option>");
      //产品
      $("#projectList").empty()
      $("#projectList").append("<option value=''>请先选择安装地址</option>");
      $("#projectCode input").val("");
      $("#payCycle input").val("");
      $("#filingType input").val("");
      $("#ywAttribute input").val("");
      if (isBlank(province)) {
        $("#city").append("<option value=''>请选择</option>");
        document.getElementById('projectCompany').disabled = true;
        form.render('select');
        return "";
      }
      $.ajax({
        type: "POST",
        url: "${ctx}/main/redirect/getCityListByTraderId",
        data: {
          traderId: traderId,
          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 + '" rel="' + city.columns.traderId + '">' + city.columns.CityName + '</option>';
          }
          $("#city").append(html);
          form.render('select');
        }
      });

    }

    function cityOrder(traderId, city) {
      $("#area").empty()
      $("#projectCompany").empty();
      $("#projectCompany").append("<option value=''>请先选择安装地址</option>");
      //产品
      $("#projectList").empty()
      $("#projectList").append("<option value=''>请先选择安装地址</option>");
      $("#projectCode input").val("");
      $("#payCycle input").val("");
      $("#filingType input").val("");
      $("#ywAttribute input").val("");
      if (isBlank(city)) {
        $("#area").append("<option value=''>请选择</option>");
        document.getElementById('projectCompany').disabled = true;
        form.render('select');
        return "";
      }
      $.ajax({
        type: "POST",
        url: "${ctx}/main/redirect/getAreaListByTraderId",
        data: {
          traderId: traderId,
          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 + '" >' + area.columns.DistrictName + '</option>';
          }
          $("#area").append(html);
          // if (!isBlank(arean)) {
          //     $("#area").val(arean)
          // }

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

    }

    function areaOrder(){
      let province = $("#province").find("option:selected").val();//省
      let city = $("#city").find("option:selected").val();//市
      let area = $("#area").find("option:selected").val();//区
      //添加项目公司
      $.ajax({
        type: "GET",
        url: "${ctx}/customerEntry/getCompanyByArea",
        data: {
          province:province,
          city:city,
          area:area,
          partner:`${partner.id}`
        },
        success: function (result1) {
          var companies = result1.data
          var projectCompanySelect = $("#projectCompany");

          // 清空下拉列表
          projectCompanySelect.empty();

          // 添加默认选项
          projectCompanySelect.append('<option value="">请选择项目公司:</option>');
          if (companies.length>0){
            // 遍历公司信息并添加到下拉列表中
            for (var i = 0; i < companies.length; i++) {
              var company = companies[i];
              projectCompanySelect.append('<option value="' + company.columns.id + '">' + company.columns.name + '</option>');
            }
          }
          // 重新渲染 layui form
          form.render('select');
        }
      })

    }
    function getProjectByArea() {
      let tenantType = $("#tenantType").val();
      let province = $("#province").find("option:selected").val();//省
      let city = $("#city").find("option:selected").val();//市
      let area = $("#area").find("option:selected").val();//区
      if (tenantType === "2") {
        province = $("#provinceAnother").find("option:selected").val();//省
        city = $("#cityAnother").find("option:selected").val();//市
        area = $("#areaAnother").find("option:selected").val();//区
      }
      var projectCompany = $("#projectCompany");
      projectCompany.empty()
      form.render('select');
      $.ajax({
        type: "POST",
        url: "${ctx}/customerEntry/getProjectByArea",
        data: {
          traderId: `${traderId}`,
          type: tenantType,
          province:province,
          city:city,
          area:area,
          partner: `${partner.id}`
        },
        success: function (result) {
          var projectList = $("#projectList");
          projectList.empty();
          if (typeof result.data !== 'undefined') {
            var data = result.data
            projectList.append('<option value="">请选择产品:</option>');
            for (var i = 0; i < data.length; i++) {
              var city = data[i];
              projectList.append('<option value="' + city.columns.id + '" title="' + city.columns.name + '" rel="' + city.columns.id + '">' + city.columns.name + '</option>');
            }
          }
          form.render('select');
        }
      });
      //添加项目公司
      $.ajax({
        type: "GET",
        url: "${ctx}/customerEntry/getCompanyByArea",
        data: {
          province:province,
          city:city,
          area:area,
          partner:`${partner.id}`
        },
        success: function (result1) {
          var companies = result1.data
          var projectCompanySelect = $("#projectCompany");

          // 清空下拉列表
          projectCompanySelect.empty();

          // 添加默认选项
          projectCompanySelect.append('<option value="">请选择项目公司:</option>');
          if (companies.length>0){
            // 遍历公司信息并添加到下拉列表中
            for (var i = 0; i < companies.length; i++) {
              var company = companies[i];
              projectCompanySelect.append('<option value="' + company.columns.id + '">' + company.columns.name + '</option>');
            }
          }
          // 重新渲染 layui form
          form.render('select');
        }
      })
    }

    function provinceOrderAnother(traderId, province) {
      $("#cityAnother").empty();
      $("#areaAnother").empty();
      $("#projectCompany").empty();
      $("#projectCompany").append("<option value=''>请先选择安装地址</option>");
      //产品
      $("#projectList").empty()
      $("#projectList").append("<option value=''>请先选择安装地址</option>");
      $("#projectCode input").val("");
      $("#payCycle input").val("");
      $("#filingType input").val("");
      $("#ywAttribute input").val("");
      if (isBlank(province)) {
        $("#cityAnother").append("<option value=''>请选择</option>");
        document.getElementById('projectCompany').disabled = true;
        form.render('select');
        return "";
      }
      $.ajax({
        type: "POST",
        url: "${ctx}/main/redirect/getCityListByTraderId",
        data: {
          traderId: traderId,
          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 + '" rel="' + city.columns.traderId + '">' + city.columns.CityName + '</option>';
          }
          $("#cityAnother").append(html);
          form.render('select');
        }
      });
    }

    function cityOrderAnother(traderId, city, arean) {
      $("#areaAnother").empty()
      $("#projectCompany").empty()
      $("#projectCompany").append("<option value=''>请先选择安装地址</option>");
      //产品
      $("#projectList").empty()
      $("#projectList").append("<option value=''>请先选择安装地址</option>");
      $("#projectCode input").val("");
      $("#payCycle input").val("");
      $("#filingType input").val("");
      $("#ywAttribute input").val("");
      if (isBlank(city)) {
        $("#areaAnother").append("<option value=''>请选择</option>");
        document.getElementById('projectCompany').disabled = true;
        form.render('select');
        return "";
      }
      $.ajax({
        type: "POST",
        url: "${ctx}/main/redirect/getAreaListByTraderId",
        data: {
          traderId: traderId,
          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 + '" >' + area.columns.DistrictName + '</option>';
          }
          $("#areaAnother").append(html);
          if (!isBlank(arean)) {
            $("#areaAnother").val(arean)
          }
          form.render('select');
        }
      });
    }
    $(".saveOrder").click(function () {
      submitEntry('1');
    })

    var saveFlag = false;
    function submitEntry(type) {
      if (saveFlag) {
        return;
      }
      // 客户类型
      let tenantType = $("#tenantType").val();
      let tenantName = $("input[name=tenantName]").val();;//业主姓名
      let mobile = $("input[name=mobile]").val();//联系方式
      let idCode = $("input[name=idCode]").val();//身份证号
      let province = $("#province").find("option:selected").val();//省
      let city = $("#city").find("option:selected").val();//市
      let area = $("#area").find("option:selected").val();//区
      let address = $("input[name=customerAddress]").val();//用户地址
      let idCardFront = $('.idCardFront').val();//身份证正面
      let idCardBack = $('.idCardBack').val();//身份证反面
      let bankName = $("#bankName").val(); //开户银行
      let bankCode = $("#bankCode").val(); //银行账号
      let bankCard=$(".bankCard").val(); //银行卡照片
      let exigenceName = $("#exigenceName").val();//紧急联系人
      let exigencePhone = $("#exigencePhone").val();//紧急联系人电话
      let bankNum = tssBankNum;
      let bankNumName = tssBankNumName;
      <c:if test="${info.columns.tss_bank_num_name.columnType eq '2'}">
      bankNumName = $("#tssBank").val();
      </c:if>
      let company=$("#projectCompany").find("option:selected").val(); //项目公司
      let projectList=$("#projectList").find("option:selected").val(); //产品信息

      if (tenantType === "2") {
        let company=$("#projectCompany").find("option:selected").val(); //项目公司
        tenantName = $("input[name=tenantNameAnother]").val();
        mobile = $("input[name=mobileAnother]").val();
        idCode = $("input[name=idCodeAnother]").val();
        province = $("#provinceAnother").find("option:selected").val();//省
        city = $("#cityAnother").find("option:selected").val();//市
        area = $("#areaAnother").find("option:selected").val();//区
        address = $("input[name=customerAddressAnother]").val();//用户地址
        idCardFront = $('.idCardFrontAnother').val();//身份证正面
        idCardBack = $('.idCardBackAnother').val();//身份证反面
        bankName = $("#bankNameAnother").val(); //开户银行
        bankCode = $("#bankCodeAnother").val(); //银行账号
        bankCard = $(".bankCardAnother").val(); //银行卡照片
        bankNum = tssBankNumAnother;
        bankNumName = tssBankNumNameAnother;
        <c:if test="${info.columns.tss_bank_num_name.columnType eq '2'}">
        bankNumName = $("#tssBankAnother").val();
        </c:if>
      }
      let age=$("input[name='age']").val(); //年龄
      let gender=$("input[name='gender']:checked").val(); //性别
      let residenceBooklet;//户口本复印件
      $(".residenceBooklet").each(function () {
        if (isBlank(residenceBooklet)) {
          residenceBooklet = $(this).val();
        } else {
          residenceBooklet = residenceBooklet + "," + $(this).val();
        }
      });
      let houseOwnership;//房产证
      $(".houseOwnership").each(function () {
        if (isBlank(houseOwnership)) {
          houseOwnership = $(this).val();
        } else {
          houseOwnership = houseOwnership + "," + $(this).val();
        }
      });
      let creditCertificate;//信誉凭证
      $(".creditCertificate").each(function () {
        if (isBlank(creditCertificate)) {
          creditCertificate = $(this).val();
        } else {
          creditCertificate = creditCertificate + "," + $(this).val();
        }
      });

      let bpName = $('#bpName').val();//共签人名称
      let bpRelation = $("#bpRelation").find("option:selected").val();//共签人与业主关系
      let bpIdCard = $('#bpIdCard').val();//共签人证件号码
      let bpMobile = $('#bpMobile').val();//共签人手机号
      let bpCardFront = $('.bpCardFront').val();//共签人身份证正面
      let bpCardBack = $('.bpCardBack').val();//共签人身份证反面
      let bpFile ;//共签人子女证明材料

      $(".bpFile").each(function () {
        if (isBlank(bpFile)) {
          bpFile = $(this).val();
        } else {
          bpFile = bpFile + "," + $(this).val();
        }
      });
      let regnoUrl = $('.regnoUrl').val();//营业执照
      let regno = $('#regno').val();// 信用代码
      let corp = $('#corp').val();// 负责人姓名

      var order = {
        id: '${entry.columns.id}',
        projectId: projectList,
        tenantName: tenantName,
        mobile: mobile,
        idCode: idCode,
        province: province,
        city: city,
        area: area,
        address: address,
        age:age,
        gender:gender,
        bankName: bankName,
        bankCode: bankCode,
        tssBankNum: bankNum,
        idCardFront: idCardFront,
        idCardBack: idCardBack,
        residenceBooklet: residenceBooklet,
        bankCard: bankCard,
        bpName: bpName,
        bpRelation:bpRelation,
        bpIdCard: bpIdCard,
        bpMobile: bpMobile,
        bpCardFront: bpCardFront,
        bpCardBack: bpCardBack,
        bpFile: bpFile,
        type: type,
        tssBankNumName: bankNumName,
        tenantType: tenantType,
        regnoUrl: regnoUrl,
        regno: regno,
        corp: corp,
        company:company,
        exigenceName:exigenceName,
        exigencePhone:exigencePhone,
        houseOwnership:houseOwnership,
        creditCertificate:creditCertificate
      };
      saveFlag = true;
      savetemFlag = true;
      console.log(JSON.stringify(order))
      $.ajax({
        url: "${ctx}/customerEntry/saveCustomerEntry",
        type: "POST",
        contentType: "application/json;charsetset=UTF-8",
        data: JSON.stringify(order)
        , success: function (result) {
          if (result.code === '200') {
            var index = parent.layer.getFrameIndex(window.name);
            layer.msg("保存成功", {icon: 1, time: 1000}, function () {
              parent.layer.close(index);
              parent.table.reload('test');
            })
          } else {
            layer.msg(result.errMsg, {icon: 2});
          }
          saveFlag = false;
          savetemFlag = false;

        }, error: function () {
          layer.msg("保存失败", {icon: 2});
          saveFlag = false;
          savetemFlag = false;
        }
      })
    }

    //取消
    $(".cancelorder").click(function () {
      parent.layer.closeAll();
      parent.searchOrder();

    })

    // 验证手机号
    function isPhoneNo(phone) {
      // var tel = /(^1\d{10}$)|(^(\d{3,4}\-)?\d{5,9}$)/;包含座机号
      var tel = /^1[3|4|5|6|7|8|9][0-9]{9}$/;
      return tel.test($.trim(phone));
    }

    function IsCard(str) {
      var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
      return reg.test(str);
    }

    function isNumber(value) {
      var z_reg = /^(([0-9])|([1-9]([0-9]+)))(.[0-9]+)?$/;
      return z_reg.test(value);
    };

    let initBankData = [];
    if (!isBlank(tssBankNumName) && !isBlank(tssBankNum)) {
      initBankData = [{name: tssBankNumName, value: tssBankNum, selected: true}];
    }
    <c:if test="${info.columns.tss_bank_num_name.columnType eq '1'}">
    var tssBankXm = xmSelect.render({
      el: '#tssBank',
      name: 'tssBank',
      radio: true,
      tips: '请输入查询',
      size: 'mini',
      style: {
        height: '30px',
      },
      paging: true,
      pageSize: 6,
      data: initBankData,
      clickClose: true,
      filterable: true,
      remoteSearch: true,
      remoteMethod: function (val, cb, show) {
        searchVal(val, cb, {
          name: val,
          partner:`${partner.id}`
        }, 'name');
      },
      on: function (data) {
        if (data.isAdd && data.arr.length > 0) {
          let d = data.arr[0];
          tssBankNumName = d.name;
          tssBankNum = d.value;
        } else {
          tssBankNumName = "";
          tssBankNum = "";
        }
      }
    });

    var tssBankXmAnother = xmSelect.render({
      el: '#tssBankAnother',
      name: 'tssBankAnother',
      radio: true,
      tips: '请输入查询',
      size: 'mini',
      style: {
        height: '30px',
      },
      paging: true,
      pageSize: 6,
      data: initBankData,
      clickClose: true,
      filterable: true,
      remoteSearch: true,
      remoteMethod: function (val, cb, show) {
        searchVal(val, cb, {
          name: val,
          partner:`${partner.id}`
        }, 'name');
      },
      on: function (data) {
        if (data.isAdd && data.arr.length > 0) {
          let d = data.arr[0];
          tssBankNumAnother = d.value;
          tssBankNumNameAnother = d.name;
        } else {
          tssBankNumAnother = "";
          tssBankNumNameAnother = "";
        }
      }
    });
    </c:if>


    function searchVal(val, cb, searchData, filed) {
      if (!isBlank(val)) {
        $.ajax({
          type: 'post',
          url: '${ctx}/sysSettings/linkNumber/findLinkNumberList',
          data: searchData,
          async: false,
          dataType: 'json',
          success: function (d) {
            let arr = [];
            for (let i = 0; i < d.length; i++) {
              let data = {};
              data.name = d[i].columns.bank_name;
              data.value = d[i].columns.number;
              arr.push(data);
            }
            cb(arr);
          }
        });
      } else {
        cb([]);
      }
    }
  });

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

  function delImg(that, id) {
    $("#" + id).show();
    $(that).parent().remove();
    if('uploader20'==id){
      quaimgsCount--;
      $("#uploader20").show();
    }
  }

  // 关闭弹框
  function cancel() {
    var index = parent.layer.getFrameIndex(window.name);//先得到当前iframe层的索引
    parent.layer.close(index); //再执行关闭
  }

  function checkSelection() {
    let tenantType = $("#tenantType").val();
    let province = $("#province").find("option:selected").val();//省
    let city = $("#city").find("option:selected").val();//市
    let area = $("#area").find("option:selected").val();//区
    if (tenantType === "2") {
      province = $("#provinceAnother").find("option:selected").val();//省
      city = $("#cityAnother").find("option:selected").val();//市
      area = $("#areaAnother").find("option:selected").val();//区
    }
    // 检查是否所有选项都被选中
    if (isBlank(province) || isBlank(city)  || isBlank(area) ) {
      // 如果有选项未被选中，
      document.getElementById('projectCompany').disabled = true;
      document.getElementById('projectList').disabled = true;
    } else {
      // 如果所有选项都被选中，
      document.getElementById('projectCompany').disabled = false;
      document.getElementById('projectList').disabled = false;
    }
  }

  function change() {
    let flag = "${partner.overageFlag}";
    if (flag === "1") {
      let age = $("#age").val();
      if (age >= 65) {
        $("#bcxx").removeClass("hide");
      } else {
        $("#bcxx").addClass("hide");
      }
    }
  }

  function getAge(idCard) {
    // 从身份证号中获取出生日期
    var birthday = new Date(idCard.substring(6, 10), parseInt(idCard.substring(10, 12)) - 1, idCard.substring(12, 14));

    // 获取当前日期
    var today = new Date();

    // 计算年龄
    var age = today.getFullYear() - birthday.getFullYear();

    // 如果当前月份小于出生月份，或者当前月份等于出生月份但是当前日期小于出生日期，则年龄减一
    if (today.getMonth() < birthday.getMonth() || (today.getMonth() === birthday.getMonth() && today.getDate() < birthday.getDate())) {
      age--;
    }

    return age;
  }

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