| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508 |
- const n = `<template>
- <div class="s-office-select-common">
- <a-input-search
- v-model:value="userValue"
- :readonly="true"
- :placeholder="placeholder"
- @click="onSearch"
- @search="onSearch"
- />
- <s-modal v-model:value="visible" :title="title" width="1000px" :showFullScreen="false">
- <template #footer>
- <a-button key="back" @click="handleCancel">{{ $l('取消') }}</a-button>
- <a-button key="submit" type="primary" :loading="loading" @click="handleOk">
- {{ $l('确认') }}
- </a-button>
- </template>
- <div class="modal-container">
- <div class="side">
- <s-tree
- :levelOneChildren="getLevelOneChildren"
- :levelTwoChildren="getLevelTwoChildren"
- @select:modelValue="handTreeSelect"
- v-model:select="treeValue"
- :height="470"
- />
- </div>
- <div class="main">
- <div class="filter">
- <a-input-search
- v-model:value="searchValue"
- :placeholder="$l('请输入')"
- style="width: 330px"
- @search="handSearch"
- />
- </div>
- <div class="list-wrap">
- <div class="item left-wrap">
- <div class="head">
- <div class="sub-title">{{ treeNode.title || treeNode.name }}</div>
- <div class="right">
- <a-button type="link" @click="handSelectAll">
- {{ !isAll ? $l('全选') : $l('反选') }}
- </a-button>
- <a-dropdown>
- <a type="link" @click.prevent>
- <DownOutlined />
- </a>
- <template #overlay>
- <a-menu>
- <a-menu-item @click="handChangeNodesAll">
- <a href="javascript:;">{{ $l('节点全选') }}</a>
- </a-menu-item>
- </a-menu>
- </template>
- </a-dropdown>
- </div>
- </div>
- <div class="user-list" @scroll="handScroll">
- <div
- class="item"
- v-for="item in userList"
- :key="item.id"
- @click="handItemChange(item)"
- >
- <div class="icon s-theme-icon-bg">
- {{ item.name && item.name.slice(0, 1) }}
- </div>
- <div class="cont">
- <div class="name">{{ item.name }} ({{ item.nameOrCount }})</div>
- <div class="job">{{ item.deptName }}</div>
- </div>
- </div>
- <div class="not-more" v-if="pageNo >= total">{{ $l('没有更多了') }}</div>
- </div>
- </div>
- <div class="item right-wrap">
- <div class="head">
- <div class="sub-title">{{ $l('本次已选') }}</div>
- <a-button type="link" @click="clearAll">{{ $l('清除') }}</a-button>
- </div>
- <div class="user-list select-list" @scroll="handRightScroll">
- <div class="item" v-for="(item, idx) in selectList" :key="item.id">
- <div class="icon s-theme-icon-bg">
- {{ item.name && item.name.slice(0, 1) }}
- </div>
- <div class="cont">
- <div class="name">{{ item.name }} ({{ item.nameOrCount }})</div>
- <div class="job">{{ item.deptName }}</div>
- </div>
- <div class="icon no-bg" @click="handItemClear(item, idx)">
- <CloseCircleOutlined />
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </s-modal>
- </div>
- </template>
- <script setup>
- import { ref, watch } from 'vue'
- import {
- levelOneChildren,
- levelTwoChildren,
- getJobs,
- jobIds,
- positionGetByIds
- } from '../../api/common'
- const emits = defineEmits(['change', 'update:value'])
- const props = defineProps({
- // 选中值(v-model:value)
- value: {
- type: [String, Array],
- default() {
- return ''
- }
- },
- // 是否多选,传 false 为单选
- multiple: {
- type: Boolean,
- default: true
- },
- // 占位文案
- placeholder: {
- type: String,
- default() {
- return window.$l('请选择')
- }
- },
- // 弹窗标题
- title: {
- type: String,
- default() {
- return window.$l('岗位选择')
- }
- }
- })
- const userValue = ref('')
- const treeValue = ref('')
- const searchValue = ref('')
- const loading = ref(false)
- const visible = ref(false)
- const treeNode = ref({})
- const userList = ref([])
- const userIds = ref([])
- const pageNo = ref(1)
- const total = ref(0)
- const isAll = ref(false)
- let timer = null
- const unitId = ref('')
- const selectList = ref([])
- const pageNum = ref(1)
- const pageCount = ref(20)
- const prevNum = ref(0)
- watch(
- () => props.value,
- (val) => {
- if (val && val.length) {
- const arr = Array.isArray(val) ? val : [val]
- userIds.value = props.multiple ? arr : arr.slice(0, 1)
- } else {
- userIds.value = []
- }
- },
- { immediate: true }
- )
- const onSearch = () => {
- visible.value = true
- }
- const handleCancel = () => {
- visible.value = false
- }
- const getSelectUsers = async (pageNo = 1, prevNo = 0) => {
- if (loading.value) {
- loading.value = false
- return
- }
- if (pageNo === 1) {
- selectList.value = []
- }
- let ids = []
- if (userIds.value.length < 100) {
- pageNum.value = 1
- prevNum.value = 0
- ids = userIds.value
- } else {
- ids = userIds.value.slice(prevNo * (pageCount.value || 20), pageNo * (pageCount.value || 20))
- }
- if (
- !ids.length ||
- (selectList.value.length &&
- ids.length >= userIds.value.length &&
- ids.length >= selectList.value.length)
- )
- return
- loading.value = true
- const res = await positionGetByIds(ids)
- selectList.value = selectList.value.concat(res)
- setUsers()
- timer = setTimeout(() => {
- loading.value = false
- clearTimeout(timer)
- }, 200)
- }
- const handSearch = () => {
- if (!unitId.value) {
- window.$message.warning(window.$l('请选择部门'))
- return
- }
- pageNo.value = 1
- userList.value = []
- getUserData(unitId.value)
- }
- const setUsers = () => {
- const list = selectList.value.filter((i) => userIds.value.includes(i.id))
- const nameList = list.map((i) => i.name)
- const len = nameList.length - 1
- userValue.value = nameList.slice(0, 1).join(',') + (len > 0 ? ' +' + len : '')
- }
- const clearCurrListSelect = () => {
- userList.value.forEach((i) => {
- if (userIds.value.includes(i.id)) {
- const index = userIds.value.indexOf(i.id)
- userIds.value.splice(index, 1)
- }
- })
- getSelectUsers()()
- }
- const handSelectAll = () => {
- isAll.value = !isAll.value
- if (isAll.value) {
- selectAll()
- } else {
- clearCurrListSelect()
- }
- }
- const handChangeNodesAll = async () => {
- if (!unitId.value) {
- window.$message.warning(window.$l('请选择部门'))
- return
- }
- const payload = {
- searchValue: searchValue.value,
- unitid: unitId.value.join(',')
- }
- const res = await jobIds(payload)
- const ids = userIds.value.concat(res)
- userIds.value = Array.from(new Set(ids))
- getSelectUsers()
- }
- const selectAll = () => {
- userList.value.forEach((i) => {
- if (!userIds.value.includes(i.id)) {
- userIds.value.push(i.id)
- }
- })
- getSelectUsers()
- }
- const clearAll = () => {
- isAll.value = false
- userValue.value = ''
- userIds.value = []
- selectList.value = []
- }
- const handleOk = () => {
- visible.value = false
- const list = selectList.value.filter((i) => userIds.value.includes(i.id))
- const nameList = list.map((i) => i.name)
- const len = nameList.length - 1
- const tags = nameList.slice(0, 1).join(',') + (len > 0 ? ' +' + len : '')
- const idList = list.map((i) => i.id)
- // v-model:value —— 单选回传字符串,多选回传数组
- emits('update:value', props.multiple ? idList : idList[0] || '')
- emits('change', tags, nameList, idList, list)
- }
- const handTreeSelect = (e, n) => {
- treeNode.value = n.node
- pageNo.value = 1
- total.value = 0
- userList.value = []
- loading.value = true
- unitId.value = e
- getUserData(e)
- }
- const getUserData = async (id) => {
- const payload = {
- pageNo: pageNo.value,
- pageSize: 20,
- searchValue: searchValue.value,
- unitid: id.join(','),
- containsChild: true
- }
- loading.value = true
- const res = await getJobs(payload)
- userList.value = userList.value.concat(res.list)
- total.value = res.pages
- timer = setTimeout(() => {
- loading.value = false
- clearTimeout(timer)
- }, 200)
- }
- const handItemChange = (item) => {
- if (!userIds.value.includes(item.id)) {
- userIds.value.push(item.id)
- }
- getSelectUsers()
- }
- const handItemClear = (item, idx) => {
- selectList.value.splice(idx, 1)
- userIds.value.splice(userIds.value.indexOf(item.id), 1)
- getSelectUsers()
- }
- const handScroll = ({ target: { offsetHeight, scrollHeight, scrollTop } }) => {
- if (loading.value) return
- if (offsetHeight + scrollTop >= scrollHeight - 20) {
- if (pageNo.value <= total.value) {
- pageNo.value++
- getUserData([treeNode.value.id])
- }
- }
- }
- const handRightScroll = ({ target: { offsetHeight, scrollHeight, scrollTop } }) => {
- if (loading.value) return
- if (offsetHeight + scrollTop >= scrollHeight - 20) {
- prevNum.value = pageNum.value
- pageNum.value++
- getSelectUsers(pageNum.value, prevNum.value)
- }
- }
- const getLevelOneChildren = (id) => {
- return levelOneChildren(id)
- }
- const getLevelTwoChildren = (id) => {
- return levelTwoChildren(id)
- }
- <\/script>
- <style lang="less">
- .s-modal {
- .ant-modal-content {
- }
- .modal-container {
- display: flex;
- justify-content: space-between;
- align-items: flex-start;
- border: 1px solid var(--s-border-color-split);
- .side {
- height: 500px;
- width: 300px;
- border-right: 1px solid var(--s-border-color-split);
- overflow: auto;
- }
- .main {
- width: 700px;
- }
- .filter {
- width: 100%;
- height: 60px;
- border-bottom: 1px solid var(--s-border-color-split);
- display: flex;
- justify-content: flex-start;
- align-items: center;
- padding-left: 10px;
- box-sizing: border-box;
- }
- .list-wrap {
- height: 440px;
- display: flex;
- justify-content: space-between;
- align-items: center;
- }
- .left-wrap,
- .right-wrap {
- max-width: 350px;
- min-width: 350px;
- width: 350px;
- height: 440px;
- }
- .left-wrap {
- border-right: 1px solid var(--s-border-color-split);
- }
- .right-wrap {
- .head {
- padding-right: 0;
- }
- }
- .head {
- display: flex;
- justify-content: space-between;
- align-items: center;
- height: 40px;
- padding: 0 20px;
- box-sizing: border-box;
- border-bottom: 1px solid var(--s-border-color-split);
- // user-select: none;
- .sub-title {
- width: 80%;
- text-overflow: ellipsis;
- overflow: hidden;
- white-space: nowrap;
- }
- }
- .user-list {
- height: 380px;
- overflow: hidden auto;
- .item {
- padding: 5px 20px;
- box-sizing: border-box;
- display: flex;
- justify-content: flex-start;
- align-items: center;
- margin-bottom: 1px;
- cursor: pointer;
- // user-select: none;
- }
- .item:first-child {
- margin-bottom: 2px;
- }
- .icon {
- min-width: 40px;
- width: 40px;
- height: 40px;
- border-radius: 40px;
- display: flex;
- justify-content: center;
- align-items: center;
- color: var(--s-text-color-regular);
- font-size: 18px;
- margin-right: 20px;
- }
- .cont {
- width: 230px;
- }
- .name {
- color: var(--s-text-color);
- }
- .job {
- color: var(--s-text-color-secondary);
- }
- .name,
- .job {
- width: 100%;
- text-overflow: ellipsis;
- overflow: hidden;
- white-space: nowrap;
- }
- }
- .select-list {
- .cont {
- width: 180px;
- }
- .no-bg {
- background-color: var(--s-bg-color-container);
- justify-content: flex-end;
- opacity: 0;
- font-size: 20px;
- color: var(--s-color-error);
- }
- .item:hover {
- .no-bg {
- opacity: 1;
- }
- }
- }
- .not-more {
- color: var(--s-text-color-secondary);
- font-size: 13px;
- text-align: center;
- margin: 10px 0;
- }
- }
- .right {
- display: flex;
- justify-content: flex-end;
- align-items: center;
- .mt-4 {
- transform: translateY(1px);
- }
- }
- }
- </style>
- `;
- export {
- n as default
- };
|