text: const baseUrl = window.location.origin + '/ajax/admin/money/withdrawStatistics/';
  
  var columns = [
    {
      data: 'agent',
      orderable: false,
    },
    {
      data: null,
      orderable: false,
      render: function(data, type, row) {
        return moment($('#date_from').datepicker('getDate')).format("YYYY-MM-DD");
      }
    },
    {
      data: null,
      orderable: false,
      render: function(data, type, row) {
        return moment($('#date_to').datepicker('getDate')).format("YYYY-MM-DD");
      }
    },
    {
      data: null,
      orderable: false,
      render: function(data, type, row) {
        var totalmoney = parseFloat(row.totalmoney).toFixed(2);
  
        _html = "<p class='m-0'>" + totalmoney + "</p>";
        return _html;
      }
    },
    {
      data: null,
      orderable: false,
      render: function(data, type, row) {
        var _html = "";
  
        var pay_type = $('#pay_type').val();
        if (pay_type === "-1") {
          _html = '<p class="text-dark m-0">已回退</p>';
        } else if (pay_type === "1") {
          _html = "<p class='text-danger m-0'>已打款</p>";
        } else if (pay_type === "0") {
          _html = '<p class="text-dark m-0">未打款</p>';
        } else {
          _html = '<p class="text-dark m-0">全部</p>';
        }
  
        return _html;
      }
    }
  ];
  
  var apiWithdrawStatic = {
    initTable: function (url, method = 'POST', order = []) {
      $('#dt_withdrawStatistics').DataTable({
        dom: "<'row pr-4'<'col-sm-6 col-md-6'l><'col-sm-6 col-md-6 d-flex justify-content-end'B>>" +
          "<'row'<'col-sm-12'tr>>" +
          "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
        buttons: [
          { extend: 'csv', text: 'CSV 导出', charset: 'UTF-8', fieldSeparator: ',', bom: true },
          { extend: 'print', text: '打印' }
        ],
        responsive: true,
        processing: true,
        serverSide: true,
        order: order, //Initial
        searching: false,
        pageLength : 10,
        lengthMenu: [
          [ 5, 10, 25, 50, 100 ],
          [ 5, 10, 25, 50, 100 ]
        ],
        columns: columns,
        "language": {
          "lengthMenu": "显示 _MENU_ 行",
          "emptyTable": "没有数据。",
          "search": '搜索',
          'csv': 'CSV 导出',
          "info": "显示_START_ - _END_ / _TOTAL_件",
          "infoFiltered": "(filtered from _MAX_ total entries)",
          "zeroRecords": "没有匹配的数据。",
          "loadingRecords": "载入中...",
          "processing": "请稍候...",
          "paginate": {
            "first": '首页',
            'last': '尾页',
            "next": "下页",
            "previous": "上页"
          },
          searchPanes: {
            count: '{total} found',
          }
        },
        ajax: {
          url: url,
          type: method,
          headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
          },
          data: function(d) {
            d.agent = $('#agent').val();
            d.pay_type = $('#pay_type').val();
            d.date_from = moment($('#date_from').datepicker('getDate')).format("YYYY-MM-DD");
            d.date_to = moment($('#date_to').datepicker('getDate')).format("YYYY-MM-DD");
          },
          error: function (err) {
            console.log(err);
          }
        },
        drawCallback: function(data) {
          var response = this.api().ajax.json();
          var sum = parseFloat(response.sum).toFixed(2);
          if (response) {
            var html = '<td colspan="5" class="text-center"><b>合计：	' + sum + '</b></td>';
            $(this.api().table().footer()).html(html);
          }
        }
      });
    },
    updateTable: function () {
      $('#dt_withdrawStatistics').DataTable().ajax.reload();
    }
  };
  
  $(document).ready(function () {
  
    $("div[class='input-group date']").datepicker({
      format: 'yyyy-mm-dd',
      language: 'zh-CN'
    });
  
    var date_from = new Date();
    date_from.setMonth(date_from.getMonth() - 1);
    date_from.setDate(date_from.getDate() + 1);
    var date_to = new Date();
  
    $('#date_from').datepicker('setDate', date_from);
    $('#date_to').datepicker('setDate', date_to);
  
    $('#btnSearch').on('click', function () {
      apiWithdrawStatic.updateTable();
    });
  
    $('#agent, #pay_type').on('change', function() {
      apiWithdrawStatic.updateTable();
    })
    
    apiWithdrawStatic.initTable(baseUrl + "getData", 'GET');
  
  });
  
  