<template>
  <div class="box">
    <!-- 查询 -->
    <div class="inquire">
      <span>分区</span>
      <el-select v-model="inquire.partitionId" placeholder="请选择">
        <el-option
          v-for="item in inquire.partitionArr"
          :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.userId"
        placeholder=""
        class="input"
      ></el-input>
    </div>
    <div class="inquire">
      <span>状态</span>
      <el-select v-model="inquire.status" placeholder="请选择">
        <el-option
          v-for="item in inquire.statusArr"
          :key="item.id"
          :label="item.desc"
          :value="item.id"
        >
        </el-option>
      </el-select>
    </div>
    <!-- 时间选择器 -->
    <div class="inquire">
      <div class="block">
        <span class="demonstration">日期</span>
        <el-date-picker
          v-model="inquire.time"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
      </div>
    </div>
    <!-- 查询按钮 -->
    <el-button class="primary" type="primary" @click="getData()"
      >查询</el-button
    >
    <el-button class="primary" type="primary" @click="addDialog = true"
      >重置搜索</el-button
    >

    <!-- 表格 -->
    <el-table
      v-loading="loading"
      :data="tableData"
      border
      style="width: 100%; margin-top: 25px"
    >
      <el-table-column prop="id" align="center" label="序号" />
      <el-table-column prop="guildId" align="center" label="公会ID" />
      <el-table-column prop="erbanNo" align="center" label="公会长ID" />
      <el-table-column prop="nick" align="center" label="公会长昵称" />
      <el-table-column align="center" prop="giftInfo" label="公会长头像">
        <template v-slot="scope">
          <el-image
            style="width: 100px; height: 100px"
            :src="scope.row.avatar"
            :zoom-rate="1.1"
            :preview-src-list="[scope.row.avatar]"
            fit="scale-down"
            preview-teleported="true"
            hide-on-click-modal="true"
          />
        </template>
      </el-table-column>
      <el-table-column prop="guildName" align="center" label="公会昵称" />
      <el-table-column align="center" prop="giftInfo" label="公会头像">
        <template v-slot="scope">
          <el-image
            style="width: 100px; height: 100px"
            :src="scope.row.guildAvatar"
            :zoom-rate="1.1"
            :preview-src-list="[scope.row.guildAvatar]"
            fit="scale-down"
            preview-teleported="true"
            hide-on-click-modal="true"
          />
        </template>
      </el-table-column>
      <el-table-column
        prop="guildContact"
        align="center"
        label="公会联系方式"
      />
      <el-table-column align="center" prop="idCard" label="公会长身份证件">
        <!-- <template v-slot="scope">
          <el-image
            style="width: 100px; height: 100px"
            :src="scope.row.idCard"
            :zoom-rate="1.1"
            :preview-src-list="[scope.row.idCard]"
            fit="scale-down"
            preview-teleported="true"
            hide-on-click-modal="true"
          />
        </template> -->
      </el-table-column>
      <el-table-column prop="inviteErbanNo" align="center" label="邀请人ID" />
      <el-table-column prop="inviteCheck" align="center" label="邀请人证明">
        <template v-slot="scope">
          <el-image
            style="width: 100px; height: 100px"
            :src="scope.row.inviteCheck"
            :zoom-rate="1.1"
            :preview-src-list="[scope.row.inviteCheck]"
            fit="scale-down"
            preview-teleported="true"
            hide-on-click-modal="true"
          />
        </template>
      </el-table-column>
      <el-table-column prop="applyTime" align="center" label="申请时间" />
      <el-table-column prop="auditStatus" align="center" label="状态">
        <template v-slot="scope">
          {{
            scope.row.auditStatus == 0
              ? "未审核"
              : scope.row.auditStatus == 1
              ? "已通过"
              : "拒绝"
          }}
        </template>
      </el-table-column>
      <el-table-column prop="x" align="center" label="操作人" />
      <el-table-column align="center" label="操作">
        <template v-slot="scope">
          <el-button
            v-show="scope.row.auditStatus == 0"
            @click="agree(scope.row.id)"
            type="text"
            size="default"
            >同意</el-button
          >
          <el-button
            v-show="scope.row.auditStatus == 0"
            @click="refuse(scope.row.id)"
            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-model="delDialog" title="提示" width="30%" center>
      <span> 确定要解散该公会吗?</span>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="delDialog = false">取消</el-button>
          <el-button type="primary" @click="delClick()"> 确认 </el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>
