<template>
  <section class="content">
    <div class="box box-primary">
      <div class="box-body">
        <section class="content-header">
          <h1 id="itemTitle"></h1>
        </section>
        <section class="content-body">
          <div id="toolbar">
            <div class="col-sm-12">
              <div class="pull-left">
                <form id="searchForm"
                      class="col-sm-pull-12"
                      action="/admin/chargeRecord/exportPartitionDetail"
                      method="get"
                      target="_blank">
                  <div class="col-sm-11">
                    <input type="number"
                           name="partitionId"
                           value="1"
                           hidden />
                    <label for="beginDate"
                           class="col-sm-2 control-label">开始日期:</label>
                    <div class="col-sm-4"><input type="text"
                             class="form-control"
                             name="beginDate"
                             id="beginDate"
                             placeholder="必填"></div>
                    <label for="endDate"
                           class="col-sm-2 control-label">结束日期:</label>
                    <div class="col-sm-4"><input type="text"
                             class="form-control"
                             name="endDate"
                             id="endDate"
                             placeholder="必填"></div>
                  </div>
                </form>
              </div>
              <div class="pull-right">
                <button id="btnSearch"
                        class="btn btn-default">
                  <i class="glyphicon glyphicon-search"></i>查询
                </button>
                <button id="btnExport"
                        class="btn btn-default">
                  <i class="glyphicon glyphicon-export"></i>导出
                </button>
              </div>

            </div>
          </div>

          <!-- .content -->
          <div id="table"></div>
        </section>
      </div>
    </div>
  </section>
</template>

<script>
import TableHelper from '@/utils/bootstrap-table-helper';

export default {
  name: "ChargeRecordEnPartitionStatisticsView",
  setup () {
    return {};
  },
  created () {
    this.$nextTick(function () {
      this.initData();
    });
  },
  methods: {
    initData () {

      $(function () {
        var chargeStart = $('#beginDate').datepicker({
          format: 'yyyy-mm-dd',
          autoclose: true
        });
        chargeStart.datepicker("setDate", new Date(new Date() - 7 * 24 * 60 * 60 * 1000))

        var chargeEnd = $('#endDate').datepicker({
          format: 'yyyy-mm-dd',
          autoclose: true
        });
        chargeEnd.datepicker("setDate", new Date())

        chargeStart.on('changeDate', function () {
          var date = $('#beginDate').datepicker('getDate');
          chargeEnd.datepicker('setStartDate', date);
        });
        chargeEnd.on('changeDate', function () {
          var date = $('#endDate').datepicker('getDate');
          chargeStart.datepicker('setEndDate', date);
        });

        $('#table').bootstrapTable('destroy');
        $('#table').bootstrapTable({
          columns: [
            { field: 'date', title: '日期', align: 'center', width: '14%' },
            { field: 'googleUsd', title: 'google充值美元', align: 'center', width: '14%' },
            { field: 'payermaxUsd', title: 'payermax充值美元', align: 'center', width: '14%' },
            { field: 'myCardUsd', title: 'myCard充值美元', align: 'center', width: '14%' },
            { field: 'startPayUsd', title: 'startPay充值美元', align: 'center', width: '14%' },
            { field: 'iosUsd', title: 'ios充值美元', align: 'center', width: '14%' },
            { field: 'companyUsd', title: '对公打款美元', align: 'center', width: '14%' },
            { field: 'totalUsd', title: '总充值美元', align: 'center', width: '14%' },
          ],
          cache: false,
          striped: true,
          showRefresh: false,
          pagination: false,
          search: false,
          queryParamsType: "undefined",
          queryParams: function queryParams (params) {   //设置查询参数
            var param = {
              partitionId: 1,
              beginDate: $('#beginDate').val(),
              endDate: $('#endDate').val()
            };
            return param;
          },
          toolbar: '#toolbar',
          url: '/admin/chargeRecord/partitionDetail',
          onLoadSuccess: function () {  //加载成功时执行
            console.log("load success");
          },
          onLoadError: function () {  //加载失败时执行
            console.log("load fail");
          }
        });

        // 导出EXCEL
        $('#btnExport').on('click', function () {
          if (!$('#beginDate').val() || !$('#endDate').val()) {
            $("#tipMsg").text("请输入必填的信息");
            $("#tipModal").modal('show');
            return;
          }
          $("#searchForm").submit();
        });

        // 查询刷新
        $('#btnSearch').on('click', function () {
          if (!$('#beginDate').val() || !$('#endDate').val()) {
            $("#tipMsg").text("请输入必填的信息");
            $("#tipModal").modal('show');
            return;
          }
          TableHelper.doRefresh('#table');
        });
      });
    }
  },

};
</script>

<style scoped></style>