<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <meta name="decorator" content="base"/>
  <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/style/admin.css" media="all">
  <link rel="stylesheet" type="text/css" href="${ctxPlugin}/static/css/reset.css" />
  <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/dist/viewer.css" media="all">
  <style>
    .layui-form-select dl {
      max-height: 200px;
      width: 80%;
    }
    html {
      background-color: #fff;
    }
    .layui-table td, .layui-table th {
      text-align: center;
    }
    .hx_l > span {
      position: absolute;
      right: 10px;
      top: 5px
    }
    #attachFile > li {
      height: 26px
    }
  </style>
</head>
<body>
<div class="layui-form">
  <div class="layui-card">
    <div class="layui-card-body layui-col-xs12" id="LAY_app">
      <button class="layui-btn" style="margin-left: 94.5%;" onclick="approvalRecord()">审批记录</button>
      <div class="layui-row layui-col-space12 layui-form-item">
        <div class="layui-col-lg3 layui-col-sm3">
          <label class="layui-form-label">电站编号：</label>
          <div class="layui-input-block">
            <input type="text" id="powerStationCode" disabled name="powerStationCode"  class="layui-input" value="${entry.powerStationCode}">
          </div>
        </div>
        <div class="layui-col-lg3 layui-col-sm3">
          <label class="layui-form-label">电站状态：</label>
          <div class="layui-input-block">
            <input type="text" id="entryStatus" name="entryStatus" disabled class="layui-input " value="" disabled>
          </div>
        </div>

        <div class="layui-col-lg3 layui-col-sm3">
          <label class="layui-form-label">代理商名称：</label>
          <div class="layui-input-block">
            <input type="text" id="traderName" name="traderName" class="layui-input layui-bg-gray" value="${entry.createTraderName}" disabled>
          </div>
        </div>

        <div class="layui-col-lg3 layui-col-sm3">
          <label class="layui-form-label">审核状态：</label>
          <div class="layui-input-block">
            <input type="text" name="status" class="layui-input layui-bg-gray" value="" disabled>
          </div>
        </div>
        <div class="layui-col-lg3 layui-col-sm3">
          <label class="layui-form-label">产品名称：</label>
          <div class="layui-input-block">
            <input type="text" id="projectName" name="projectName" class="layui-input layui-bg-gray"  value="${project.name}"  disabled>
          </div>
        </div>
        <div class="layui-col-lg3 layui-col-sm3">
          <label class="layui-form-label">项目公司：</label>
          <div class="layui-input-block">
            <input type="text" id="projectCompanyName" disabled class="layui-input " value="${entry.projectCompanyName}">
          </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 w-130">业主姓名：</label>
          <div class="layui-input-block ">
            <input type="text" id="tenantName" name="tenantName"  class="layui-input" value="${entry.tenantName}" disabled>
          </div>
        </div>
        <div class="layui-col-lg3 layui-col-sm3">
          <label class="layui-form-label w-130">身份证号：</label>
          <div class="layui-input-block ">
            <input type="text" id="idCode" name="idCode" class="layui-input" value="${entry.idCode}" disabled>
          </div>
        </div>
        <div class="layui-col-lg6 layui-col-sm6">
          <label class="layui-form-label w-130">安装地址：</label>
          <div class="layui-input-block ">
            <input type="text" id="address" name="address" class="layui-input" value="${entry.province}${entry.city}${entry.area}${entry.address}"  disabled>
          </div>
        </div>
        <div class="layui-col-lg3 layui-col-sm3">
          <label class="layui-form-label w-130">变更类型：</label>
          <div class="layui-input-block ">
            <input type="text" name="idCode" class="layui-input" value="物料信息" disabled>
          </div>
        </div>
        <div class="layui-col-lg3 layui-col-sm3">
          <label class="layui-form-label w-130">变更单号：</label>
          <div class="layui-input-block ">
            <input type="text" name="number" class="layui-input" value="${apply.number}" disabled>
          </div>
        </div>
        <div class="layui-col-lg3 layui-col-sm3">
          <label class="layui-form-label w-130">变更申请人：</label>
          <div class="layui-input-block ">
            <input type="text" name="creator" class="layui-input" value="${apply.creator}" disabled>
          </div>
        </div>
        <div class="layui-col-lg3 layui-col-sm3">
          <label class="layui-form-label w-130">申请时间：</label>
          <div class="layui-input-block ">
            <input type="text" name="creatTime" class="layui-input" value="${apply.createTime}" disabled>
          </div>
        </div>

        <div class="layui-inline layui-col-xs12">
          <label class="layui-form-label w-130">变更原因：</label>
          <div class="layui-input-block ">
            <textarea name="changeReason" id="changeReason" disabled class="layui-textarea">${apply.changeReason}</textarea>
