<template>
  <div>
    <el-dialog
      width="1000px"
      title="预约人员"
      :visible.sync="lookVisible"
      :before-close="onClose"
      append-to-body
    >
      <div>
        <el-form :inline="true" :model="searchForm">
          <el-form-item>
            <el-input
              v-model.trim="searchForm.search"
              clearable
              @keyup.enter.native="search"
              placeholder="学员编号/姓名/手机号"
            ></el-input>
          </el-form-item>
          <el-form-item prop="organId">
            <el-select
              v-model.trim="searchForm.organId"
              placeholder="请选择分部"
              clearable
              filterable
            >
              <el-option
                v-for="(item, index) in selects.branchs"
                :key="index"
                :value="item.id"
                :label="item.name"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="subjectId">
            <el-select
              v-model.trim="searchForm.subjectId"
              clearable
              filterable
              placeholder="请选择声部"
            >
              <el-option
                v-for="(item, index) in selects.subjects"
                :key="index"
                :value="item.id"
                :label="item.name"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button @click="search" type="primary">搜索</el-button>
            <el-button @click="onReSet" type="danger">重置</el-button>
            <el-button
              @click="onExport"
              type="primary"
              v-permission="'imLiveBroadcastRoom/exportReservationRoomUser'"
              >导出</el-button
            >
          </el-form-item>
        </el-form>
        <div class="tableWrap">
          <el-table
            style="width: 100%"
            :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
            :data="tableList"
            ref="multipleSelection"
          >
            <el-table-column
              align="center"
              prop="userId"
              label="编号"
            ></el-table-column>
            <el-table-column
              align="center"
              prop="username"
              label="姓名"
            ></el-table-column>
            <el-table-column
              align="center"
              prop="phone"
              label="手机号"
            ></el-table-column>
            <el-table-column
              align="center"
              prop="organName"
              label="分部"
            ></el-table-column>
            <el-table-column
              align="center"
              prop="subjectName"
              label="声部"
            ></el-table-column>
          </el-table>
          <pagination
            sync
            :total.sync="rules.total"
            :page.sync="rules.page"
            :limit.sync="rules.limit"
            :page-sizes="rules.page_size"
            @pagination="getList"
          />
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="onClose">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { getRoomUser } from "../api";
import { getLiveGoodsMapperList } from "@/views/liveShopManger/api";
import pagination from "@/components/Pagination/index";
import { Export } from "@/utils/downLoadFile";
export default {
  name: "eidtPostMsg",
  components: { pagination },
  data() {
    return {
      searchForm: {
        search: "",
        subjectId: "",
        organId: "",
      },
      tableList: [],
      organList: [],
      subjectList: [],
      rules: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
        page_size: [10, 20, 40, 50], // 选择限制显示条数
      },
      addMuiscVisible: false,
      multipleSelection: [],
      chioseIdList: [],
      isNewPage: false,
      lookVisible: false,
      activeRow: { sendFlag: false },
    };
  },

  mounted() {
    this.$store.dispatch("setBranchs");
    this.$store.dispatch("setSubjects");
  },
  methods: {
    async getList() {
      try {
        const res = await getRoomUser({
          ...this.searchForm,
          page: this.rules.page,
          rows: this.rules.limit,
          roomUid: this.activeRow.roomUid,
        });
        this.tableList = res.data.rows;
        this.rules.total = res.data.total;
      } catch (e) {
        console.log(e);
      }
    },
    search() {
      this.rules.page = 1;
      this.getList();
    },
    onReSet() {
      // this.searchForm.search = "";
      (this.searchForm = {
        search: "",
        subjectId: "",
        organId: "",
      }),
        this.search();
    },
    onClose() {
      this.lookVisible = false;
    },
    openDioag(row) {
      this.activeRow = row;
      this.lookVisible = true;

      this.getList();
    },
    async onExport() {

      await Export(
        this,
        {
          url: "/api-web/imLiveBroadcastRoom/exportReservationRoomUser",
          fileName: `${this.activeRow.roomTitle}预约人员.xls`,
          method: "post",
          params: { ...this.searchForm,roomUid: this.activeRow.roomUid, },
        },
        `您确定导出"${this.activeRow.roomTitle}"预约人员列表?`
      );
    },
  },
};
</script>
<style lang="scss" scoped>
.w100 {
  width: 100%;
}
.btnWrap {
  justify-content: flex-start;
}
</style>
