{extend name="public:base" /}
{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:150px;">
                            <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>
                            </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" style="width:150px;">
                            <select name="payment_status" id="payment_status">
                                <option value=""   selected="selected" {if $payment_status === '' } selected {/if}>缴费状态</option>
                                <option value="0"  {if $payment_status === 0 || $payment_status === '0'} selected {/if}>未缴费</option>
                                <option value="2"  {if $payment_status == 2 } selected {/if}>已缴费</option>
                            </select>
                        </div>
                        <div class="layui-input-inline" style="width:150px;">
                            <select name="settle_status" id="settle_status">
                                <option value="" selected="selected" {if $settle_status === '' } selected {/if}>结算状态</option>
                                <option value="0"  {if $settle_status === 0 || $settle_status === '0' } selected {/if}>未结算</option>
                                <option value="2"  {if $settle_status == 2 } selected {/if}>已结算</option>
                            </select>
                        </div>
                        <div class="layui-input-inline" style="width:150px;">
                            <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:150px;" value="{$date_start}">
                        </div>
                        <div class="layui-input-inline">
                            <input type="text" name="date_end" style="width:150px;" id="date_end" placeholder="结束日期" autocomplete="off" class="layui-input" value="{$date_end}">
                        </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-body ">
                    <div>

                        <div class="layui-btn-group demoTable">
                            <button class="layui-btn" data-type="getCheckData">
                                合并账单<!-- <span class="layui-badge layui-bg-orange" id="merge_list">0</span> -->
                            </button>
                        </div>


                    </div>
                    <table class="layui-table"  lay-filter="demo" lay-data="{  url:'/invoice', page:true, initSort: {field:'wealth', type:'desc'}, id:'idTest',where:{search_type:document.getElementById('search_type').value,search_text:document.getElementById('search_text').value,date_start:document.getElementById('date_start').value,date_end:document.getElementById('date_end').value,settle_status:document.getElementById('settle_status').value,payment_status:document.getElementById('payment_status').value}
}">                        <thead>
                    <tr>

                        <th lay-data="{type: 'checkbox', fixed: 'left'} "></th>
                        <th lay-data="{templet: '#invoice_id',sort: true} ">账单号</th>
                        <th lay-data="{field:'station_name',sort: true}">所属基站名</th>
                        <th lay-data="{templet:'#em_numb',sort: true} ">所属电表号</th>
                        <th lay-data="{templet: '#useage'}">抄表度数</th>
                        <th lay-data="{templet: '#repo_numb'}">用电量</th>
                        <th lay-data="{templet:'#payment'}">缴费金额</th>
                        <th lay-data="{templet:'#settle'}">结算金额</th>
                        <th lay-data="{field: 'status'}">账单状态</th>
                        <th lay-data="{field: 'now_date',sort: true}">抄表日期</th>
                        <!--<th lay-data="{fixed: 'right',  align:'center', toolbar: '#barDemo'}">操作</th>-->
                    </tr>
                    </thead>
                    </table>

                </div>

            </div>
        </div>
    </div>
</div>
</body>
{/block}
{block name="js"}
<script type="text/html" id="invoice_id">
    <a  class="layui-link"  title="查看" href="/invoice/{{d.id}}">{{d.invoice_id}}</a>
</script>
<script type="text/html" id="em_numb">
    <a  class="layui-link"  title="查看电表" href="/em_edit/{{d.em_id}}">{{d.em_numb}}</a>
</script>

<script type="text/html" id="payment">
    应缴: {{ d.payment_amount }} 已缴:{{ d.paid_amount }}
</script>
<script type="text/html" id="settle">
    应结: {{ d.settle_amount }} 已结:{{ d.sett_amount }}
</script>
<script type="text/html" id="useage">
    上期: {{ d.last_sum_numb  }} 本期:{{ d.current_sum_numb  }}
</script>
<script type="text/html" id="repo_numb">
    {{ (d.current_sum_numb*10000 - d.last_sum_numb*10000)/10000 }}
</script>
<script type="text/javascript">

    var $list =  new Set();
    layui.use(['form', 'layer', 'laydate', 'upload','table', 'element', 'slider'],
        function () {
            $ = layui.jquery;
            var form = layui.form,
                layer = layui.layer,
                laydate = layui.laydate,
                table = layui.table,
                element = layui.element,
                slider = layui.slider,
                upload = layui.upload;
                laydate.render({
                    elem:'#date_end',
                    trigger:'click',
                })
                laydate.render({
                    elem:'#date_start',
                    trigger:'click',
                })

            var $ = layui.$, active = {
                getCheckData: function(){ //获取选中数据
                    var ids = [];
                    var checkStatus = table.checkStatus('idTest')
                        ,data = checkStatus.data;

                    var iDs = '';
                    var count = 0;
                    data.forEach(
                        function($value,$key){
                            iDs += $value.invoice_id + '_'
                            count ++ 
                        }
                    )
                    if(count > 0) {
                        url = '/invoice/merge/list/'+iDs;
                        url = url.substr(0,(url.length -1))
                        xadmin.open('合并账单',url)
                    } else {
                        layer.msg('请选择账单', {
                            time: 2000,
                          });
                    }

                    
                    
                }
            };

            $('.demoTable .layui-btn').on('click', function(){
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });


        })


    function merge_list()
    {
        var iDs = '';
        if($list.size != 0){
            $list.forEach(
                function($value,$key){
                    iDs += $value + '_'
                }
            )
            url = '/invoice/merge/list/'+iDs;
            url = url.substr(0,(url.length -1))
            xadmin.open('合并账单',url)
        }
    }
</script>
{/block}