<%--            <input type="text" id="changeReason" name="changeReason" class="layui-input" value="${apply.changeReason}" autocomplete="off" disabled>--%>
          </div>
        </div>
      </div>
      <div class="layui-col-xs12 mb-20 pr-30 mt-10">
        <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
          <ul class="layui-tab-title">
            <li class="layui-this">组件</li>
            <li>逆变器</li>
          </ul>
          <div class="layui-tab-content" style=" overflow: auto;margin-bottom: 120px">
            <div class="layui-tab-item layui-show">
              <table class="layui-table">
                <thead>
                <tr>
                  <th>序号</th>
                  <th>物料代码</th>
                  <th>物料名称</th>
                  <th>物料规格</th>
                  <th>品牌</th>
                  <th>变更前物料条码</th>
                  <th>变更后物料条码</th>
                </tr>
                </thead>
                <tbody id="materialTable">
                <c:forEach items="${zjList}" varStatus="vs" var="material">
                  <tr>
                    <td>${vs.count}</td>
                    <td>${material.columns.material_code}</td>
                    <td>${material.columns.material_name}</td>
                    <td>${material.columns.material_spec}</td>
                    <td>${material.columns.material_brand}</td>
                    <td>${material.columns.barcode}</td>
                    <td>${material.columns.new_barcode}</td>
                  </tr>
                </c:forEach>
                </tbody>
              </table>
            </div>
            <div class="layui-tab-item">
              <table class="layui-table">
                <thead>
                <tr>
                  <th>序号</th>
                  <th>物料代码</th>
                  <th>物料名称</th>
                  <th>物料规格</th>
                  <th>品牌</th>
                  <th>逆变器sn码</th>
                  <th>变更后逆变器sn码</th>
                  <th>通讯棒sn码</th>
                  <th>变更后通讯棒sn码</th>
                  <th>验证码</th>
                  <th>变更后验证码</th>
                </tr>
                </thead>
                <tbody id="nbqTable">
                <c:forEach items="${nbqList}" varStatus="vs" var="material">
                  <tr>
                    <td>${vs.count}</td>
                    <td>${material.columns.material_code}</td>
                    <td>${material.columns.material_name}</td>
                    <td>${material.columns.material_spec}</td>
                    <td>${material.columns.material_brand}</td>
                    <td>${material.columns.nbq_sn}</td>
                    <td>${material.columns.new_nbq_sn}</td>
                    <td>${material.columns.sn}</td>
                    <td>${material.columns.new_sn}</td>
                    <c:choose>
                      <c:when test="${material.columns.material_brand eq '固德威' || material.columns.material_brand eq '爱士惟'}">
                        <td>${material.columns.yz_code}</td>
                        <td>${material.columns.new_yz_code}</td>
                      </c:when>
                      <c:otherwise>
                        <td>--</td>
                        <td>--</td>
                      </c:otherwise>
                    </c:choose>
                  </tr>
                </c:forEach>
                </tbody>
              </table>
            </div>
          </div>
        </div>
      </div>
      <div class="layui-inline layui-col-xs12" style="position: fixed;bottom: 30px;background: #F8F8F8;padding-bottom: 20px;">
        <label class="layui-form-label w-130">审核备注：</label>
        <div class="layui-input-block ">
          <textarea name="auditRemarks" id="auditRemarks" placeholder="" class="layui-textarea"></textarea>
<%--          <input type="text" id="auditRemarks" name="auditRemark" class="layui-input" value="" autocomplete="off">--%>
        </div>
      </div>
    </div>
  </div>
</div>
<div class="layui-form-item text-c operate-footer">
  <button type="button" class="layui-btn" id="temp">暂存</button>
  <button type="button" class="layui-btn" id="pass">审核通过</button>
  <button type="button" class="layui-btn" id="refuse">审核驳回</button>
  <button class="layui-btn layui-btn-primary" onclick="closeDiv()">关闭</button>
