

  <title>我的订单 - 财务管理</title>

  <div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
      <a lay-href="">首页</a>
      <a><cite>财务管理</cite></a>
      <a><cite>充值统计</cite></a>
    </div>
  </div>
  
  <div class="layui-fluid">
    <form class="layui-form" action="">
      <div class="layui-form-item">

        <script type="text/html" template>
          {{# if(layui.router().search.show_all === '1'){ }}
        <div class="layui-input-inline">
          <input type="text" name="uid"  placeholder="用户ID" autocomplete="off" class="layui-input">
        </div>
        {{# } }}
        </script>

        <div class="layui-input-inline">
          <select lay-filter="group_by" class="group_by" name="group_by">
            <option value='day'>按天汇总</option>
            <option value='month'>按月汇总</option>
            <option value='year'>按年汇总</option>
          </select>
        </div>

        <div class="layui-input-inline">
          <input type="text" id="date" name="date"  placeholder="时间范围" autocomplete="off" class="layui-input">
        </div>
      </div>
    </form>

    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <div class="layui-card">
          <div class="layui-card-body">
            <table class="layui-hide" id="test-table-toolbar" lay-filter="test-table-toolbar"></table>
          </div>
        </div>
      </div>
    </div>
  </div>
  
  <script>
  layui.use(['admin', 'table','laydate'], function(){
    var $ = layui.$
    ,admin = layui.admin
    ,view = layui.view
    ,table = layui.table
    ,form = layui.form
    ,laydate = layui.laydate;

    var today=new Date();
    var targetday_milliseconds=today.getTime()+1000*60*60*24;
    today.setTime(targetday_milliseconds);
    var end = admin.formatDate(today,"YY-MM-DD")
    var targetday_milliseconds=today.getTime()-1000*60*60*24*30;
    today.setTime(targetday_milliseconds);
    var start = admin.formatDate(today,"YY-MM-DD")

    laydate.render({
      elem: '#date'
      ,range: true
      ,value: start + ' - ' + end
      ,done: function(value, date, endDate){
        var date_range = value
        var start = date_range.split(" - ")[0]
        var end = date_range.split(" - ")[1]
        table.reload('test-table-toolbar',{where: {"start":start,"end":end, page: {curr: 1}}})        
      }
    });

    form.render()
    var show_all_order = layui.router().search.show_all
    var access_token = layui.data('layuiAdmin')['access-token']
    var uid_hide = true
    if (show_all_order == "1") {
      uid_hide = false
    }


    table.render({
      elem: '#test-table-toolbar'
      ,url:'/order/count?type=充值&state=已付款'
      ,headers: {"access-token":access_token}
      ,title: '订单列表'
      ,where: {"show_all": show_all_order}
      ,cols: [[  
        {field:'time', title:'时间'}
        ,{field:'sum', title:'金额 (元)'}
      ]]
      ,page: true
      ,defaultToolbar: []
    }); 

    $("input[name='uid']").on('change', function(){
        var uid = $(this).val();
        table.reload('test-table-toolbar',{where: {"uid":uid, page: {curr: 1}}})

    });   

    form.on('select(group_by)', function(data){
      var group_by = data.value
      table.reload('test-table-toolbar',{where: {"group_by":group_by}, page: {curr: 1}})
    }); 

  });
  </script>