{extend name="public:form" /}
{block name="body"}
<style type="text/css">
.layui-table-page{
  text-align: right;
}
</style>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body">
                           <form class="layui-form">
                             <div class="layui-input-inline" style="width:130px;">
                              <select name="search_type" id="search_type"   >
                                <option value="1" selected="selected" {if $search_type eq 1 } selected {/if}>站名</option>
                                <option value="2" {if $search_type eq 2 } selected {/if}>站号</option>
                                <option value="3" {if $search_type eq 3 } selected {/if}>项目编号</option>
                                <option value="4" {if $search_type eq 4 } selected {/if}>电表识别号</option>
                                <option value="5" {if $search_type eq 5 } selected {/if}>机房二维码</option>
                              </select>
                            </div>
                            <div class="layui-input-inline">
                              <input type="text" name="search_text" 
                              style="width:150px;" placeholder="搜索内容" autocomplete="off" id="search_text" class="layui-input" value="{$search_text}">
                            </div>
                           <div class="layui-input-inline layui-show-xs-block" style="width:130px;">

                              <select name="area_id" id="area_id">
                              <option value="0"> 区域</option>
                              {volist name="regions" id="region"}
                              {if $region.level == 0}
                                <option disabled='disabled'  class='layui-disabled' >{$region.region_name}</option>
                              {else /}
                              <option value="{$region.id}" {if $area_id eq $region.id } selected {/if} >&nbsp;&nbsp;&nbsp;&nbsp;{$region.region_name}</option>
                              {/if}
                              
                              {/volist}
                             
                              </select>
                            </div>
                    
                            <div class="layui-input-inline" style="width:130px;">
                              <select name="cp_date" id="cp_date">
                                <option value="1">抄表日期</option>
<!--                                 <option value="2">缴费日期</option>
 -->                            </select>
                            </div>
                            <div class="layui-input-inline">
                                <input type="text" name="date_start" id="date_start" placeholder="开始日期" autocomplete="off" class="layui-input"  style="width:130px;" value="{$date_start}">
                            </div>
                            <div class="layui-input-inline">
                                <input type="text" name="date_end" style="width:130px;" id="date_end" placeholder="结束日期" autocomplete="off" class="layui-input" value="{$date_end}">
                            </div>
                            <div class="layui-input-inline layui-show-xs-block" style="width:130px;">
                              <select name="pay_status" id="pay_status">
                                <option  value="2" {if $pay_status eq 2 } selected {/if}>缴费状态</option>
                                <option value="1" {if $pay_status eq 1 } selected {/if}>已缴费</option>
                                <option value="0" {if $pay_status eq 0 } selected {/if}>未缴费</option>
                              </select>
                            </div>
                            <div class="layui-input-inline">
                              <button class="layui-btn" lay-submit="" lay-filter="search">
                                <i class="layui-icon">&#xe615;</i></button>
                            </div>
                          </form>
                        </div>
                            <div class="layui-card-header">
                           <button class="layui-btn" id="CpImport">
                                <i class="layui-icon iconfont">&#xe7e4;</i></button>
                            <a href="/cp_export" target="_blank" class="layui-btn">
                                <i class="layui-icon iconfont">&#xe7e6;</i></a>
                          
                         
                        </div> 
                      <div class="layui-card-body">
                      <table class="layui-table" lay-data="{  url:'/copy', page:true,  id:'idTest',where:{search_type:document.getElementById('search_type').value,search_text:document.getElementById('search_text').value,area_id:document.getElementById('area_id').value,date_start:document.getElementById('date_start').value,date_end:document.getElementById('date_end').value,pay_status:document.getElementById('pay_status').value,cp_date:document.getElementById('cp_date').value} }">
                       <thead>
                          <tr>
                          <th lay-data="{field:'order_id'} ">单号</th>
                          <th lay-data="{field:'station_sp_code'}" >所属基站号</th>
                          <th lay-data="{field:'station_name'}">所属基站名</th>
                          <th lay-data="{field:'em_number'} ">所属电表号</th>
                          <th lay-data="{field:'cp_date'}">抄表日期</th>
                          <th lay-data="{field:'create_time'}">创建日期</th>
                           <th lay-data="{field:'cp_status',templet: '#cp_status'}">缴费情况</th>
                            <th lay-data="{fixed: 'right',  align:'center', toolbar: '#barDemo'}">操作</th>
                          </tr>
                        </thead>
                        </table>
                      </div>
                    </div>
                </div>
            </div>
        </div> 
    </body>
