123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281 |
- <!--
- * @FilePath: index.vue
- * @Author: 旭颖
- * @Date: 2022-12-14 16:03:57
- * @LastEditors: Please set LastEditors
- * @LastEditTime: 2023-04-08 17:57:00
- -->
- <template>
- <div class="page-container">
- <el-form-item label="发送人员" prop="users">
- <div class="grid">
- <div class="item">
- <el-scrollbar height="400px">
- <el-tree
- ref="departmentTree"
- :data="department_list"
- default-expand-all
- :empty-text="emptyText"
- highlight-current
- node-key="id"
- :props="defaultProps"
- @node-click="handleNodeDepartment"
- />
- </el-scrollbar>
- </div>
- <div class="item middle">
- <el-scrollbar height="400px">
- <div class="people-search">
- <el-input
- v-model.trim="name"
- clearable
- placeholder="请输入姓名"
- />
- <el-button
- circle
- :icon="Search"
- style="margin-left: 10px"
- type="primary"
- />
- <el-button
- style="margin-left: 10px"
- type="primary"
- @click="selectAll"
- >
- 全选
- </el-button>
- </div>
- <el-tree
- ref="departmentPeople"
- :data="people_list"
- :default-checked-keys="peopleChecked"
- default-expand-all
- highlight-current
- min-width="200px"
- node-key="id"
- :props="defaultProps"
- show-checkbox
- @check-change="handleNodeClickPeople"
- />
- </el-scrollbar>
- </div>
- <div class="item">
- <el-scrollbar height="400px">
- <div class="people-search">
- <el-input
- v-model.trim="name"
- clearable
- placeholder="请输入姓名"
- />
- <el-button
- circle
- :icon="Search"
- style="margin-left: 10px"
- type="primary"
- />
- </div>
- <div>
- <div
- v-for="(item, index) in users"
- :key="index"
- class="select-list"
- >
- <div class="name">{{ item.name }}</div>
- <el-icon
- color="#f56c6c"
- size="18"
- style="line-height: 35px; display: inline-block"
- @click="deletePeople(item.id)"
- >
- <Delete />
- </el-icon>
- </div>
- </div>
- </el-scrollbar>
- </div>
- </div>
- </el-form-item>
- </div>
- </template>
- <script>
- import { getDepartmentList, getPersonList } from './api/index'
- import { handleTree } from '@/utils/publicMethods' //将列表转坏为树形
- import { nextTick } from 'vue'
- import { Search, Delete } from '@element-plus/icons-vue'
- export default defineComponent({
- name: 'RoleManagementEdit',
- // props: ['pieData'],
- emits: ['changeNavfu'],
- setup(props, ctx) {
- const pie_data = toRefs(props.pieData)
- // const $baseMessage = inject('$baseMessage')
- const state = reactive({
- formRef: null,
- departmentTree: null,
- department_list: [], //部门列表
- departmentPeople: null,
- defaultProps: {
- children: 'children',
- label: 'name',
- },
- peopleChecked: [], //选中人员列表
- people_list: '', //用户列表
- name: '', //用户姓名
- emptyText: '',
- users: [], //已选择的用户
- form: {
- name: '',
- send_type: [],
- body: '',
- type: '',
- users: [],
- status: 1,
- },
- title: '',
- dialogFormVisible: false,
- list: [],
- })
- if (pie_data) {
- state.users = pie_data
- const arr = []
- for (let i = 0; i < pie_data.length; i++) {
- arr.push(pie_data[i].id)
- }
- state.peopleChecked = arr
- }
- watch(props, (newProps) => {
- const pie_data = newProps.pieData
- console.log(newProps.pieData, 'newProps.pieData')
- if (pie_data) {
- state.users = pie_data
- const arr = []
- for (let i = 0; i < pie_data.length; i++) {
- arr.push(pie_data[i].id)
- }
- console.log(arr)
- state.peopleChecked = arr
- }
- getDepartment()
- getPerson()
- })
- //获取部门列表
- const getDepartment = async () => {
- const { data } = await getDepartmentList({
- status: 1,
- sortedBy: 'desc',
- orderBy: 'sort',
- filter: 'id;name;parent_id;sort;status',
- })
- // const arr_1 = data
- const arr_1 = [{ id: 0, name: '全部部门' }].concat(data)
- const arr = handleTree(arr_1, 'id', 'parent_id')
- state.department_list = arr
- nextTick(() => {
- state['departmentTree'].setCurrentKey(0)
- })
- }
- //获取用户列表
- const getPerson = async (department_id) => {
- const { data } = await getPersonList({
- department_id: department_id,
- status: 1,
- filter: 'id;name',
- })
- state.people_list = data
- }
- //点击切换部门
- const handleNodeDepartment = (node) => {
- getPerson(node.id)
- }
- const handleNodeClickPeople = () => {
- const data = state['departmentPeople'].getCheckedNodes()
- state.users = data
- ctx.emit('changeNavfu', data)
- }
- //全选
- const selectAll = () => {
- const arr = []
- state.people_list.map((item) => {
- arr.push(item.id)
- })
- state.peopleChecked = arr
- }
- //删除已选中的人员
- const deletePeople = (id) => {
- state.users = state.users.filter((item) => {
- return item.id !== id
- })
- const arr = []
- state.users.map((item) => {
- arr.push(item.id)
- })
- state['departmentPeople'].setCheckedKeys(arr, true, false)
- ctx.emit('changeNavfu', arr)
- }
- onMounted(() => {
- getDepartment()
- getPerson()
- })
- return {
- ...toRefs(state),
- getDepartment,
- getPerson,
- handleNodeDepartment,
- handleNodeClickPeople,
- deletePeople,
- selectAll,
- Search,
- Delete,
- }
- },
- })
- </script>
- <style lang="scss" scoped>
- .page-container {
- padding: 0 !important;
- }
- .vab-tree-border {
- width: 100%;
- height: 250px;
- padding: $base-padding;
- overflow-y: auto;
- border: 1px solid #dcdfe6;
- border-radius: $base-border-radius;
- }
- .grid {
- display: flex;
- border: dashed 1px #dcdfe6;
- padding: 15px;
- width: 100%;
- .item {
- flex: 1;
- margin-right: 5px;
- }
- .middle {
- padding: 0 20px;
- border-right: dashed 1px #dcdfe6;
- border-left: dashed 1px #dcdfe6;
- }
- }
- .people-search {
- display: flex;
- margin-bottom: 15px;
- }
- .select-list {
- display: flex;
- height: 30px;
- padding: 0 10px;
- line-height: 30px;
- cursor: pointer;
- .name {
- flex: 1;
- }
- }
- .select-list:hover {
- background-color: #eeeeee;
- }
- </style>
|