<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="countDate">
        <el-date-picker clearable
                        v-model="queryParams.countDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="统计类型" prop="dataType">
        <el-select v-model="queryParams.dataType" clearable size="small">
          <el-option
              v-for="dict in unionTotalDataTypeList"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
              @keyup.enter.native="handleQuery"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="工会" prop="unionId">
        <el-select v-model="queryParams.unionId" clearable size="small">
          <el-option
              v-for="dict in unionList"
              :key="dict.id"
              :label="dict.name"
              :value="dict.id"
              @keyup.enter.native="handleQuery"
          />
        </el-select>
      </el-form-item>
<!--      <el-form-item label="工会" prop="unionName">
        <el-input
            v-model="queryParams.unionName"
            placeholder="请输入工会"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </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">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="unionTotalList" @selection-change="handleSelectionChange" @sort-change="handleSortChange">
      <el-table-column label="统计类型" align="center" prop="dataType">
        <template v-slot="scope">
          <cai-dict-tag :options="unionTotalDataTypeList" :value="scope.row.dataType"/>
        </template>
      </el-table-column>
      <el-table-column label="时间" align="center" prop="countDate" width="180"/>
      <el-table-column label="工会名称" align="center" prop="unionName" />
      <el-table-column label="工会主播收入" align="center" prop="anchorEarningsTotal" sortable="custom" :sort-orders="['descending', 'ascending']"/>
      <el-table-column label="工会收益" align="center" prop="unionEarningsTotal" sortable="custom" :sort-orders="['descending', 'ascending']"/>
      <el-table-column label="统计时间" align="center" prop="refreshTime" width="180"/>
    </el-table>

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

<script>
import {listUnionTotal, unionList} from "@/api/cai/unionTotal";
import {unionTotalDataTypeList} from "@/constant/statusMap";

export default {
  name: "UnionTotal",
  data() {
    return {
      unionTotalDataTypeList,
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 工会每日收益表格数据
      unionTotalList: [],
      unionList:[],
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderByColumn: undefined,
        isAsc: undefined,
        countDate: undefined,
        dataType: undefined,
        unionId: undefined,
        unionName: undefined
      },
    };
  },
  created() {
    this.getList();
    this.queryUnionList();
  },
  methods: {
    /** 查询工会每日收益列表 */
    getList() {
      this.loading = true;
      listUnionTotal(this.queryParams).then(response => {
        this.unionTotalList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    queryUnionList(){
      unionList().then(respon => {
        this.unionList = respon.data
      })
    },
    handleSortChange(column, prop, order) {
      this.queryParams.orderByColumn = column.prop;
      this.queryParams.isAsc = column.order;
      this.getList();
    },
    /** 搜索按钮操作 */
    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
    },
  }
};
</script>
