<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="" prop="date">
        <el-date-picker clearable
          v-model="queryParams.date"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择">
        </el-date-picker>
      </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-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-refresh"
          size="mini"
          @click="handleRefreshToday"
          v-hasPermi="['cai:dayIncomeStatistics:edit']"
        >重新统计当天数据</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-refresh"
          size="mini"
          @click="handleRefreshLastday"
          v-hasPermi="['cai:dayIncomeStatistics:edit']"
        >重新统计昨天数据</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dayIncomeStatisticsList" @selection-change="handleSelectionChange">
      <el-table-column label="日期" align="center" prop="date" width="90" />
      <el-table-column label="充值金额" align="center" prop="expInMoney" />
      <el-table-column label="充值笔数" align="center" prop="orderCount" />
      <el-table-column label="提现金额" align="center" prop="outMoney" />
      <el-table-column label="打款笔数" align="center" prop="cashCount" />
      <el-table-column label="vip收入" align="center" prop="vipInMoney" />
      <el-table-column label="vip笔数" align="center" prop="vipCount" />
      <el-table-column label="当日差额" align="center" prop="diff">
        <template v-slot="scope">
          <span :class="scope.row.diff >= 0 ? 'font-red': 'font-green' ">{{ scope.row.diff }}</span>
        </template>
      </el-table-column>
      <el-table-column label="手动加余额" align="center" prop="modifyCoinAdd" />
      <el-table-column label="手动减余额" align="center" prop="modifyCoinSub" />
      <el-table-column label="手动加收益" align="center" prop="modifyIncomeAdd" />
      <el-table-column label="手动减收益" align="center" prop="modifyIncomeSub" />
      <el-table-column label="最近更新时间" align="center" prop="updateTime" width="160"/>
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template v-slot="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
          >修改</el-button>
        </template>
      </el-table-column>-->
    </el-table>

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

<script>
import {
  listDayIncomeStatistics,
  refreshLastDayDayIncomeStatistics,
  refreshTodayDayIncomeStatistics
} from '@/api/cai/dayIncomeStatistics'

export default {
  name: "DayIncomeStatistics",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 每日账单统计表格数据
      dayIncomeStatisticsList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        date: undefined,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询每日账单统计列表 */
    getList() {
      this.loading = true;
      listDayIncomeStatistics(this.queryParams).then(response => {
        response.rows.forEach((value,index) => {
          value.diff = parseInt(value.expInMoney) + parseInt(value.vipInMoney) - parseInt(value.outMoney)
          value.modifyCoinAdd = value.modifyCoinAdd / 100
          value.modifyCoinSub = value.modifyCoinSub / 100
          value.modifyIncomeAdd = value.modifyIncomeAdd / 100
          value.modifyIncomeSub = value.modifyIncomeSub / 100
        })
        this.dayIncomeStatisticsList = response.rows
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    handleRefreshToday() {
      this.$modal.confirm('是否重新统计当天统计数据？').then(() => {
        this.loading = true;
        return refreshTodayDayIncomeStatistics();
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("刷新当天统计成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 修改按钮操作 */
    handleRefreshLastday(row) {
      this.$modal.confirm('是否重新统计昨天统计数据？').then(() => {
        this.loading = true;
        return refreshLastDayDayIncomeStatistics();
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("刷新昨天统计成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
  }
};
</script>
<style lang="scss" scoped>
.context-avatar-center {
  display: flex;
  align-items: center; /* 垂直居中 */
  justify-content: center; /* 水平居中 */
}
.font-red {
  color: red;
}
.font-green {
  color: green;
}
.font-blue {
  color: blue;
}
</style>
