<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="80px">
      <el-form-item label="时间">
         <el-date-picker
          style="margin-top:5px;"
          v-model="dateRange"
          size="small"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="datetimerange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="报表种类" prop="type">
         <el-select v-model="queryParams.type" placeholder="请选择报表种类" size="small">
          <el-option label="日" :value="1"/>
          <el-option label="周" :value="2"/>
          <el-option label="月" :value="3"/>
          <el-option label="年" :value="4"/>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['system:admin:export']"
        >导出</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="adminList">
      <el-table-column label="时间" align="center" prop="reportDate" />
      <el-table-column label="报表种类" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.type == 1 ? '日':scope.row.type ==2 ? '周':scope.row.type ==3 ? '月':scope.row.type ==4 ? '年': '' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="总金额" align="center" prop="totalMoney" />
      <el-table-column label="现金" align="center" prop="cashMoney" />
      <el-table-column label="微信" align="center" prop="wxMoney" />
      <el-table-column label="支付宝" align="center" prop="zfbMoney" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.current"
      :limit.sync="queryParams.size"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listReport, exportReport } from "@/api/recharge/reportForm";

export default {
  name: "admin",
  data() {
    return {
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 参数表格数据
      adminList: [],
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        current: 1,
        size: 10,
        type: 1,
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();

  },
  methods: {
    /** 查询参数列表 */
    getList() {
      this.loading = true;
      listReport(this.addDateRange(this.queryParams,this.dateRange,'section')).then(response => {
          this.adminList = response.data.records.map(val=>{
            return {
              ...val,
              type:this.queryParams.type
            }
          });
          this.total = response.data.total;
          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.current = 1;
      this.queryParams.startTime = undefined;
      this.queryParams.endTime = undefined;
      this.queryParams.endTime = undefined;
      this.queryParams.type = 1
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      let queryParams = {...this.queryParams};
      delete queryParams.current
      delete queryParams.size
      this.exportLoading = true;
      exportReport(queryParams).then(response =>{
        this.exportLoading = false;
        localStorage.setItem('fileExportId', response.msg)
        this.$router.push({path:'/recharge/fileExport'})
      })

      // this.$confirm('是否确认导出数据?', "警告", {
      //     confirmButtonText: "确定",
      //     cancelButtonText: "取消",
      //     type: "warning"
      //   }).then(() => {
      //     this.exportLoading = true;
      //     return exportReport(queryParams);
      //   }).then(res => {
      //     this.downloadBlob(res)
      //     this.exportLoading = false;
      //   }).catch(() => {
      //     this.exportLoading = false;
      //   });
    },
  }
};
</script>
