<template>
  <!-- 授权用户 -->
  <el-dialog
    title="选择用户"
    :visible.sync="visible"
    width="800px"
    top="5vh"
    append-to-body
    custom-class="el-dialog3"
  >
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
      <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>
      <el-table @row-click="clickRow" ref="table" :data="userList" @selection-change="handleSelectionChange" height="260px">
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column label="用户名称" prop="userName" :show-overflow-tooltip="true" />
        <el-table-column label="用户昵称" prop="nickName" :show-overflow-tooltip="true" />
        <el-table-column label="邮箱" prop="email" :show-overflow-tooltip="true" />
        <el-table-column label="手机" prop="phonenumber" :show-overflow-tooltip="true" />
        <el-table-column label="状态" align="center" prop="status">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/>
          </template>
        </el-table-column>
        <el-table-column label="创建时间" align="center" prop="createTime" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-row>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="handleSelectUser">确 定</el-button>
      <el-button @click="visible = false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { unallocatedUserList, groupUserSelectAll } from "@/api/doc/groupUser";
export default {
  dicts: ["sys_normal_disable"],
  props: {
    // 角色编号
    groupId: {
      type: [String],
    },
  },
  data() {
    return {
      // 遮罩层
      visible: false,
      // 选中数组值
      userIds: [],
      // 总条数
      total: 0,
      // 未授权用户数据
      userList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        groupId: undefined,
        // userName: undefined,
        // phonenumber: undefined
      },
    };
  },
  methods: {
    // 显示弹框
    show() {
      this.queryParams.groupId = parseInt(this.groupId);
      this.getList();
      this.visible = true;
    },
    clickRow(row) {
      this.$refs.table.toggleRowSelection(row);
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.userIds = selection.map((item) => item.userId);
    },
    // 查询表数据
    getList() {
      unallocatedUserList(this.queryParams).then((res) => {
        this.userList = res.rows;
        this.total = res.total;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 选择授权用户操作 */
    handleSelectUser() {
      const groupId = this.queryParams.groupId;
      const userIds = this.userIds.join(",");
      if (userIds == "") {
        this.$modal.msgError("请选择要分配的用户");
        return;
      }
      groupUserSelectAll({ groupId: groupId, userIds: userIds }).then((res) => {
        this.$modal.msgSuccess(res.msg);
        if (res.code === 200) {
          this.visible = false;
          this.$emit("ok");
        }
      });
    },
  },
};
</script>

<style scoped lang="scss">
//弹窗样式
::v-deep .el-dialog3 {
  width: calc(100vw * (1050 / 1920)) !important;
  height: calc(100vh * (900 / 1080)) !important;
  background: url(../../../assets/img/Group-585.png);
  background-size: calc(100vw * (1050 / 1920)) calc(100vh * (900 / 1080));
  //标题
  .el-dialog__title{
    color: #ffffff;
  }
  .dialog-footer {
      position: absolute;
      right: 8%;
      bottom: 5%;
    }
}
::v-deep .el-dialog .el-input {
  width: calc(100vw * (240 / 1920)) !important;
}
//表格
::v-deep .el-table {
  height: calc(100vh * (510 / 1080)) !important;
  width: calc(100vw * (855 / 1920)) !important;
  margin-left: calc(100vw * (20 / 1920)) !important;
  background: transparent;
  overflow: auto;
    //滚动条样式
::-webkit-scrollbar {
  width: 3.5px;
}
::-webkit-scrollbar-track {
  background-color: rgba(0, 0, 0, 0);
}
::-webkit-scrollbar-thumb {
  background: #2e8aec;
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: #2e8aec;
}

}
//搜索重置按钮颜色
::v-deep .el-button--primary,.el-button--mini{
  background-color: #002a5cff;
}
//关闭按钮
::v-deep .el-dialog__headerbtn{
 font-size: 25px;
 right: 3%;
}
//顶部和表格的距离
::v-deep .el-dialog .el-form-item{
 margin-top: calc(100vh * (30 / 1080)) !important;
}
//底部跳转
::v-deep .pagination-container .el-pagination{
  right: 10px;
}
</style>
