<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>项目信息设置</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <meta name="decorator" content="base"/>
  <link rel="stylesheet" type="text/css" href="${ctxPlugin}/static/css/reset.css" />
  <link rel="stylesheet" type="text/css" href="${ctxPlugin}/lib/font/iconfont.css" />
  <style>
    html{
      background-color: #fff;
    }
    .layui-form-radio {
      padding-right: 0px !important;
      margin: 0px !important;
    }
    @font-face {
      font-family: 'iconfont';
      src: url('${ctxPlugin}/lib/font/iconfont.eot');
      src: url('${ctxPlugin}/lib/font/iconfont.eot?#iefix') format('embedded-opentype'),
      url('${ctxPlugin}/lib/font/iconfont.woff2') format('woff2'),
      url('${ctxPlugin}/lib/font/iconfont.woff') format('woff'),
      url('${ctxPlugin}/lib/font/iconfont.ttf') format('truetype'),
      url('${ctxPlugin}/lib/font/iconfont.svg#iconfont') format('svg');
    }
    .iconfont {
      font-family: "iconfont" !important;
      font-size: 16px;
      font-style: normal;
      -webkit-font-smoothing: antialiased;
      -moz-osx-font-smoothing: grayscale;
    }
    .zjDetail{
      margin-top: 10px;
      margin-bottom: 50px;
    }
    .zjDetail .yearInput{
      width: 80px;
    }
    .layui-form-label {
      width: 120px;
    }

    .layui-input-block {
      margin-left: 120px;
    }
    .layui-tab-title li {
      background-color:#f2f2f2;
      line-height: 40px;
    }
    .layui-tab-title .layui-this {
      background-color: #fff;
    }
  </style>
