<template>
  <div class="app-container">
    <el-form
      @submit.native.prevent
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="用户名称" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入用户名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号码" prop="phonenumber">
        <el-input
          v-model="queryParams.phonenumber"
          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">
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="addConference"
          >新增参会人
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="deleteConference"
          >删除参会人
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-close"
          size="mini"
          @click="close()"
          v-hasPermi="['system:detailes:close']"
          >关闭
        </el-button>
      </el-col>
    </el-row>

    <el-table
      stripe
      :cell-style="cellStyle"
      v-loading="loading"
      :data="conference_detailsList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="用户ID" align="center" prop="userId" />
      <el-table-column label="用户姓名" align="center" prop="userName" />
      <el-table-column label="所属部门" align="center" prop="deptName" />
      <el-table-column label="电话号码" align="center" prop="phonenumber" />
      <el-table-column label="邮箱" align="center" prop="email" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="300px"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="deleteConference(scope.row)"
            v-hasPermi="['system:conference:remove']"
            >删除
          </el-button>
          <!--       <el-table-column label="状态" align="center" prop="state" />-->
          <!--            <el-table-column label="状态" align="center" prop="state">-->
          <!--              <template slot-scope="scope">-->
          <!--                <dict-tag-->
          <!--                  :options="dict.type.whether_to_attend"-->
          <!--                  :value="scope.row.state"-->
          <!--                />-->
          <!--              </template>-->
          <!--            </el-table-column>-->
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <select-user
      ref="select"
      @refreshList="refreshList()"
      :id="queryParams.id"
      @ok="handleQuery"
    />
  </div>
</template>

<script>
import { listJoin } from "@/api/smartSchool/conferenceManage/participants";
import { CustomCellStyle } from "@/enums/customStyle";
import selectUser from "./selectUser";
import { updatePersonnel } from "@/api/smartSchool/conferenceManage/selectParticipants";
import { deleteJoin } from "@/api/smartSchool/conferenceManage/participants";
import { delConference } from "@/api/smartSchool/conferenceManage/conference";

export default {
  name: "Conference_details",
  dicts: ["whether_to_attend"],
  components: { selectUser },
  created() {
    this.conferenceId = this.$route.query && this.$route.query.id;
    this.getList();
  },
  data() {
    return {
      // 路由传来的会议ID
      conferenceId: undefined,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 参会人信息表格数据
      conference_detailsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        userId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      cellStyle: CustomCellStyle,
    };
  },

  methods: {
    // closeCurrentTab,
    /** 查询参会人信息列表 */
    getList() {
      this.loading = true;
      listJoin(this.queryParams, this.conferenceId).then((response) => {
        this.conference_detailsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        conferenceId: null,
        userId: null,
        name: null,
        state: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    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;
    },
    // 关闭按钮
    close() {
      const path = { path: "/conferenceManage/conferenceInformation" };
      this.$tab.closeOpenPage(path);
      // this.open = false;
      // this.reset();
    },
    addConference() {
      this.$refs.select.visible = true;

      this.$refs.select.getList();
    },
    deleteConference(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm(
          `是否确认删除选中的${
            Object.hasOwnProperty.call(ids, "length") ? ids.length : 1
          }条数据？`
        )
        .then(function () {
          return deleteJoin(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },

    refreshList() {
      this.getList();
    },
  },
};
</script>
