123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460 |
- <template>
- <el-dialog
- v-model="dialogVisible"
- title="人员选择"
- :width="type == 1 ? 680 : 460"
- destroy-on-close
- append-to-body
- @closed="$emit('closed')"
- draggable
- >
- <template v-if="type == 1">
- <div class="user-select">
- <div class="user-select__left">
- <div class="user-select__search">
- <el-input
- v-model="searchForm.name"
- prefix-icon="search"
- placeholder="搜索成员"
- >
- <template #append>
- <el-button
- icon="search"
- @click="search"
- ></el-button>
- </template>
- </el-input>
- </div>
- <div class="user-select__select">
- <div
- class="user-select__tree"
- v-loading="showGrouploading"
- >
- <el-scrollbar>
- <el-tree
- class="menu"
- ref="groupTree"
- :data="group"
- node-key="id"
- :props="{
- label: 'name',
- children: 'children',
- }"
- highlight-current
- :expand-on-click-node="false"
- :current-node-key="groupId"
- @node-click="groupClick"
- >
- <template #default="{ node, data }">
- <span
- class="custom-tree-node el-tree-node__label"
- >
- <span class="label">
- <el-icon
- :size="16"
- class="m-r-5"
- >
- <qiye
- v-if="data.type === '1'"
- :style="{
- color:
- $TOOL.data.get(
- 'IS_PRIMARY_TENANT'
- ) &&
- data.tenantDTO &&
- $utils.getTenantColorById(
- data
- .tenantDTO
- .id
- ),
- }"
- ></qiye>
- <bumen
- v-else
- :style="{
- color:
- $TOOL.data.get(
- 'IS_PRIMARY_TENANT'
- ) &&
- data.tenantDTO &&
- $utils.getTenantColorById(
- data
- .tenantDTO
- .id
- ),
- }"
- ></bumen>
- </el-icon>
- {{ node.label }}
- </span>
- </span>
- </template>
- </el-tree>
- </el-scrollbar>
- </div>
- <div
- class="user-select__user"
- v-loading="showUserloading"
- >
- <div class="user-select__user__list">
- <el-scrollbar ref="userScrollbar">
- <el-tree
- class="menu"
- ref="userTree"
- :data="user"
- node-key="id"
- highlight-current
- :props="{
- key: 'id',
- label: 'name',
- children: 'children',
- }"
- :default-checked-keys="selectedIds"
- :show-checkbox="limit > 1"
- check-on-click-node
- @check-change="userClick"
- ></el-tree>
- </el-scrollbar>
- </div>
- <footer>
- <el-pagination
- background
- layout="prev,next"
- small
- :total="total"
- :page-size="pageSize"
- v-model:currentPage="currentPage"
- @current-change="paginationChange"
- ></el-pagination>
- </footer>
- </div>
- </div>
- </div>
- <div class="user-select__toicon">
- <el-icon><arrow-right /></el-icon>
- </div>
- <div class="user-select__selected">
- <header>已选 ({{ selected.length }})</header>
- <ul>
- <el-scrollbar>
- <li
- v-for="(item, index) in selected"
- :key="item.id"
- >
- <span class="name">
- <el-avatar
- v-if="
- $TOOL.data.get('IS_PRIMARY_TENANT')
- "
- :size="30"
- :style="{
- background:
- $utils.getTenantColorById(
- item.tenantId
- ) + '!important',
- }"
- >{{
- item.name.substring(0, 1)
- }}</el-avatar
- >
- <el-avatar v-else>{{
- item.name.substring(0, 1)
- }}</el-avatar>
- <label>{{ item.name }}</label>
- </span>
- <span class="delete">
- <el-button
- text
- type="primary"
- icon="del-filled"
- circle
- size="small"
- @click="deleteSelected(index)"
- ></el-button>
- </span>
- </li>
- </el-scrollbar>
- </ul>
- </div>
- </div>
- </template>
- <template #footer>
- <el-button @click="dialogVisible = false">取 消</el-button>
- <el-button type="primary" @click="save">确 认</el-button>
- </template>
- </el-dialog>
- </template>
- <script>
- import userService from "@/api/sys/userService";
- import officeService from "@/api/sys/officeService";
- export default {
- props: {
- tenantId: { type: String, default: null },
- limit: {
- type: Number,
- default: 999999,
- },
- },
- data() {
- return {
- searchForm: {
- loginName: "",
- companyDTO: {
- id: "",
- },
- officeDTO: {
- id: "",
- },
- name: "",
- },
- dialogVisible: false,
- showGrouploading: false,
- showUserloading: false,
- groupId: "",
- pageSize: 10,
- total: 0,
- currentPage: 1,
- group: [],
- user: [],
- role: [],
- type: 1,
- selected: [],
- value: [],
- };
- },
- computed: {
- selectedIds() {
- return this.selected.map((t) => t.id);
- },
- },
- methods: {
- //打开赋值
- open(data) {
- this.value = data || [];
- this.selected = JSON.parse(JSON.stringify(data || []));
- this.dialogVisible = true;
- this.getGroup();
- this.getUser();
- },
- //获取组织
- async getGroup() {
- this.showGrouploading = true;
- // officeService.treeData().then((data) => {
- // this.officeTreeData = data
- // this.showGrouploading = false;
- // })
- var res = await officeService.treeData({ tenantId: this.tenantId });
- this.showGrouploading = false;
- var allNode = { id: "", type: "1", name: "所有" };
- res.unshift(allNode);
- this.group = res;
- },
- //获取用户
- async getUser() {
- this.showUserloading = true;
- userService
- .list({
- current: this.currentPage,
- size: this.pageSize,
- ...this.searchForm,
- "tenantDTO.id": this.tenantId,
- })
- .then((data) => {
- this.user = data.records;
- this.total = data.total;
- // this.pageNo = data.current
- this.showUserloading = false;
- this.$refs.userScrollbar.setScrollTop(0);
- });
- },
- //组织点击
- groupClick(data) {
- if (data.type === "1") {
- this.searchForm.companyDTO.id = data.id;
- this.searchForm.officeDTO.id = "";
- } else {
- this.searchForm.companyDTO.id = "";
- this.searchForm.officeDTO.id = data.id;
- }
- this.currentPage = 1;
- this.groupId = data.id;
- this.getUser();
- },
- //用户点击
- userClick(data, checked) {
- if (checked) {
- if (this.limit === 1) {
- this.selected = [
- {
- id: data.id,
- name: data.name,
- tenantId: data.tenantDTO?.id,
- },
- ];
- } else {
- this.selected.push({
- id: data.id,
- name: data.name,
- tenantId: data.tenantDTO?.id,
- });
- }
- } else {
- this.selected = this.selected.filter(
- (item) => item.id != data.id
- );
- }
- },
- //用户分页点击
- paginationChange() {
- this.getUser();
- },
- //用户搜索
- search() {
- // this.groupId = ''
- // this.$refs.groupTree.setCurrentKey(this.groupId)
- this.currentPage = 1;
- this.getUser();
- },
- //删除已选
- deleteSelected(index) {
- this.selected.splice(index, 1);
- console.log(this.selected);
- if (this.type == 1) {
- this.$refs.userTree.setCheckedKeys(this.selectedIds);
- } else if (this.type == 2) {
- this.$refs.groupTree.setCheckedKeys(this.selectedIds);
- }
- },
- //提交保存
- save() {
- this.value.splice(0, this.value.length);
- this.selected.map((item) => {
- this.value.push(item);
- });
- if (this.limit < this.value.length) {
- this.$message.error(`你最多只能选择${this.limit}个用户`);
- return;
- }
- this.$emit("doSubmit", this.value);
- this.dialogVisible = false;
- },
- },
- };
- </script>
- <style scoped>
- .user-select {
- display: flex;
- }
- .user-select__left {
- width: 400px;
- }
- .user-select__right {
- flex: 1;
- }
- .user-select__selected li .name .el-avatar {
- margin-right: 2px;
- height: 10;
- width: 25px;
- height: 25px;
- }
- .user-select__search {
- padding-bottom: 10px;
- }
- .user-select__select {
- display: flex;
- border: 1px solid var(--el-border-color-light);
- background: var(--el-color-white);
- }
- .user-select__tree {
- width: 200px;
- height: 300px;
- border-right: 1px solid var(--el-border-color-light);
- }
- .user-select__user {
- width: 200px;
- height: 300px;
- display: flex;
- flex-direction: column;
- }
- .user-select__user__list {
- flex: 1;
- overflow: auto;
- }
- .user-select__user footer {
- height: 36px;
- padding-top: 5px;
- border-top: 1px solid var(--el-border-color-light);
- }
- .user-select__toicon {
- display: flex;
- justify-content: center;
- align-items: center;
- margin: 0 10px;
- }
- .user-select__toicon i {
- display: flex;
- justify-content: center;
- align-items: center;
- background: #ccc;
- width: 20px;
- height: 20px;
- text-align: center;
- line-height: 20px;
- border-radius: 50%;
- color: #fff;
- }
- .user-select__selected {
- height: 345px;
- width: 200px;
- border: 1px solid var(--el-border-color-light);
- background: var(--el-color-white);
- }
- .user-select__selected header {
- height: 43px;
- line-height: 43px;
- border-bottom: 1px solid var(--el-border-color-light);
- padding: 0 15px;
- font-size: 16px;
- }
- .user-select__selected ul {
- height: 300px;
- overflow: auto;
- }
- .user-select__selected li {
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 5px 5px 5px 15px;
- height: 38px;
- }
- .user-select__selected li .name {
- display: flex;
- align-items: center;
- }
- .user-select__selected li .name .el-avatar {
- margin-right: 10px;
- }
- .user-select__selected li .delete {
- display: none;
- }
- .user-select__selected li:hover {
- background: var(--el-color-primary-light-9);
- }
- .user-select__selected li:hover .delete {
- display: inline-block;
- }
- .user-select-role .user-select__left {
- width: 200px;
- }
- .user-select-role .user-select__tree {
- border: none;
- height: 343px;
- }
- </style>
|