</head>
<body>
<div class="layui-form mb-0 pr-30" lay-filter="layuiadmin-form-admin" id="layuiadmin-form-admin">
  <input type="hidden" name="id" value="${setting.columns.id}" autocomplete="off" class="layui-input">
  <div class="layui-card">
    <div id="textDiv" class="layui-card-body mb-15">
      <div class="layui-form-item">
        <div class="layui-col-xs6 mb-10">
          <label class="layui-form-label">产品编号：</label>
          <div class="layui-input-block">
            <input type="text" name="code" value="${setting.columns.code}" lay-verify="required" autocomplete="off" class="layui-input ${not empty setting? 'layui-disabled':''}" ${not empty setting? 'disabled':''}>
          </div>
        </div>
        <div class="layui-col-xs6 mb-10">
          <label class="layui-form-label">产品名称：</label>
          <div class="layui-input-block">
            <input type="text" name="name" value="${setting.columns.name}" lay-verify="required" autocomplete="off" class="layui-input" disabled>
          </div>
        </div>
      </div>
      <div  class="layui-form-item">
        <div class="layui-col-xs6 mb-10">
          <label class="layui-form-label">所属产品线：</label>
          <div class="layui-input-block">
            <select name="productLineId" lay-verify="required" lay-filter="productLineId" id="productLineId" disabled>
              <option value="">请选择</option> <!-- 设置空值选项 -->
              <c:forEach items="${productLine}" var="productLine">
                <option value="${productLine.columns.id}" data-type="${productLine.columns.attribute}"
                        <c:if test="${productLine.columns.id == setting.columns.product_line_id}">selected</c:if>>${productLine.columns.name}</option>
              </c:forEach>
            </select>
          </div>
        </div>

        <div class="layui-col-xs6 mb-10">
          <label class="layui-form-label">业务属性：</label>
          <div class="layui-input-block">
            <input type="text" id="attribute" value="${setting.columns.attribute}" lay-verify="required" disabled class="layui-input layui-bg-gray" disabled>
          </div>
        </div>
      </div>
      <div  class="layui-form-item">
        <div class="layui-col-xs6 mb-10">
          <label class="layui-form-label">备案方式：</label>
          <div class="layui-input-block">
            <select name="filingType" lay-verify="required" disabled>
              <option value="">请选择</option>
              <option value="1" <c:if test="${setting.columns.filing_type eq '1'}">selected</c:if>>农户备案</option>
              <option value="2" <c:if test="${setting.columns.filing_type eq '2'}">selected</c:if>>项目公司备案</option>
            </select>
          </div>
        </div>
        <div class="layui-col-xs6 mb-10">
          <label class="layui-form-label">EPC公司：</label>
          <div class="layui-input-block">
            <select name="epcCompanyId" lay-verify="required"  lay-filter="epcCompanyId" disabled>
              <option value="">请选择</option>
              <c:forEach items="${epcCompany}" var="company">
                <option value="${company.columns.id}" data-type="${company.columns.company_code}"
                        <c:if test="${company.columns.id == setting.columns.epc_company_id}">selected</c:if>
                >${company.columns.name}</option>
              </c:forEach>
            </select>
          </div>
        </div>
      </div>
      <div  class="layui-form-item">
        <div class="layui-col-xs6 mb-10">
          <label class="layui-form-label">EPC单价：</label>
          <div class="layui-input-block">
            <input type="text" name="epcPrice" value="${setting.columns.epc_price}" autocomplete="off" lay-verify="required" class="layui-input"  oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')" disabled>
            <span class="pos-a h-32 lh-32 layui-span-unit">元/瓦</span>
          </div>
        </div>
      </div>
      <div  class="layui-form-item">
        <div class="layui-col-xs6 mb-10">
          <label class="layui-form-label">租金支付周期：</label>
          <div class="layui-input-block">
            <select name="payCycle" lay-verify="required" disabled>
              <option value="">请选择</option>
              <option value="1" <c:if test="${setting.columns.pay_cycle eq 1}">selected</c:if>>按月支付</option>
              <option value="2" <c:if test="${setting.columns.pay_cycle eq 2}">selected</c:if>>按季支付</option>
              <option value="3" <c:if test="${setting.columns.pay_cycle eq 3}">selected</c:if>>按年支付</option>
            </select>
          </div>
        </div>
        <div class="layui-col-xs6 mb-10">
          <label class="layui-form-label">组件规格：</label>
          <div class="layui-input-block">
            <select id="assemblySpecs" name="assemblySpecs" disabled>
              <option value="">请选择</option>
              <c:forEach items="${assemblySpecsList}" var="assemblySpecs">
                <option value="${assemblySpecs.columns.model}" <c:if test="${setting.columns.assembly_specs eq assemblySpecs.columns.model}">selected</c:if> >${assemblySpecs.columns.model}</option>
              </c:forEach>
            </select>
          </div>
        </div>
      </div>
      <div  class="layui-form-item">
        <%--                暂时隐藏对接资方字段，未删除表单，默认值为1--%>
        <div class="layui-col-xs6 mb-10" style="display: none">
          <label class="layui-form-label">是否对接资方：</label>
          <div class="layui-input-block">
            <label><input type="radio" name="connectManageFlag" lay-filter="connectManageFlag" value="0" title="否" disabled></label>
            <label  class="ml-20"><input type="radio" name="connectManageFlag" lay-filter="connectManageFlag" value="1" title="是" checked disabled></label>
          </div>
        </div>

        <div class="layui-col-xs6 mb-10">
          <label class="layui-form-label">是否国网授权：</label>
          <div class="layui-input-block">
            <label><input type="radio" name="stateAuthorizedFlag" lay-filter="stateAuthorizedFlag" value="0" title="否" disabled ${setting.columns.state_authorized_flag eq 0 or setting eq null ? 'checked':''}></label>
            <label  class="ml-20"><input type="radio" name="stateAuthorizedFlag" lay-filter="stateAuthorizedFlag" value="1" title="是" disabled ${setting.columns.state_authorized_flag eq 1 ? 'checked':''}></label>
          </div>
        </div>
        <div class="layui-col-xs6 mb-10">
          <label class="layui-form-label">资方名称：</label>
          <div class="layui-input-block ">
            <select id="management" name="management" disabled>
              <option value="">请选择</option>
              <c:forEach items="${partnerList}" var="partner">
                <option value="${partner.id}" <c:if test="${setting.columns.management eq partner.id}">selected</c:if> >${partner.name}</option>
              </c:forEach>
            </select>
          </div>
        </div>
      </div>
      <div  class="layui-form-item">
        <div class="layui-col-xs6 mb-10">
          <label class="layui-form-label">是否购买保险：</label>
          <div class="layui-input-block">
            <label><input type="radio" name="buyInsuranceFlag" lay-filter="buyInsuranceFlag"  value="0" title="否" disabled  ${setting.columns.buy_insurance_flag eq 0 or setting eq null ? 'checked':''}  ></label>
            <label class="ml-20"><input type="radio" name="buyInsuranceFlag" lay-filter="buyInsuranceFlag" value="1"  title="是" disabled ${setting.columns.buy_insurance_flag eq 1 ? 'checked':''}></label>
          </div>
        </div>
        <div class="layui-col-xs6 mb-10">
          <label class="layui-form-label">保险名称：</label>
          <div class="layui-input-block ">
            <select id="insuranceId" name="insuranceId" lay-filter="layui-input-bx" disabled ${setting.columns.buy_insurance_flag eq 0 or setting eq null ? '':''}>
              <option value="">请选择</option>
              <c:forEach var="insurance" items="${insuranceList}">
                <option id="bxDM" value="${insurance.columns.id}" ${setting.columns.insurance_id eq insurance.columns.id ? 'selected':''}>${insurance.columns.name}</option>
              </c:forEach>
            </select>
          </div>
        </div>
      </div>
      <div class="layui-form-item">
        <div class="layui-col-xs12 mb-15 mt-20">
          <div class="layui-tab">
            <ul class="layui-tab-title">
              <li class="layui-this" >租金方案</li>
              <li>参数设置</li>
              <li>授权区域</li>
            </ul>
            <div class="layui-tab-content">
              <div class="layui-tab-item layui-show">
                <div class="zjDetail">
                  <c:if test="${empty variables}">
                    <div  class="layui-form-item">
                      <div class="layui-col-xs5 mb-10">
                        <label class="layui-form-label">第1阶段：</label>
                        <div class="layui-inline">
                          <input type="text" name="startYear" value="1" class="layui-input yearInput" style="border: black;"  oninput="value=value.replace(/[^\d]/g,'')" disabled>
                        </div>
                        <div class="layui-inline">~</div>
                        <div class="layui-inline">
                          <input type="text" name="endYear" value="" class="layui-input yearInput"  oninput="value=value.replace(/[^\d]/g,'')" disabled>
                          <span class="pos-a h-32 lh-32 layui-span-unit">年</span>
                        </div>
                      </div>

                      <div class="layui-col-xs5 mb-10">
                        <label class="layui-form-label">第1阶段单价：</label>
                        <div class="layui-input-block">
                          <input type="text" name="unitPrice" value="" class="layui-input"  oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')" disabled>
                          <span class="pos-a h-32 lh-32 layui-span-unit">元/块/年</span>
                        </div>
                      </div>
                    </div>
                    <div  class="layui-form-item">
                      <div class="layui-col-xs5 mb-10">
                        <label class="layui-form-label">第2阶段：</label>
                        <div class="layui-inline">
                          <input type="text" name="startYear" value="" class="layui-input yearInput"  oninput="value=value.replace(/[^\d]/g,'')" disabled>
                        </div>
                        <div class="layui-inline">~</div>
                        <div class="layui-inline">
                          <input type="text" name="endYear" value="" class="layui-input yearInput"  oninput="value=value.replace(/[^\d]/g,'')" disabled>
                          <span class="pos-a h-32 lh-32 layui-span-unit">年</span>
                        </div>
                      </div>

                      <div class="layui-col-xs5 mb-10">
                        <label class="layui-form-label">第2阶段单价：</label>
                        <div class="layui-input-block">
                          <input type="text" name="unitPrice" value=""  class="layui-input"  oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')" disabled>
                          <span class="pos-a h-32 lh-32 layui-span-unit">元/块/年</span>
                        </div>
                      </div>
                    </div>
                  </c:if>

                  <c:if test="${not empty variables}">
                    <c:forEach var="variable" items="${variables}" varStatus="vs">
                      <div  class="layui-form-item">
                        <div class="layui-col-xs5 mb-10">
                          <label class="layui-form-label">第${vs.count}阶段：</label>
                          <div class="layui-inline">
                            <input type="text" name="startYear" value="${variable.startYear}" class="layui-input yearInput"
                            <c:if test="${vs.count == 1}"> style="border: black;"</c:if>   oninput="value=value.replace(/[^\d]/g,'')" disabled>

                          </div>
                          <div class="layui-inline">~</div>
                          <div class="layui-inline">
                            <input type="text" name="endYear" value="${variable.endYear}" class="layui-input yearInput"  oninput="value=value.replace(/[^\d]/g,'')" disabled>
                            <span class="pos-a h-32 lh-32 layui-span-unit">年</span>
                          </div>
                        </div>

                        <div class="layui-col-xs5 mb-10">
                          <label class="layui-form-label">第${vs.count}阶段单价：</label>
                          <div class="layui-input-block">
                            <input type="text" name="unitPrice" value="${variable.unitPrice}" class="layui-input"  oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')" disabled>
                            <span class="pos-a h-32 lh-32 layui-span-unit">元/块/年</span>
                          </div>
                        </div>
                      </div>
                    </c:forEach>
                  </c:if>

                </div>
              </div>
              <div class="layui-tab-item">
                <table class="layui-table" style="margin-top: 10px;margin-bottom: 50px;">
                  <thead>
                  <tr>
                    <th>参数名</th>
                    <th><i class="red">*</i>参数值</th>
                    <th>租赁年限从（含）</th>
                    <th>租赁年限到（含）</th>
                  </tr>
                  </thead>
                  <tbody id="productParaListBody">
                  <c:if test="${not empty productPara}">
                    <c:forEach var="para" items="${productPara}">
                      <tr>
                        <td><select class="para" name="para" lay-filter="para" disabled>
                          <option value="">请选择</option>
                          <option value="BASIC_ELE_TIME"
                                  <c:if test="${para.productParaCode eq 'BASIC_ELE_TIME'}">selected</c:if>>基准发电小时数(小时)</option>
                          <option value="ELE_PRICE"
                                  <c:if test="${para.productParaCode eq 'ELE_PRICE'}">selected</c:if>>电价(元/kwh)</option>
                          <option value="MANUFACTURER_INCONE_RATIO"
                                  <c:if test="${para.productParaCode eq 'MANUFACTURER_INCONE_RATIO'}">selected</c:if>>收益分成比例(厂商)</option>
                          <option value="DECAY_RATE"
                                  <c:if test="${para.productParaCode eq 'DECAY_RATE'}">selected</c:if>>光伏板衰减率(年)</option>
                          <option value="MAINTENANCE_PRICE"
                                  <c:if test="${para.productParaCode eq 'MAINTENANCE_PRICE'}">selected</c:if>>运维费用(元/瓦/年)</option>
                          <option value="DEPOSIT_RATIO"
                                  <c:if test="${para.productParaCode eq 'DEPOSIT_RATIO'}">selected</c:if>>保证金比例</option>
                          <option value="RESIDUALS_RATE"
                                  <c:if test="${para.productParaCode eq 'RESIDUALS_RATE'}">selected</c:if>>残值率</option>
                          <option value="PRICE_SUBSIDY"
                                  <c:if test="${para.productParaCode eq 'PRICE_SUBSIDY'}">selected</c:if>>电价补贴</option>
                          <option value="DISPOSAL_PRICE"
                                  <c:if test="${para.productParaCode eq 'DISPOSAL_PRICE'}">selected</c:if>>投资资产到期处置价</option>
                        </select>
                        </td>
                        <td><input type="text" name="product_para_value" autocomplete="off"
                                   class="layui-input product_para_value"
                                   value="${para.productParaValue}" disabled></td>
                        <td><input type="text" name="lease_term_from" autocomplete="off"
                                   class="layui-input lease_term_from"
                                   value="${para.leaseTermFrom}" disabled></td>
                        <td><input type="text" name="lease_term_to" autocomplete="off"
                                   class="layui-input lease_term_to"
                                   value="${para.leaseTermTo}" disabled></td>
                      </tr>
                    </c:forEach>
                  </c:if>
                  </tbody>
                </table>
              </div>
              <div class="layui-tab-item">
                <table class="layui-table" style="margin-bottom: 60px">
                  <thead>
                  <tr>
                    <th>省</th>
                    <th>市</th>
                    <th>区/县</th>
                  </tr>
                  </thead>
                  <tbody id="areaSetListBody">
                  <c:forEach items="${areaList}" var="al">
                    <tr>
                      <td>${al.province}</td>
                      <td>${al.city}</td>
                      <td>${al.area}</td>
                    </tr>
                  </c:forEach>
                  </tbody>
                </table>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/font/iconfont.js"></script>