<script type="text/html"  id="cp_status">
    {{# if( d.cp_status == 1){ }}
      已缴费 已结算
   
    {{# }else if(d.cp_status == 2){ }}
      已缴费 未结算
   
     {{# }else if(d.cp_status == 3){ }}
     未缴费 已结算
   
     {{# }else if(d.cp_status == 4){ }}
      待确收
   
     {{# }else if( d.cp_status == 5){ }}
      已确收
    {{# }else { }}
     未缴费 未结算
    {{# } }}
</script>
<script type="text/html" id="barDemo">
<a title="查看"  href="/copy_show/{{d.id}}">[查看]</a>
<a title="账单" href="/statement_add/{{d.id}}">[账单]</a>

{{# if( d.statement_id && d.statement_id > 0 ){ }}

  {{# if(!d.photo_id || d.photo_id <= 1 ||
!d.statement_photo_id || d.statement_photo_id <= 1){ }}
<a title="缴费" href="javascript:;" onclick="showInfo()">[缴费]</a>
<a title="结算" href="javascript:;" onclick="showInfo()">[结算]</a>
  {{# }else { }}
<a title="缴费" href="/payment_add/{{d.id}}">[缴费]</a>
<a title="结算" href="/settle_add/{{d.id}}">[结算]</a>
 {{# } }}
{{# } }}


{{# if(d.identity == 1 && d.cp_status == 1){ }}
<a title="申请确收" onclick="aConfirm(this,{{d.id}})" href="javascript:;">[申请确收]</a>
{{# } }}

{{# if((d.identity == 1 || d.identity == 2) && d.cp_status == 4){ }}
<a title="待确收" class="layui-disabled">[待确收]</a>
{{# } }}

{{# if(d.identity == 5 && d.cp_status == 4){ }}
<a title="确收" onclick="confirm(this,{{d.id}})" href="javascript:;">[确收]</a>
{{# } }}

 {{# if(  d.identity !== 5 &&  d.payment_id ==null  &&  d.settle_id ==null ){ }}
<a title="删除" onclick="del(this,{{d.id}})" href="javascript:;">[删除]</a>
{{# } }}
</script>
<script>
layui.use(['table','laydate'], function(){


  var table = layui.table;
  var laydate = layui.laydate;

   
  //监听表格复选框选择
  table.on('checkbox(demo)', function(obj){
    console.log(obj)
  });

  //监听工具条
  table.on('tool(demo)', function(obj){
    var data = obj.data;
   
  });
  
  var $ = layui.$, active = {
    getCheckData: function(){ //获取选中数据
      var checkStatus = table.checkStatus('idTest')
      ,data = checkStatus.data;
      layer.alert(JSON.stringify(data));
    }
    ,getCheckLength: function(){ //获取选中数目
      var checkStatus = table.checkStatus('idTest')
      ,data = checkStatus.data;
      layer.msg('选中了：'+ data.length + ' 个');
    }
    ,isAll: function(){ //验证是否全选
      var checkStatus = table.checkStatus('idTest');
      layer.msg(checkStatus.isAll ? '全选': '未全选')
    }
  };
  
  $('.demoTable .layui-btn').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });
});

</script>
 <script type="text/javascript">
layui.use(['form', 'layer', 'laydate', 'upload'],
      function () {
          $ = layui.jquery;
          var form = layui.form,
              layer = layui.layer,
              laydate = layui.laydate,
              upload = layui.upload;


          //消息提示
          function layMsg(msg,type=6,time=1000){
              layer.msg(msg,{
                icon: type,
                time: time,
              });
          }

          laydate.render({
              elem:'#date_end',
              trigger:'click',

          })

          laydate.render({
              elem:'#date_start',
              trigger:'click',
          })

          var cpFile = upload.render({
              elem: '#CpImport' ,
              url: '/cp_import_only',
              accept: 'file',
              exts: 'xls|xlsx',
              field: 'cp_file',
              done: function (res) {
                  if(res.status == 1){
                      var msg = res.data.mes;
                      var fMsg = res.data.failMsg;
                      var time = 0;
                      if(fMsg.length !== undefined && fMsg.length > 0){
                          for (var i=0;i<fMsg.length;i++)
                          {
                              msg += fMsg[i] + ' \n ';
                              time ++
                          }
                      }
                      layer.msg(msg,{icon: 6,time: time*2000 },function(){
                          setTimeout(function(){
                              location.reload()
                          },1500)
                      })
                  }
                  else {
                      layMsg('导入失败',{icon: 5})
                      return;
                  }
              }
          });
  })

function del(obj,id){
  layer.confirm('确认要删除吗？',function(index){
  $.ajax({
          url: '/copy_del',
          method: "POST",
          data: {id:id},
          dataType: "json",
          success: function (data) {
              if(data.status == 1){
                  layer.msg(data.message,{icon:1,time:1000});
                  location.reload()
              } else {
                  layer.alert(data.message, {
                    icon: 5
                  });
              }
          }
      });     
  });
}

function aConfirm(obj,id){
    layer.confirm('是否申请确收？',function(index){
        $.ajax({
            url: '/apply_confirm',
            method: "POST",
            data: {id:id},
            dataType: "json",
            success: function (data) {
                if(data.status == 1){
                    layer.msg(data.message,{icon:1,time:1000});
                    //锁定按钮状态
                    $(obj).html('待确收');
                    $(obj).addClass('layui-disabled');
                } else {
                    layer.alert(data.message, {
                        icon: 5
                    });
                }
            }
        });
    });
}

function confirm(obj,id){
    layer.confirm('是否确收？',function(index){
        $.ajax({
            url: '/confirm',
            method: "post",
            data: {id:id},
            dataType: "json",
            success: function (data) {
                if(data.status == 1){
                    layer.msg(data.message,{icon:1,time:1000});
                    location.reload()
                } else {
                    layer.alert(data.message, {
                        icon: 5
                    });
                }
            }
        });
    });
}

function showInfo(){
    layer.msg('请先补充账单的附件信息');
}
</script>
{/block}