</div>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/dist/viewer.js"></script>
<script type="text/javascript">

  //图片查看效果
  var viewer = new Viewer(document.getElementById('LAY_app'));
  layui.use(['form', 'table', 'upload', 'jquery', 'element'], function () {
    $ = layui.$;
    layer = layui.layer;
    $(function(){
      $("input[name='entryStatus']").val(getStatus('${entry.status}','${entry.credit}','${entry.designAuditFlag}'));
      $("input[name='status']").val(getStatus2('${apply.status}'));
    })

    //暂存
    var tempRep = false;
    $("#temp").click(function(){
      if(tempRep){
        return;
      }
      var id = '${apply.id}';
      var auditRemark = $("#auditRemarks").val();
      if (isBlank(auditRemark)) {
        layer.msg("请输入审核备注！",{icon:"2"});
        return;
      }
      tempRep = true;
      var loadingIndex = layer.load(2, {shade: [0.5,'#fff']});
      $.ajax({
        type: 'post',
        url: '${ctx}/entryChanges/materialInformationChange/temp',
        dataType: 'json',
        data: {
          id: id,
          auditRemark: auditRemark
        },
        success: function(data){
          if (data.code == "200") {
            top.layer.msg("暂存成功，请处理下一条数据!");
          } else {
            layer.msg(data.errMsg);
          }
        },
        complete: function(){
          tempRep = false;
        }
      });
    })

    //审核通过
    var opeRep = false;
    $("#pass").click(function(){
      if(opeRep){
        return;
      }
      var id = '${apply.id}';
      // var auditRemark = $("input[name='auditRemarks']").val();
      var auditRemark = $("#auditRemarks").val();
      opeRep = true;
      var loadingIndex = layer.load(2, {shade: [0.5,'#fff']});
      $.ajax({
        type: 'post',
        url: '${ctx}/entryChanges/materialInformationChange/pass',
        dataType: 'json',
        data: {
          id: id,
          auditRemark: auditRemark
        },
        success: function(data){
          layer.close(loadingIndex);
          if (data.code == "200") {
            top.layer.msg("操作成功");
            closeDiv();
            parent.location.reload();
          } else {
            layer.msg(data.errMsg);
          }
        },
        complete: function(){
          opeRep = false;
        }
      });
    })


    //审核不通过
    var refRep = false;
    $("#refuse").click(function(){
      if(refRep){
        return;
      }
      var id = '${apply.id}';
      // var auditRemark = $("input[name='auditRemark']").val();
      var auditRemark = $("#auditRemarks").val();
      if (isBlank(auditRemark)) {
        layer.msg("请输入审核备注！",{icon:"2"});
        return;
      }
      refRep = true;
      $.ajax({
        type: 'post',
        url: '${ctx}/entryChanges/materialInformationChange/refuse',
        dataType: 'json',
        data: {
          id: id,
          auditRemark: auditRemark
        },
        success: function(data){
          console.log(data)

          if (data.code == "200") {
            top.layer.msg("操作成功");
            closeDiv();
            parent.location.reload();
          }else if(data.code ==="501"){
            layer.msg(data.errMsg,{icon:5,anim:6});
          } else {
            layer.msg(data.errMsg);
          }
        },
        error: function (data){
          console.log("error Data"+data)
        },
        complete: function(){
          refRep = false;
        }
      });
    })

  })

  function getStatus(status, credit, design_audit_flag) {
    if (status == '0') {
      //预审状态 0.暂存 1.待预审 2.预审待审批 3.预审审批中 4.预审通过 5.预审拒绝
      if (credit == '1') {
        return '待预审';
      } else if (credit == '2') {
        return '预审审批中';
      } else if (credit == '3') {
        return '预审审批中';
      } else if (credit == '4') {
        if(design_audit_flag == '3'){
          return '自审驳回';
        }else if(design_audit_flag == 'a'){
          return '待设计';
        }else {
          return '待踏勘';
        }
      } else if (credit == '5') {
        return '预审拒绝';
      }
      return '暂存';
    }
    if (status == '1') {
      //设计审核状态：1.待踏勘 2.待自审 3.自审驳回 4.自审通过 5.设计审核驳回 6.设计审核通过/已完成 7.进件审核驳回
      if (design_audit_flag == '1') {
        return '待踏勘';
      } else if (design_audit_flag == '2') {
        return '待自审';
      } else if (design_audit_flag == '3') {
        return '自审驳回';
      } else if (design_audit_flag == '4') {
        return '自审通过';
      } else if (design_audit_flag == '5') {
        return '设计审核驳回';
      } else if (design_audit_flag == '6') {
        return '设计审核通过';
      } else if (design_audit_flag == '7') {
        return '进件审核驳回';
      } else if (design_audit_flag == 'a') {
        return '待设计';
      }
      return '待审核';
    }
    if (status == '2') {
      return '审核驳回';
    }
    if (status == '3') {
      return '待下单';
    }
    if (status == '4') {
      return '待安装';
    }
    if (status == '5') {
      return '待安装验收';
    }
    if (status == 'f') {
      return '安装验收退回';
    }
    if (status == '6') {
      return '待并网';
    }
    if (status == '7') {
      return '待并网验收';
    }
    if (status == '8') {
      return '待交付';
    }
    if (status == '9') {
      return '待归档';
    }
    if (status == '10') {
      return '验收驳回';
    }
    if (status == '11') {
      return '归档驳回';
    }
    if (status == 'a') {
      return '已完成';
    }
    if (status == 'c') {
      return '待代理商确认';
    }
    if (status == 'e') {
      return '待签署合同';
    }
    if (status == 'w') {
      return '信息登记';
    }
    if (status == 'g') {
      return '设计审核';
    }
    if (status == 'AN') {
      return '待安装确认';
    }
    if (status == 'AT') {
      return '安装确认驳回';
    }
    if (status == 'BW') {
      return '待并网确认';
    }
    if (status == 'BN') {
      return '并网确认驳回';
    }
    if (status == 'h') {
      return '设计自审';
    }
    if (status == 'i') {
      return '安装自审';
    }
  }

  // 状态 0.待审核 1.审核通过 2.审核驳回
  function getStatus2(status){
    if (status == '0'){
      return '待审核';
    }else if (status == '2') {
      return '审核通过';
    }else if (status == '3') {
      return '审核驳回';
    }
  }

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

  function isBlank(val) {
    if (val == null || val == '' || val == undefined) {
      return true;
    }
    return false;
  }
  function approvalRecord(){
    layer.open({
      title: '审批记录',
      type: 2,
      area: ['35%', '100%'],
      offset: 'rt',
      content: '${ctx}/customerEntry/approvalRecordPage?entryId=${entry.id}'
    })
  }
</script>
</body>
</html>


