<template>
  <div class="box">
    <!-- 查询 -->
    <div class="inquire">
      <span>分区</span>
      <el-select filterable v-model="inquire.partitionId" placeholder="请选择">
        <el-option
          v-for="item in inquire.options"
          :key="item.id"
          :label="item.desc"
          :value="item.id"
        >
        </el-option>
      </el-select>
    </div>
    <div class="inquire">
      <span>房间ID:</span>
      <el-input
        v-model="inquire.roomId"
        placeholder=""
        class="input"
      ></el-input>
    </div>
    <div class="inquire">
      <span>BOOM等级:</span>
      <el-input
        v-model="inquire.boomLevel"
        placeholder=""
        class="input"
      ></el-input>
    </div>
    <div class="inquire">
      <span>触发者ID：</span>
      <el-input
        v-model="inquire.triggererId"
        placeholder=""
        class="input"
      ></el-input>
    </div>
    <div class="inquire">
      <div class="block">
        <span class="demonstration">开始时间</span>
        <el-date-picker
          v-model="inquire.time[0]"
          type="datetime"
          placeholder="开始时间"
        >
        </el-date-picker>
      </div>
    </div>
    <div class="inquire">
      <div class="block">
        <span class="demonstration">结束时间</span>
        <el-date-picker
          v-model="inquire.time[1]"
          type="datetime"
          placeholder="结束时间"
        >
        </el-date-picker>
      </div>
    </div>

    <!-- 查询按钮 -->
    <el-button class="primary but" type="primary" @click="getData()"
      >查询</el-button
    >
    <el-button
      class="primary"
      type="primary"
      @click="
        inquire.partitionId = inquire.options[0].id;
        inquire.roomId = '';
        inquire.boomLevel = '';
        inquire.triggererId = '';
        inquire.time = [];
        getData();
      "
      >重置查询</el-button
    >
    <el-button
      class="primary"
      type="primary"
      @click="diamondStatisticsExportFun()"
      >导出</el-button
    >

    <!-- 表格 -->
    <el-table
      v-loading="loading"
      :data="tableData"
      border
      style="width: 100%; margin-top: 25px"
    >
      <el-table-column prop="cycleDate" align="center" label="日期" />
      <el-table-column prop="roomErbanNo" align="center" label="房间ID" />
      <el-table-column prop="level" align="center" label="Boom等级" />
      <el-table-column prop="erbanNo" align="center" label="触发者ID" />
      <el-table-column prop="drawTime" align="center" label="触发时间" />
      <el-table-column prop="num" align="center" label="参与用户数" />
      <el-table-column prop="awardNum" align="center" label="发放奖励数" />
      <el-table-column prop="ownerGold" align="center" label="获得金币数" />
      <el-table-column align="center" label="操作" width="300">
        <template v-slot="scope">
          <el-button
            @click="
              memberVal = scope.row;
              detailListFun();
            "
            type="text"
            size="default"
            >贡献及获奖明细</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      style="margin-top: 10px"
      class="paginationClass"
      v-model:current-page="currentPage"
      v-model:page-size="pageSize"
      :page-sizes="[10, 20, 30, 40, 50, 100, 200, 300, 400, 500, 999999999]"
      layout="sizes, prev, pager, next"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
    <!-- 贡献或获奖明细 -->
    <el-dialog
      v-loading="loading2"
      v-model="memberDialog"
      title="贡献或获奖明细"
      center
    >
      <!-- 内嵌表格 -->
      <el-table
        :data="member.tableData"
        border
        style="width: 100%; margin-top: 25px"
      >
        <el-table-column prop="roleType" align="center" label="角色">
          <template v-slot="scope">
            {{
              scope.row.roleType == 1
                ? "房主"
                : scope.row.roleType == 2
                ? "贡献榜1"
                : scope.row.roleType == 3
                ? "贡献榜2"
                : scope.row.roleType == 4
                ? "贡献榜3"
                : scope.row.roleType == 5
                ? "boom触发者"
                : scope.row.roleType == 6
                ? "房内普通用户"
                : ""
            }}
          </template>
        </el-table-column>
        <el-table-column prop="erbanNo" align="center" label="用户ID" />
        <el-table-column prop="nick" align="center" label="用户昵称" />
        <el-table-column prop="exper" align="center" label="贡献值" />
        <el-table-column prop="level" align="center" label="Boom等级" />
        <el-table-column prop="awardType" align="center" label="奖品类型">
          <template v-slot="scope">
            {{
              scope.row.awardType == 8
                ? "金币"
                : scope.row.awardType == 6
                ? "礼物"
                : scope.row.awardType == 5
                ? "座驾"
                : scope.row.awardType == 1
                ? "头饰"
                : scope.row.awardType == 3
                ? "气泡"
                : scope.row.awardType == 10
                ? "VIP"
                : scope.row.awardType == 11
                ? "勋章"
                : "铭牌"
            }}
          </template>
        </el-table-column>
        <el-table-column prop="awardName" align="center" label="获得奖励" />
        <el-table-column prop="awardNum" align="center" label="获得奖励数" />
        <el-table-column
          prop="createTime"
          align="center"
          label="奖励发放时间"
        />
      </el-table>
      <!-- 分页 -->
      <el-pagination
        style="margin-top: 10px"
        class="paginationClass"
        v-model:current-page="currentPage2"
        v-model:page-size="pageSize2"
        :page-sizes="[10, 20, 30, 40, 50, 100, 200, 300, 400, 500, 999999999]"
        layout="sizes, prev, pager, next"
        :total="total2"
        @size-change="handleSizeChange2"
        @current-change="handleCurrentChange2"
      />
      <template #footer>
        <span class="dialog-footer">
          <el-button type="primary" @click="memberDialog = false">
            关闭
          </el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>