<script>

  var attribute='${empty setting?0:setting.columns.attribute}';
  var myreg = /^[0-9]*$/;
  layui.config({
    base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['form','jquery'], function () {
    $ = layui.$,
            form = layui.form;
    if(!isBlank(attribute)){
      var att=getAttribute(attribute);
      $("#attribute").val(att);
    }
    form.on('select(productLineId)', function(data){
      var attribute = $(data.elem).find("option:selected").attr("data-type");
      var att=getAttribute(attribute);
      $("#attribute").val(att);
    });

    form.on('radio(buyInsuranceFlag)', function (data) {
      if(data.value == '0'){
        $("#insuranceId").val("");
        $("#insuranceId").attr("disabled", "disabled");
      }else{
        $("#insuranceId").removeAttr("disabled");
      }
      form.render("select");
    });

    form.verify({
      pass: function(value){
        var te = /^[1-9]\d{0,2}$/;
        if(!isBlank(value) && !te.test(value)){
          return "排序只能填正整数";
        }
      },
    });

    var from = layui.form
    var layer = layui.layer
    // var epcm = ''
    //保险与EPC公司关联，修改的时候数据需初始化
    var epcm = "${setting.columns.epc_company_id}";
    from.on('select(epcCompanyId)',function (data) {
      $("#insuranceId").empty();
      let html = "";
      $("#insuranceId").html(html);
      //  layui.form.render('select');
      epcm = data.value
      //调用方法
      $.ajax({
        type:"POST",
        url:"${ctx}/sysSettings/projectInfoSetting/getEpc",
        data: {
          id: epcm
        },
        success:function(result){
          if(result =="205"){
            layer.msg("暂无数据!")
            return
          }
          // console.log(result)
          let html = "<option value=''>请选择</option>";
          for (let i = 0; i < result.length; i++) {
            let epc = result[i];
            html = html + '<option value="' + epc.columns.id + '">' + epc.columns.name + '</option>';
          }
          $("#insuranceId").append(html);
          form.render('select');
        }
      });
    })

    //点击提示信息
    from.on('select(layui-input-bx)',function (data) {
      if (epcm === '') {
        layer.msg('还未选择EPC公司,请先选择EPC公司后重试');
        $("#insuranceId").val('');
        layui.form.render('select');
      }
    })
    var  saveFg=false;
    form.on('submit(component-form-element)',function(data){
      if(saveFg){
        return false;
      }
      var field = data.field; //获取提交的字段
      var url = '${ctx}/sysSettings/projectInfoSetting/add';
      if(!isBlank(field.id)){
        url = '${ctx}/sysSettings/projectInfoSetting/edit';
      }
      var attribute = $("#productLineId").find("option:selected").attr("data-type");
      // if(isBlank(field.projectCompanyId) && '1'== attribute){
      //     layer.msg("央企项目，项目公司不能为空！",{icon:5,anim:6});
      //     return false;
      // }
      if(isBlank(field.payCycle) && '1'== attribute){
        layer.msg("央企项目，租金支付周期不能为空！",{icon:5,anim:6});
        return false;
      }
      var assemblySpecs=$("#assemblySpecs").val();
      if(isBlank(assemblySpecs)){
        layer.msg("组件规格必选", {time: 3000});
        return false;
      }
      if(!isBlank(field.connectManageFlag) && field.connectManageFlag=="1" && isBlank(field.management)){
        layer.msg("资方不能为空", {time: 3000});
        return false;
      }
      if(!isBlank(field.buyInsuranceFlag) && field.buyInsuranceFlag=="1" && isBlank(field.insuranceId)){
        layer.msg("保险名称不能为空", {time: 3000});
        return false;
      }
      var variables=[];

      $(".zjDetail").find(".layui-form-item").each(function (index){
        var stage=index+1;
        var startYear=$(this).find("input[name='startYear']").val();
        var endYear=$(this).find("input[name='endYear']").val();
        var unitPrice=$(this).find("input[name='unitPrice']").val();
        var obj={
          stage:stage
          ,startYear:startYear
          ,endYear:endYear
          ,unitPrice:unitPrice
        }
        variables.push(obj);
      })

      var productPara=[];
      var checktr = false;
      $("#productParaListBody").find("tr").each(function (index){
        let code = $(this).find(".para").val();
        let name = $(this).find(".para option:selected").text();
        let value = $(this).find(".product_para_value").val();
        let lease_term_from = $(this).find(".lease_term_from").val();
        let lease_term_to = $(this).find(".lease_term_to").val();
        if (isBlank(value)) {
          layer.msg(name + "参数值不能为空");
          checktr = true;
          return false;
        }
        let obj={
          productParaName:name
          ,productParaCode:code
          ,productParaValue:value
          ,leaseTermFrom:lease_term_from
          ,leaseTermTo:lease_term_to
        }
        productPara.push(obj);
      })
      if(checktr){
        saveFg = false;
        return
      }

      let areaList = [];
      $("#areaSetListBody").find("tr").each(function (index) {
        let province = $(this).find("td").eq(0).text();
        let city = $(this).find("td").eq(1).text();
        let area = $(this).find("td").eq(2).text();
        let addAreaVo = {
          province: province,
          city: city,
          area: area
        };
        areaList.push(addAreaVo);
      })
      console.log(areaList,"传送")
      //  let companyList = [];
      // $("#addProjectCor").find("tr").each(function (index) {
      //     let id =  $(this).find("td").eq(0).text();
      //     let companyCode = $(this).find("td").eq(1).text();
      //     let name = $(this).find("td").eq(2).text();
      //     let addProjectCor = {
      //         id: id,
      //         companyCode: companyCode,
      //         name: name,
      //     };
      //     companyList.push(addProjectCor);
      // })
      saveFg=true;
      field.variables=variables;
      field.productPara=productPara;
      field.areaList = areaList;
      // field.companyList = companyList
      console.log(field);
      // return ;
      $.ajax({
        url: url,
        type: 'post',
        contentType : "application/json;charsetset=UTF-8",
        data:JSON.stringify(field),
        success: function(data) {
          console.log(data)
          if(data.code === "200"){
            var index = parent.layer.getFrameIndex(window.name);
            layer.msg('操作成功！', {icon:1,time:1000},function(){
              localStorage.removeItem("areaList");
              parent.layer.close(index);
              parent.location.reload(); //刷新父页面
            })
          } else if (data.code === "501") {
            layer.msg(data.errMsg, {icon: 5, anim: 6});
            saveFg = false;
          } else if (data.code === "400") {
            layer.msg(data.errMsg, {icon: 5, anim: 6});
            saveFg = false;
          } else {
            layer.msg("添加失败！", {icon: 5, anim: 6});
            saveFg = false;
          }
        },
        complete:function(){

        }
      });

    })

    $(".layui-tab-title li").click(function (data) {
      $('.layui-tab-item').eq($(this).index()).addClass('layui-show').siblings('.layui-tab-item').removeClass('layui-show');
      $(".layui-tab-title li").removeClass("layui-this");
      $(this).addClass("layui-this");
      switch ($(this).index()) {
        case 0:
          $(".tableTitle1").addClass("layui-hide")
          $(".tableTitle2").addClass("layui-hide")
          // $(".tableTitle3").addClass("layui-hide")
          break;
        case 1:
          $(".tableTitle1").removeClass("layui-hide");
          $(".tableTitle2").addClass("layui-hide")
          // $(".tableTitle3").addClass("layui-hide")
          break;
        case 2:
          $(".tableTitle2").removeClass("layui-hide")
          $(".tableTitle1").addClass("layui-hide")
          // $(".tableTitle3").addClass("layui-hide")
          break;
        case 3:
          $(".tableTitle1").addClass("layui-hide")
          $(".tableTitle2").addClass("layui-hide")
          // $(".tableTitle3").removeClass("layui-hide")
          break;

      }
    })
  });

  function isBlank(val) {
    if (val == null || val == '' || val == undefined) {
      return true;
    }
    return false;
  }
  function cancel(){
    var index = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
  }

  function btnUpdate(){
    var htm='<div class="layui-word-aux btnDiv">';
    htm+= '<button class="layui-btn layui-btn-xs  ml-10" onclick="addBtn(this)"><i class="layui-icon">&#xe654;</i>';
    htm+= '<button class="layui-btn delBtn layui-btn-xs" onclick="delBtn(this)"><i class="layui-icon">&#xe640;</i></button>';
    htm+= '</div>';
    var len=$(".zjDetail").find(".layui-form-item").length;
    if(len>1){
      $(".zjDetail").find(".layui-form-item:last").append(htm);
    }
  }

  function getAttribute(attribute){
    var att='';
    if(attribute == '1'){
      att= '纯租25年业务';
    }else if(attribute == '2'){
      att= '经营性租赁';
    }else if(attribute == '3'){
      att= '融资租赁';
    }else if(attribute == '4'){
      att= '光伏贷';
    }else if(attribute == '5'){
      att= '全款';
    }else if(attribute == '6'){
      att= '其它';
    }
    return att;
  }

  function addPara() {
    let html = '<tr>';
    html += '<td><select class="para" name="para" lay-filter="para">';
    html += '<option value="">请选择</option>';
    html += '<option value="BASIC_ELE_TIME">基准发电小时数(小时)</option>';
    html += '<option value="ELE_PRICE">电价(元/kwh)</option>';
    html += '<option value="MANUFACTURER_INCONE_RATIO">收益分成比例(厂商)</option>';
    html += '<option value="DECAY_RATE">光伏板衰减率(年)</option>';
    html += '<option value="MAINTENANCE_PRICE">运维费用(元/瓦/年)</option>';
    html += '<option value="DEPOSIT_RATIO">保证金比例</option>';
    html += '<option value="PRICE_SUBSIDY">电价补贴</option>';
    html += '<option value="RESIDUALS_RATE">残值率</option>';
    html += '<option value="DISPOSAL_PRICE">投资资产到期处置价</option>';
    html += '</select></td>';
    html += '<td><input type="text" name="product_para_value" autocomplete="off" class="layui-input product_para_value"></td>';
    html += '<td><input type="text" name="lease_term_from" autocomplete="off" class="layui-input lease_term_from"></td>';
    html += '<td><input type="text" name="lease_term_to" autocomplete="off" class="layui-input lease_term_to"></td>';
    html += '<td><span onclick="delOne(this)" style="color: #0e8ee7">删除</span></td>';
    html += '</tr>';
    $("#productParaListBody").append(html);
    form.render("select");
  }


  function addProjectCor() {
    let csareaList = [];
    $("#areaSetListBody").find("tr").each(function (index) {
      let province = $(this).find("td").eq(0).text();
      let city = $(this).find("td").eq(1).text();
      let area = $(this).find("td").eq(2).text();
      let addAreaVo = {
        province: province,
        city: city,
        area: area
      };
      csareaList.push(addAreaVo);
    })
    var str=JSON.stringify(csareaList)
    localStorage.setItem("areaList", str);
    layer.open({
      type: 2,
      title: '关联项目公司',
      content: '${ctx}/sysSettings/projectInfoSetting/addProjectComInfo',
      area: ['100%', '100%']
    });
  }


  function addArea(){
    layer.open({
      type: 2,
      title: '添加区域',
      content: '${ctx}/trader/toAddAreaPage',
      area: ['60%','100%'],
      success : function(layero) {
        layero.find('.layui-layer-btn').css('text-align', 'center');
        layero.find('.layui-layer-btn').find(".layui-layer-btn0").css("background-color","#009688");
      }
    });
  }

  function addAreaHtml(province, city, area) {
    let flag = false;
    $("#areaSetListBody").find("tr").each(function (index){
      let pro = $(this).find("td").eq(0).text();
      let cit = $(this).find("td").eq(1).text();
      let are = $(this).find("td").eq(2).text();
      if (pro === province) {
        if (isBlank(city)) {
          layer.msg('区域已存在');
          flag = true;
          return false;
        } else if (cit === city) {
          if (isBlank(area)) {
            layer.msg('区域已存在');
            flag = true;
            return false;
          } else {
            let split = area.split(",");
            for (let i = 0; i < split.length; i++) {
              if (are === split[i]) {
                layer.msg('区域已存在');
                flag = true;
                return false;
              }
            }
          }
          if (isBlank(are)){
            layer.msg('区域已存在');
            flag = true;
            return false;
          }
        }
        if (isBlank(cit)){
          layer.msg('区域已存在');
          flag = true;
          return false;
        }else if (cit === city) {
          if (isBlank(area)) {
            layer.msg('区域已存在');
            flag = true;
            return false;
          } else {
            let split = area.split(",");
            for (let i = 0; i < split.length; i++) {
              if (are === split[i]) {
                layer.msg('区域已存在');
                flag = true;
                return false;
              }
            }
          }
        }

      }
    })
    if (flag) {
      return;
    }
    let html = '';
    if (isBlank(area)) {
      html += '<tr>';
      html += '<td>' + province + '</td>';
      html += '<td>' + city + '</td>';
      html += '<td>' + area + '</td>';
      html += '<td><span onclick="delOne(this)" style="color: #0e8ee7">删除</span></td>';
      html += '</tr>';
    } else {
      let split = area.split(",");
      for (let i = 0; i < split.length; i++) {
        html += '<tr>';
        html += '<td>' + province + '</td>';
        html += '<td>' + city + '</td>';
        html += '<td>' + split[i] + '</td>';
        html += '<td><span onclick="delOne(this)" style="color: #0e8ee7">删除</span></td>';
        html += '</tr>';
      }
    }

    $("#areaSetListBody").append(html);
  }


  function GetValue(obj) {
    console.log("传送数据", obj);
    // 遍历接收到的数据，将每个项目公司信息渲染到表格中
    obj.forEach(function(item) {
      // 检查 item.id 是否与现有项目的 ID 相同
      var idExists = false;
      $("#addProjectCor tr").each(function() {
        var existingId = $(this).find('td:first').text(); // 获取每行的第一个单元格（即 ID）
        if (existingId === item.id) {
          idExists = true; // 如果存在相同的 ID，则将标志设置为 true
          return false; // 停止循环
        }
      });

      // 如果不存在相同的 ID，则将新行添加到表格中
      if (!idExists) {
        var newRow = '<tr>' +
                '<td style="display: none">' + item.id + '</td>' +
                '<td>' + item.company_code + '</td>' +
                '<td>' + item.name + '</td>' +
                '<td><span onclick="delOne(this)" style="color: #0e8ee7">删除</span></td>' +
                '</tr>';
        $("#addProjectCor").append(newRow);
      }
    });
  }



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