123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366 |
- <template>
- <a-modal
- width="60%"
- height="100%"
- :visible="visible"
- :title="title"
- @ok="handleSubmit"
- @cancel="close"
- cancelText="关闭"
- style="margin-top: -70px"
- wrapClassName="ant-modal-cust-warp"
- >
- <!-- <a-col :md="6" :sm="24">
- <a-card :bordered="false"> -->
- <!--组织机构-->
- <!-- <a-directory-tree
- selectable
- :selectedKeys="selectedDepIds"
- :checkStrictly="true"
- :dropdownStyle="{maxHeight:'200px',overflow:'auto'}"
- :treeData="departTree"
- :expandAction="false"
- :expandedKeys.sync="expandedKeys"
- @select="onDepSelect"
- /> -->
- <!-- </a-card>
- </a-col> -->
- <!-- 用户姓名:
- <a-input-search
- :style="{width:'150px',marginBottom:'15px'}"
- placeholder="请输入姓名"
- v-model="queryParam.realname"
- @search="onSearch"
- ></a-input-search>
- <a-button @click="searchReset(1)" style="margin-left: 20px" icon="redo">重置</a-button> -->
- <!--用户列表-->
- <a-table style="margin-top: -25px;"
- ref="table"
- :scroll="scrollTrigger"
- size="middle"
- rowKey="id"
- :columns="columns"
- :dataSource="dataSource"
- :pagination="ipagination"
- :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange,type: getType}"
- :loading="loading"
- @change="handleTableChange">
- </a-table>
- </a-modal>
- </template>
- <script>
- import {filterObj} from '@/utils/util'
- import {queryDepartTreeList, getUserList, queryUserByDepId} from '@/api/api'
- import { putAction,getAction } from '@/api/manage'
- export default {
- name: 'JSelectUserByDepModal',
- components: {},
- data() {
- return {
- queryParam: {
- username: "",
- },
- columns: [
- {
- title: '用户账号',
- align: 'center',
- dataIndex: 'username'
- },
- {
- title: '用户姓名',
- align: 'center',
- dataIndex: 'realname'
- },
- {
- title: '性别',
- align: 'center',
- dataIndex: 'sex',
- customRender: function (text) {
- if (text === 1) {
- return '男'
- } else if (text === 2) {
- return '女'
- } else {
- return text
- }
- }
- },
- {
- title: '手机',
- align: 'center',
- dataIndex: 'phone'
- },
- {
- title: '部门',
- align: 'center',
- dataIndex: 'orgCode'
- }
- ],
- scrollTrigger: {},
- dataSource: [],
- dataSourceAll: [],
- selectedRowKeys: [],
- selectUserRows: [],
- selectUserIds: [],
- beginUsers: [],
- title: '根据部门选择用户',
- ipagination: {
- current: 1,
- pageSize: 300,
- pageSizeOptions: ['300'],
- showTotal: (total, range) => {
- return range[0] + '-' + range[1] + ' 共' + total + '条'
- },
- showQuickJumper: true,
- showSizeChanger: true,
- total: 0
- },
- isorter: {
- column: 'createTime',
- order: 'desc'
- },
- selectedDepIds: [],
- departTree: [],
- visible: false,
- form: this.$form.createForm(this),
- loading: false,
- expandedKeys: [],
- }
- },
- props: ['modalWidth', 'multi', 'userIds','customReturnField'],
- computed: {
- // 计算属性的 getter
- getType: function () {
- return this.multi == true ? 'checkbox' : 'radio';
- }
- },
- watch: {
- userIds: {
- immediate: true,
- handler() {
- this.initUserNames()
- }
- },
- },
- created() {
- // 该方法触发屏幕自适应
- this.resetScreenSize();
- this.loadData()
- },
- methods: {
- initUserNames() {
-
- if(this.beginUsers.length == 0){
- // console.log('sssssssssssssssssssssssss',this.beginUsers);
- this.beginUsers = ['wushuju72']
- }
- // console.log('dddddddddddddddddddddddddd',this.beginUsers);
- getAction('/sys/user/listBy', {beginUsers:this.beginUsers.toString()}).then((res) => {
- if (res.success) {
- let selectedRowKeys = []
- let realNames = []
- res.result.records.forEach(user => {
- realNames.push(user['realname'])
- selectedRowKeys.push(user['id'])
- })
- this.selectedRowKeys = selectedRowKeys
- console.log("回显用户",selectedRowKeys)
- this.$emit('initComp', realNames.join(','))
- }
- })
-
-
-
- // if (this.userIds) {
- // // 这里最后加一个 , 的原因是因为无论如何都要使用 in 查询,防止后台进行了模糊匹配,导致查询结果不准确
- // let values = this.userIds.split(',') + ','
- // var param = {
- // // username: values,
- // pageNo: 1,
- // pageSize: values.length
- // }
- // param[this.customReturnField] = values;
- // console.log("回显用户参数",param)
- // getAction('/sys/user/listBy', {}).then((res) => {
- // // getUserList(param).then((res) => {
- // if (res.success) {
- // let selectedRowKeys = []
- // let realNames = []
- // res.result.records.forEach(user => {
- // realNames.push(user['realname'])
- // selectedRowKeys.push(user['id'])
- // })
- // this.selectedRowKeys = selectedRowKeys
- // console.log("回显用户",selectedRowKeys)
- // this.$emit('initComp', realNames.join(','))
- // }
- // })
- // } else {
- // // JSelectUserByDep组件bug issues/I16634
- // this.$emit('initComp', '')
- // }
- },
- async loadData(arg) {
- if (arg === 1) {
- this.ipagination.current = 1;
- }
- if (this.selectedDepIds && this.selectedDepIds.length > 0) {
- await this.initQueryUserByDepId(this.selectedDepIds)
- } else {
- this.loading = true
- let params = this.getQueryParams()//查询条件
- params.syHireType ='在职'
- if(params.realname) params.realname = `*${params.realname}*`;
- await getAction('/sys/user/listBy', {}).then((res) => {
- // await getUserList(params).then((res) => {
- if (res.success) {
- this.dataSourceAll = res.result.records
- this.dataSource = res.result.records
- this.ipagination.total = res.result.total
- }
- }).finally(() => {
- this.loading = false
- })
- }
- },
- // 触发屏幕自适应
- resetScreenSize() {
- let screenWidth = document.body.clientWidth;
- if (screenWidth < 500) {
- this.scrollTrigger = {x: 800};
- } else {
- this.scrollTrigger = {};
- }
- },
- showModal(user) {
- this.beginUsers = user;
-
- this.visible = true;
- this.queryDepartTree();
- this.initUserNames()
- this.loadData();
- this.form.resetFields();
- },
- getQueryParams() {
- let param = Object.assign({}, this.queryParam, '');
- param.field = this.getQueryField();
- param.pageNo = this.ipagination.current;
- param.pageSize = this.ipagination.pageSize;
- return filterObj(param);
- },
- getQueryField() {
- let str = 'id,';
- for (let a = 0; a < this.columns.length; a++) {
- str += ',' + this.columns[a].dataIndex;
- }
- return str;
- },
- searchReset(num) {
- let that = this;
- if (num !== 0) {
- that.queryParam = {};
- that.loadData(1);
- }
- that.selectedRowKeys = [];
- that.selectUserIds = [];
- that.selectedDepIds = [];
- },
- close() {
- this.searchReset(0);
- this.visible = false;
- },
- handleTableChange(pagination, filters, sorter) {
- //TODO 筛选
- if (Object.keys(sorter).length > 0) {
- this.isorter.column = sorter.field;
- this.isorter.order = 'ascend' === sorter.order ? 'asc' : 'desc';
- }
- this.ipagination = pagination;
- this.loadData();
- },
- handleSubmit() {
- let that = this;
- this.getSelectUserRows();
- let username = []
- this.selectUserRows.forEach(user => {
- username.push(user['username'])
- })
- that.$emit('send-notice',username.toString());
- that.searchReset(0)
- that.close();
- },
- //获取选择用户信息
- getSelectUserRows(rowId) {
- let dataSource = this.dataSourceAll;
- let userIds = "";
- this.selectUserRows = [];
- for (let i = 0, len = dataSource.length; i < len; i++) {
- if (this.selectedRowKeys.includes(dataSource[i].id)) {
- this.selectUserRows.push(dataSource[i]);
- // userIds = userIds + "," + dataSource[i].username
- userIds = userIds + "," + dataSource[i][this.customReturnField]
- }
- }
- this.selectUserIds = userIds.substring(1);
- },
- // 点击树节点,筛选出对应的用户
- onDepSelect(selectedDepIds) {
- if (selectedDepIds[0] != null) {
- this.initQueryUserByDepId(selectedDepIds); // 调用方法根据选选择的id查询用户信息
- if (this.selectedDepIds[0] !== selectedDepIds[0]) {
- this.selectedDepIds = [selectedDepIds[0]];
- }
- }
- },
- onSelectChange(selectedRowKeys, selectionRows) {
- this.selectedRowKeys = selectedRowKeys;
- this.selectionRows = selectionRows;
- },
- onSearch() {
- this.loadData(1);
- },
- // 根据选择的id来查询用户信息
- initQueryUserByDepId(selectedDepIds) {
- this.loading = true
- let params = this.getQueryParams()//查询条件
- let realname = params.realname||'';
- return queryUserByDepId({id: selectedDepIds.toString(),realname:realname}).then((res) => {
- if (res.success) {
- this.dataSource = res.result;
- this.ipagination.total = res.result.length;
- }
- }).finally(() => {
- this.loading = false
- })
- },
- queryDepartTree() {
- queryDepartTreeList().then((res) => {
- if (res.success) {
- this.departTree = res.result;
- // 默认展开父节点
- this.expandedKeys = this.departTree.map(item => item.id)
- }
- })
- },
- modalFormOk() {
- this.loadData();
- }
- }
- }
- </script>
- <style scoped>
- .ant-table-tbody .ant-table-row td {
- padding-top: 10px;
- padding-bottom: 10px;
- }
- #components-layout-demo-custom-trigger .trigger {
- font-size: 18px;
- line-height: 64px;
- padding: 0 24px;
- cursor: pointer;
- transition: color .3s;
- }
- </style>
|