<template>
  <div>
    <!-- 搜索条件 -->
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="姓名">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入"
          clearable
        ></el-input>
      </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-table border ref="table" :data="tableData">
      <el-table-column align="center" type="index" label="序号" width="55" />
      <el-table-column align="center" prop="name" label="姓名" />
      <el-table-column align="center" prop="sex" label="性别" />
      <el-table-column align="center" prop="grade" label="级部" />
      <el-table-column align="center" prop="classes" label="班级" />
      <el-table-column align="center" prop="phone" label="联系电话" />
      <el-table-column align="center" prop="cardid" label="身份证号" />
      <el-table-column align="center" prop="hobby" label="兴趣爱好" />
      <el-table-column align="center" prop="reason" label="申请理由" />
      <el-table-column align="center" prop="status" label="审核状态">
        <template slot-scope="{ row }">
          {{
            row.status == 1
              ? "未审核"
              : row.flg == 2
              ? "同意"
              : row.status == 3
              ? "不同意"
              : ""
          }}
        </template>
      </el-table-column>
      <el-table-column align="center" fixed="right" label="操作">
        <template slot-scope="scope">
          <div v-if="scope.row.status === '1'">
            <el-button @click="handleAgree(scope.row)" type="text" size="small"
              >同意</el-button
            >
            <el-button
              @click="handleDisagree(scope.row)"
              type="text"
              size="small"
              >不同意</el-button
            >
          </div>
          <el-button @click="handQuery(scope.row)" type="text" size="small"
            >查看</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <!-- 弹窗 -->
    <el-dialog
      :title="title"
      :visible.sync="dialogTableVisible"
      width="66%"
      show-close
    >
      <el-form :model="form" ref="form" size="small" label-width="108px">
        <el-row>
          <el-col :span="10">
            <el-form-item label="姓名">
              <el-input v-model="form.name"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="性别">
              <el-input v-model="form.sex"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="10">
            <el-form-item label="级部">
              <el-input v-model="form.grade"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="班级">
              <el-input v-model="form.classes"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="10">
            <el-form-item label="联系电话">
              <el-input v-model="form.phone"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="身份证号">
              <el-input v-model="form.cardid"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="10">
            <el-form-item label="兴趣爱好">
              <el-input v-model="form.hobby"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="申请理由">
              <el-input v-model="form.reason"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="10">
            <el-form-item label="审核状态">
              <el-input v-model="form.status"> </el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>

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

<script>
import {
  getsigninInfo, // 查询社团报名审核列表
  listsigninInfo, // 获取社团报名审核详细信息
  allowsignin, // 同意社团申请审批
} from "@/api/smartSchool/MassOrganization/singninInfo";
export default {
  name: "clubRegistrationReview",
  data() {
    return {
      cat: "",
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: "",
        classes: "",
        grade: "",
      },
      //表格数据
      tableData: [],
      title: "",
      // 弹窗
      form: {
        id: "",
        name: "",
        sex: "",
        cardid: "",
        grade: "",
        classes: "",
        orgName: "",
        orgPosition: "",
        phone: "",
        status: "",
      },
      // 总计
      total: 0,
      single: false, // 添加 single 属性并设置初始值
      multiple: false,
      dialogTableVisible: false,
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    // 搜索
    getList() {
      const params = {
        cid: this.$route.query.id,
        name: this.queryParams.name,
        grade: this.queryParams.grade,
        classes: this.queryParams.classes,
      };
      getsigninInfo(params).then((response) => {
        this.tableData = response.rows;
        this.total = response.total;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.throttle(() => {
        this.queryParams.pageNum = 1;
        this.getList();
      });
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        name: "",
      };
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 表单重置
    reset() {
      this.form = {};
      this.resetForm("form");
    },
    // 查看
    handQuery(row) {
      //   console.log(row, "查看row");
      this.reset();
      const ids = row.id;
      this.title = "社团报名审核";
      this.dialogTableVisible = true;
      listsigninInfo(ids).then((response) => {
        if (response.data && response.data.name) {
          this.form = response.data;
          this.form.status = response.data.status;
          this.cat = this.form.status;
          if (this.cat === "1") {
            this.form.status = "未审核";
          } else if (this.cat === "2") {
            this.form.status = "同意";
          } else if (this.cat === "3") {
            this.form.status = "不同意";
          }
        }
      });
    },
    // 同意
    handleAgree(row) {
      console.log(row, "同意row");
      this.$confirm("确定同意吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.reset();
        const params = {
          id: row.id,
          status: "2",
        };
        console.log(params);
        allowsignin(params).then((response) => {
          console.log("response", response);
          this.$modal.msgSuccess("操作成功");
          this.getList();
          this.title = "社团申请审批";
        });
      });
    },

    // 不同意
    handleDisagree(row) {
      this.$confirm("确定不同意吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.reset();
        const params = {
          id: row.id,
          status: "3",
        };
        console.log(params);
        allowsignin(params).then((response) => {
          console.log("response", response);
          this.$modal.msgSuccess("操作成功");
          this.getList();
          this.title = "社团申请审批";
        });
      });
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
  },
};
</script>

<style lang="scss" scoped>
.el-form {
  margin-top: 15px;
  margin-left: 10px;
}

.el-table {
  margin-left: 10px;
}
</style>