<script>
import {
  listPartitionInfo,
  guildApplyList,
  guildApplyAudit,
} from "@/api/nobleman/nobleman";
// @ts-ignore
import { dateFormat } from "@/utils/system-helper";
// @ts-ignore
import { ElMessage } from "element-plus";
export default {
  name: "newGuildApplication",
  data() {
    return {
      loading: false,
      //查询所需条件对象
      inquire: {
        partitionId: "",
        partitionArr: [],
        userId: "",
        status: -1,
        statusArr: [
          { desc: "未审核", id: 0 },
          { desc: "全部", id: -1 },
          { desc: "通过", id: 1 },
          { desc: "已拒绝", id: 2 },
        ],
        time: "",
      },
      // 表格
      tableData: [],
      //   新增弹窗
      addDialog: false,
      // 分页
      total: 10, //总页数
      currentPage: 1, //页码
      pageSize: 10, //条数
    };
  },
  created() {
    listPartitionInfo().then((res) => {
      console.log(res.data);
      this.inquire.partitionArr = res.data;
      this.inquire.partitionId = this.inquire.partitionArr[0].id;
    });
  },
  methods: {
    // 查询接口
    getData() {
      this.loading = true;
      let time = this.inquire.time;
      let startTime = "";
      let endTime = "";
      if (time && time.length > 0) {
        startTime = dateFormat(this.inquire.time[0], "yyyy-MM-dd hh:mm:ss");
        endTime = dateFormat(this.inquire.time[1], "yyyy-MM-dd hh:mm:ss");
      }
      guildApplyList({
        partitionId: this.inquire.partitionId,
        erbanNo: this.inquire.userId,
        auditStatus: this.inquire.status,
        startDate: startTime,
        endDate: endTime,
        pageNo: this.currentPage,
        pageSize: this.pageSize,
      }).then((res) => {
        if (res.code == 200) {
          this.total = res.data.total;
          this.tableData = res.data.rows;
          this.loading = false;
        } else {
          ElMessage({
            showClose: true,
            message: res.message,
            type: "error",
          });
        }
      });
    },
    agree(id) {
      guildApplyAudit({
        auditStatus: 1,
        id,
      }).then((res) => {
        if (res.code == 200) {
          this.getData();
        } else {
          ElMessage({
            showClose: true,
            message: res.message,
            type: "error",
          });
        }
      });
    },
    refuse(id) {
      guildApplyAudit({
        auditStatus: 2,
        id,
      }).then((res) => {
        if (res.code == 200) {
          this.getData();
        } else {
          ElMessage({
            showClose: true,
            message: res.message,
            type: "error",
          });
        }
      });
    },
    beforeAvatarUpload() {
      ElMessage({
        showClose: true,
        message: "上传中~",
        type: "warning",
      });
    },
    handleAvatarError() {
      ElMessage({
        showClose: true,
        message: "上传失败！",
        type: "error",
      });
    },
    handleAvatarSuccess2(res, file) {
      this.ediObj.imageUrl2 = file.response.data;
      ElMessage({
        showClose: true,
        message: "上传成功！",
        type: "success",
      });
    },
    handleAvatarSuccess(res, file) {
      this.ediObj.imageUrl1 = file.response.data;
      ElMessage({
        showClose: true,
        message: "上传成功！",
        type: "success",
      });
    },
    // 分页导航
    handleSizeChange() {
      this.getData();
    },
    handleCurrentChange() {
      this.getData();
    },
  },
};
</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>
