<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" >
      <el-form-item label="姓名或手机号:" >
        <el-input
          v-model.trim="queryParams.nameOrPhone"
          placeholder="请输入姓名或手机号"
          clearable
          size="small"
          style="width: 180px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="时间:">
         <el-date-picker
         style="margin-top:5px;"
          v-model="dateRange"
          value-format="yyyy-MM-dd HH:mm:ss"
          size="small"
          type="monthrange"
          range-separator="-"
          start-placeholder="开始月份"
          end-placeholder="结束月份"
        ></el-date-picker>
      </el-form-item>
      <el-form-item class="right">
        <el-button plain  size="mini" @click="resetQuery">重置</el-button>
        <el-button type="primary"  size="mini" @click="handleQuery">搜索</el-button>
      </el-form-item>
      <br>
      <el-form-item>
        <el-button
          plain
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['monthlyStatistics:role:export']"
        >导出</el-button>
        <el-button
          plain
          size="mini"
          :loading="exportLoading"
          @click="handleExport2"
          v-hasPermi="['monthlyStatistics2:role:export']"
        >上月全量导出</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="adminList" border>
      <el-table-column label="序号" align="left" prop="" show-overflow-tooltip >
        <template slot-scope="scope">
         {{scope.$index + 1}}
        </template>
      </el-table-column>
      <el-table-column label="姓名" align="left" prop="userName"  show-overflow-tooltip />
      <el-table-column label="部门" align="left" prop="dept"  show-overflow-tooltip >
        <template slot-scope="scope">
         {{JSON.parse(scope.row.dept).name}}
        </template>
      </el-table-column>
      <el-table-column label="手机号" align="left" prop="contacts" show-overflow-tooltip />
      <el-table-column label="充值金额（元）" align="left" prop="camt" show-overflow-tooltip >
        <template slot-scope="scope">
          <span>{{Number(scope.row.camt).toFixed(2) || "0.00"}}</span>
        </template>
      </el-table-column>
      <el-table-column label="消费金额（元）" align="left" prop="damt" show-overflow-tooltip >
        <template slot-scope="scope">
          <span>{{Number(scope.row.damt).toFixed(2) || "0.00"}}</span>
        </template>
      </el-table-column>
      <el-table-column label="余额（元）" align="left" prop="balance" show-overflow-tooltip />
      
      <el-table-column label="时间" align="left" prop="creTime"  show-overflow-tooltip />
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.current"
      :limit.sync="queryParams.size"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listDetal, exportDetail } from "@/api/recharge/monthlyStatistics";
import { getLastMonthStartDate, getLastMonthEndDate } from "@/assets/js/dataFormate";
export default {
  name: "admin",
  data() {
    return {
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 参数表格数据
      adminList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        current: 1,
        size: 10,
        nameOrPhone: undefined,
        startTime:undefined,
        endTime:undefined,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    //强制el-input刷新
    onInput(){
        this.$forceUpdate();
    },
    /** 查询参数列表 */
    getList() {
      this.loading = true;
      listDetal(this.addDateRange(this.queryParams,this.dateRange,'section')).then(response => {
          this.adminList = response.data.records;
          this.total = response.data.total;
          this.loading = false;
        }
      );
    },
    // 取消按钮
    cancel() {
      this.open = false;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.current = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.queryParams.nameOrPhone = undefined;
      this.queryParams.startTime = undefined;
      this.queryParams.endTime = undefined;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      if(this.dateRange.length>0){
        this.queryParams.startTime = this.dateRange[0]
        this.queryParams.endTime = this.dateRange[1]
      }
      let queryParams = {...this.queryParams};
      delete queryParams.current
      delete queryParams.size
      this.exportLoading = true;
      exportDetail(queryParams).then(response =>{
        this.exportLoading = false;
        localStorage.setItem('fileExportId', response.data)
        this.$router.push({path:'/recharge/fileExport'})
      })
    },
    /** 导出按钮操作 */
    handleExport2() {
      exportDetail({startTime:getLastMonthStartDate(),endTime:getLastMonthEndDate()}).then(response =>{
        this.exportLoading = false;
        localStorage.setItem('fileExportId', response.data)
        this.$router.push({path:'/recharge/fileExport'})
      })
    }
  }
};
</script>