<script>
import {
  listPartitionInfo,
  recordList,
  detailList,
  recordExport,
} from "@/api/boom/boom";
// @ts-ignore
import { dateFormat } from "@/utils/system-helper";
// @ts-ignore
import { ElMessage } from "element-plus";
export default {
  name: "recordData",
  data() {
    return {
      loading: false,
      loading2: false,
      //查询所需条件对象
      inquire: {
        partitionId: 2,
        options: [],
        roomId: "",
        boomLevel: "",
        triggererId: "",
        time: [],
      },
      // 表格
      tableData: [],
      // 内嵌表格
      memberDialog: false,
      memberVal: null,
      member: {
        tableData: [],
      },
      //   新增弹窗
      addDialog: false,
      // 分页
      total: 0, //总页数
      currentPage: 1, //页码
      pageSize: 10, //条数
      // 分页
      total2: 0, //总页数
      currentPage2: 1, //页码
      pageSize2: 10, //条数
    };
  },
  created() {
    listPartitionInfo().then((res) => {
      this.inquire.options = res.data;
      this.inquire.partitionId = res.data[0].id;
      this.getData();
    });
  },
  methods: {
    // 查询接口
    getData() {
      this.loading = true;
      let time = this.inquire.time;
      let startTime = null;
      let endTime = null;
      if (time.length > 0) {
        startTime = this.inquire.time[0]
          ? dateFormat(this.inquire.time[0], "yyyy-MM-dd hh:mm:ss")
          : null;
        endTime = this.inquire.time[1]
          ? dateFormat(this.inquire.time[1], "yyyy-MM-dd hh:mm:ss")
          : null;
      }
      recordList({
        partitionId: this.inquire.partitionId,
        erbanNo: this.inquire.triggererId,
        level: this.inquire.boomLevel,
        roomErbanNo: this.inquire.roomId,
        startTime: startTime,
        endTime: endTime,
        pageNo: this.currentPage,
        pageSize: this.pageSize,
      }).then((res) => {
        if (res.code == 200) {
          this.total = res.data.total;
          this.tableData = res.data.records;
          this.loading = false;
        } else {
          ElMessage({
            showClose: true,
            message: res.message,
            type: "error",
          });
        }
      });
    },
    // 详细弹窗
    detailListFun() {
      this.loading2 = true;
      let time = this.inquire.time;
      let startTime = null;
      let endTime = null;
      if (time.length > 0) {
        startTime = this.inquire.time[0]
          ? dateFormat(this.inquire.time[0], "yyyy-MM-dd hh:mm:ss")
          : null;
        endTime = this.inquire.time[1]
          ? dateFormat(this.inquire.time[1], "yyyy-MM-dd hh:mm:ss")
          : null;
      }
      detailList({
        partitionId: this.inquire.partitionId,
        signId: this.memberVal.signId,
        level: this.memberVal.level,
        startTime: startTime,
        endTime: endTime,
        pageNo: this.currentPage2,
        pageSize: this.pageSize2,
      }).then((res) => {
        if (res.code == 200) {
          this.total2 = res.data.total;
          this.member.tableData = res.data.records;
          this.memberDialog = true;
          this.loading2 = false;
        } else {
          ElMessage({
            showClose: true,
            message: res.message,
            type: "error",
          });
        }
      });
    },
    diamondStatisticsExportFun() {
      let time = this.inquire.time;
      let startTime = "";
      let endTime = "";
      if (time.length > 0) {
        startTime = this.inquire.time[0]
          ? dateFormat(this.inquire.time[0], "yyyy-MM-dd hh:mm:ss")
          : "";
        endTime = this.inquire.time[1]
          ? dateFormat(this.inquire.time[1], "yyyy-MM-dd hh:mm:ss")
          : "";
      }
      recordExport({
        partitionId: this.inquire.partitionId,
        erbanNo: this.inquire.triggererId,
        level: this.inquire.boomLevel,
        roomErbanNo: this.inquire.roomId,
        startTime: startTime,
        endTime: endTime,
      }).then();
    },
    // 分页详情导航
    handleSizeChange2() {
      this.detailListFun();
    },
    handleCurrentChange2() {
      this.detailListFun();
    },
    // 分页导航
    handleSizeChange() {
      this.getData();
    },
    handleCurrentChange() {
      this.getData();
    },
  },
};
</script>
<style lang="less" scoped>
.box {
  padding-top: 20px;
  background: #ecf0f5;
  .inquire {
    display: inline-block;
    margin-right: 20px;
    margin-bottom: 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>
