<template>
  <div class="box">
    <div class="inquire">
      <span>公会ID:</span>
      <el-input v-model="formData.guildId" placeholder="" class="input" />
    </div>
    <div class="inquire">
      <span>公会长ID:</span>
      <el-input v-model="formData.ownerErbanNo" placeholder="" class="input" />
    </div>
    <div class="inquire">
      <span>主播ID:</span>
      <el-input v-model="formData.erbanNo" placeholder="" class="input" />
    </div>
    <div class="inquire">
      <span>周期</span>
      <el-select v-model="formData.cycleDate" placeholder="请选择" clearable>
        <el-option
          v-for="item in dateCycleArr"
          :key="item.cycleDate"
          :label="item.intervalFormatter"
          :value="item.cycleDate"
        >
        </el-option>
      </el-select>
    </div>
    <el-button style="" type="primary" @click="getData()">查询</el-button>
    <el-button style="" type="primary" @click="confirmExportExcel()"
      >导出</el-button
    >
    <!-- 表格数据 -->
    <el-table
      v-loading="tableData.loading"
      :data="tableData.data"
      ref="multipleTable"
      @selection-change="handleSelectionChange"
      border
      style="width: 100%; margin-top: 25px"
    >
      <el-table-column prop="guildId" align="center" label="公会ID" />
      <el-table-column prop="guildName" align="center" label="公会昵称" />
      <el-table-column prop="uid" align="center" label="主播UID" />
      <el-table-column prop="erbanNo" align="center" label="主播ID" />
      <el-table-column prop="nick" align="center" label="主播昵称" />
      <el-table-column prop="guildCrystalNum" align="center" label="清除紫水晶数" />
            <el-table-column align="center" prop="createTime" label="清除时间">
        <template v-slot="scope">{{
          dateFormat(scope.row.createTime)
        }}</template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      style="margin-top: 10px"
      class="paginationClass"
      :current-page="formData.pageNo"
      :page-size="formData.pageSize"
      :page-sizes="[10, 20, 50, 100, 200]"
      layout="sizes, prev, pager, next"
      :total="tableData.total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
export default {
  name: "amethystClearRecord",
};
</script>
<script setup>
import { ref, onMounted, reactive, computed } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
import {
  getGuildAmethystClearRecordList,
  exportClearAmethyst,
  getGuildPolicyCycleDates,
} from "@/api/SalaryDetails/SalaryDetails.js";
import { formatDate } from "@/utils/relDate";
const formData = reactive({
  pageNo: 1,
  pageSize: 10,
  erbanNo: "",
  guildId: "",
  ownerErbanNo: "",
  cycleDate: "",
});
const tableData = reactive({
  data: [],
  total: 0,
  loading: false,
});
const dateCycleArr = ref([]);
// 查询
const getData = () => {
  tableData.loading = true;
  getGuildAmethystClearRecordList(formData).then((res) => {
    if (res.code == 200) {
      tableData.data = res.data.rows;
      tableData.total = res.data.total;
      tableData.loading = false;
    } else {
      tableData.loading = false;
      ElMessage.error(res.message);
    }
  });
};
// 导出
const confirmExportExcel = async () => {
  // Object.assign(formData, { pageSize: 10000, pageNo: 1 });
  try {
    const res = await exportClearAmethyst(formData);
    if (res) {
      ElMessage({
        message: "导出成功",
        type: "success",
      });
      let time = formatDate(new Date());
      let alink = document.createElement("a");
      alink.download = `紫水晶清除记录${time}.xls`;
      alink.style.display = "none";
      const blob = new Blob([res]);
      alink.href = URL.createObjectURL(blob);
      document.body.appendChild(alink);
      alink.click();
      URL.revokeObjectURL(alink.href);
    }
  } catch (error) {
    ElMessage({
      message: error.message,
      type: "error",
    });
  }
};
    const dateFormat = (row) => {
      const date = new Date(row);
      return date.format("yyyy-MM-dd hh:mm:ss");
    }
const handleSizeChange = (val) => {
  formData.pageSize = val;
  getData();
};
const handleCurrentChange = (val) => {
  formData.pageNo = val;
  getData();
};
onMounted(() => {
  getGuildPolicyCycleDates().then((res) => {
    if (res.code == 200) {
      dateCycleArr.value = res.data;
    } else {
      ElMessage({
        showClose: true,
        message: res.message,
        type: "error",
      });
    }
  });
});
</script>

<style lang="less" scoped>
.box {
  padding-top: 20px;
  background: #ecf0f5;

  .inquire {
    display: inline-block;
    margin-right: 20px;

    span {
      margin-right: 10px;
    }

    .input {
      width: 180px;
      margin-right: 10px;
    }
  }

  .dialogTableVisibleBut {
    display: block;
    margin: 30px 0 0 830px;
  }

  .paginationClass {
    margin: 15px 0 5px 0px;
  }
}
.selectBox {
  display: flex;
  height: 35px;
  line-height: 35px;
  margin-bottom: 20px;
}

.selectBoxImg {
  height: 150px;
}
</style>
