JSelectUserByDepModal.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. <template>
  2. <a-modal
  3. width="60%"
  4. height="100%"
  5. :visible="visible"
  6. :title="title"
  7. @ok="handleSubmit"
  8. @cancel="close"
  9. cancelText="关闭"
  10. style="margin-top: -70px"
  11. wrapClassName="ant-modal-cust-warp"
  12. >
  13. <!-- <a-col :md="6" :sm="24">
  14. <a-card :bordered="false"> -->
  15. <!--组织机构-->
  16. <!-- <a-directory-tree
  17. selectable
  18. :selectedKeys="selectedDepIds"
  19. :checkStrictly="true"
  20. :dropdownStyle="{maxHeight:'200px',overflow:'auto'}"
  21. :treeData="departTree"
  22. :expandAction="false"
  23. :expandedKeys.sync="expandedKeys"
  24. @select="onDepSelect"
  25. /> -->
  26. <!-- </a-card>
  27. </a-col> -->
  28. <!-- 用户姓名:
  29. <a-input-search
  30. :style="{width:'150px',marginBottom:'15px'}"
  31. placeholder="请输入姓名"
  32. v-model="queryParam.realname"
  33. @search="onSearch"
  34. ></a-input-search>
  35. <a-button @click="searchReset(1)" style="margin-left: 20px" icon="redo">重置</a-button> -->
  36. <!--用户列表-->
  37. <a-table style="margin-top: -25px;"
  38. ref="table"
  39. :scroll="scrollTrigger"
  40. size="middle"
  41. rowKey="id"
  42. :columns="columns"
  43. :dataSource="dataSource"
  44. :pagination="ipagination"
  45. :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange,type: getType}"
  46. :loading="loading"
  47. @change="handleTableChange">
  48. </a-table>
  49. </a-modal>
  50. </template>
  51. <script>
  52. import {filterObj} from '@/utils/util'
  53. import {queryDepartTreeList, getUserList, queryUserByDepId} from '@/api/api'
  54. import { putAction,getAction } from '@/api/manage'
  55. export default {
  56. name: 'JSelectUserByDepModal',
  57. components: {},
  58. data() {
  59. return {
  60. queryParam: {
  61. username: "",
  62. },
  63. columns: [
  64. {
  65. title: '用户账号',
  66. align: 'center',
  67. dataIndex: 'username'
  68. },
  69. {
  70. title: '用户姓名',
  71. align: 'center',
  72. dataIndex: 'realname'
  73. },
  74. {
  75. title: '性别',
  76. align: 'center',
  77. dataIndex: 'sex',
  78. customRender: function (text) {
  79. if (text === 1) {
  80. return '男'
  81. } else if (text === 2) {
  82. return '女'
  83. } else {
  84. return text
  85. }
  86. }
  87. },
  88. {
  89. title: '手机',
  90. align: 'center',
  91. dataIndex: 'phone'
  92. },
  93. {
  94. title: '部门',
  95. align: 'center',
  96. dataIndex: 'orgCode'
  97. }
  98. ],
  99. scrollTrigger: {},
  100. dataSource: [],
  101. dataSourceAll: [],
  102. selectedRowKeys: [],
  103. selectUserRows: [],
  104. selectUserIds: [],
  105. beginUsers: [],
  106. title: '根据部门选择用户',
  107. ipagination: {
  108. current: 1,
  109. pageSize: 300,
  110. pageSizeOptions: ['300'],
  111. showTotal: (total, range) => {
  112. return range[0] + '-' + range[1] + ' 共' + total + '条'
  113. },
  114. showQuickJumper: true,
  115. showSizeChanger: true,
  116. total: 0
  117. },
  118. isorter: {
  119. column: 'createTime',
  120. order: 'desc'
  121. },
  122. selectedDepIds: [],
  123. departTree: [],
  124. visible: false,
  125. form: this.$form.createForm(this),
  126. loading: false,
  127. expandedKeys: [],
  128. }
  129. },
  130. props: ['modalWidth', 'multi', 'userIds','customReturnField'],
  131. computed: {
  132. // 计算属性的 getter
  133. getType: function () {
  134. return this.multi == true ? 'checkbox' : 'radio';
  135. }
  136. },
  137. watch: {
  138. userIds: {
  139. immediate: true,
  140. handler() {
  141. this.initUserNames()
  142. }
  143. },
  144. },
  145. created() {
  146. // 该方法触发屏幕自适应
  147. this.resetScreenSize();
  148. this.loadData()
  149. },
  150. methods: {
  151. initUserNames() {
  152. if(this.beginUsers.length == 0){
  153. // console.log('sssssssssssssssssssssssss',this.beginUsers);
  154. this.beginUsers = ['wushuju72']
  155. }
  156. // console.log('dddddddddddddddddddddddddd',this.beginUsers);
  157. getAction('/sys/user/listBy', {beginUsers:this.beginUsers.toString()}).then((res) => {
  158. if (res.success) {
  159. let selectedRowKeys = []
  160. let realNames = []
  161. res.result.records.forEach(user => {
  162. realNames.push(user['realname'])
  163. selectedRowKeys.push(user['id'])
  164. })
  165. this.selectedRowKeys = selectedRowKeys
  166. console.log("回显用户",selectedRowKeys)
  167. this.$emit('initComp', realNames.join(','))
  168. }
  169. })
  170. // if (this.userIds) {
  171. // // 这里最后加一个 , 的原因是因为无论如何都要使用 in 查询,防止后台进行了模糊匹配,导致查询结果不准确
  172. // let values = this.userIds.split(',') + ','
  173. // var param = {
  174. // // username: values,
  175. // pageNo: 1,
  176. // pageSize: values.length
  177. // }
  178. // param[this.customReturnField] = values;
  179. // console.log("回显用户参数",param)
  180. // getAction('/sys/user/listBy', {}).then((res) => {
  181. // // getUserList(param).then((res) => {
  182. // if (res.success) {
  183. // let selectedRowKeys = []
  184. // let realNames = []
  185. // res.result.records.forEach(user => {
  186. // realNames.push(user['realname'])
  187. // selectedRowKeys.push(user['id'])
  188. // })
  189. // this.selectedRowKeys = selectedRowKeys
  190. // console.log("回显用户",selectedRowKeys)
  191. // this.$emit('initComp', realNames.join(','))
  192. // }
  193. // })
  194. // } else {
  195. // // JSelectUserByDep组件bug issues/I16634
  196. // this.$emit('initComp', '')
  197. // }
  198. },
  199. async loadData(arg) {
  200. if (arg === 1) {
  201. this.ipagination.current = 1;
  202. }
  203. if (this.selectedDepIds && this.selectedDepIds.length > 0) {
  204. await this.initQueryUserByDepId(this.selectedDepIds)
  205. } else {
  206. this.loading = true
  207. let params = this.getQueryParams()//查询条件
  208. params.syHireType ='在职'
  209. if(params.realname) params.realname = `*${params.realname}*`;
  210. await getAction('/sys/user/listBy', {}).then((res) => {
  211. // await getUserList(params).then((res) => {
  212. if (res.success) {
  213. this.dataSourceAll = res.result.records
  214. this.dataSource = res.result.records
  215. this.ipagination.total = res.result.total
  216. }
  217. }).finally(() => {
  218. this.loading = false
  219. })
  220. }
  221. },
  222. // 触发屏幕自适应
  223. resetScreenSize() {
  224. let screenWidth = document.body.clientWidth;
  225. if (screenWidth < 500) {
  226. this.scrollTrigger = {x: 800};
  227. } else {
  228. this.scrollTrigger = {};
  229. }
  230. },
  231. showModal(user) {
  232. this.beginUsers = user;
  233. this.visible = true;
  234. this.queryDepartTree();
  235. this.initUserNames()
  236. this.loadData();
  237. this.form.resetFields();
  238. },
  239. getQueryParams() {
  240. let param = Object.assign({}, this.queryParam, '');
  241. param.field = this.getQueryField();
  242. param.pageNo = this.ipagination.current;
  243. param.pageSize = this.ipagination.pageSize;
  244. return filterObj(param);
  245. },
  246. getQueryField() {
  247. let str = 'id,';
  248. for (let a = 0; a < this.columns.length; a++) {
  249. str += ',' + this.columns[a].dataIndex;
  250. }
  251. return str;
  252. },
  253. searchReset(num) {
  254. let that = this;
  255. if (num !== 0) {
  256. that.queryParam = {};
  257. that.loadData(1);
  258. }
  259. that.selectedRowKeys = [];
  260. that.selectUserIds = [];
  261. that.selectedDepIds = [];
  262. },
  263. close() {
  264. this.searchReset(0);
  265. this.visible = false;
  266. },
  267. handleTableChange(pagination, filters, sorter) {
  268. //TODO 筛选
  269. if (Object.keys(sorter).length > 0) {
  270. this.isorter.column = sorter.field;
  271. this.isorter.order = 'ascend' === sorter.order ? 'asc' : 'desc';
  272. }
  273. this.ipagination = pagination;
  274. this.loadData();
  275. },
  276. handleSubmit() {
  277. let that = this;
  278. this.getSelectUserRows();
  279. let username = []
  280. this.selectUserRows.forEach(user => {
  281. username.push(user['username'])
  282. })
  283. that.$emit('send-notice',username.toString());
  284. that.searchReset(0)
  285. that.close();
  286. },
  287. //获取选择用户信息
  288. getSelectUserRows(rowId) {
  289. let dataSource = this.dataSourceAll;
  290. let userIds = "";
  291. this.selectUserRows = [];
  292. for (let i = 0, len = dataSource.length; i < len; i++) {
  293. if (this.selectedRowKeys.includes(dataSource[i].id)) {
  294. this.selectUserRows.push(dataSource[i]);
  295. // userIds = userIds + "," + dataSource[i].username
  296. userIds = userIds + "," + dataSource[i][this.customReturnField]
  297. }
  298. }
  299. this.selectUserIds = userIds.substring(1);
  300. },
  301. // 点击树节点,筛选出对应的用户
  302. onDepSelect(selectedDepIds) {
  303. if (selectedDepIds[0] != null) {
  304. this.initQueryUserByDepId(selectedDepIds); // 调用方法根据选选择的id查询用户信息
  305. if (this.selectedDepIds[0] !== selectedDepIds[0]) {
  306. this.selectedDepIds = [selectedDepIds[0]];
  307. }
  308. }
  309. },
  310. onSelectChange(selectedRowKeys, selectionRows) {
  311. this.selectedRowKeys = selectedRowKeys;
  312. this.selectionRows = selectionRows;
  313. },
  314. onSearch() {
  315. this.loadData(1);
  316. },
  317. // 根据选择的id来查询用户信息
  318. initQueryUserByDepId(selectedDepIds) {
  319. this.loading = true
  320. let params = this.getQueryParams()//查询条件
  321. let realname = params.realname||'';
  322. return queryUserByDepId({id: selectedDepIds.toString(),realname:realname}).then((res) => {
  323. if (res.success) {
  324. this.dataSource = res.result;
  325. this.ipagination.total = res.result.length;
  326. }
  327. }).finally(() => {
  328. this.loading = false
  329. })
  330. },
  331. queryDepartTree() {
  332. queryDepartTreeList().then((res) => {
  333. if (res.success) {
  334. this.departTree = res.result;
  335. // 默认展开父节点
  336. this.expandedKeys = this.departTree.map(item => item.id)
  337. }
  338. })
  339. },
  340. modalFormOk() {
  341. this.loadData();
  342. }
  343. }
  344. }
  345. </script>
  346. <style scoped>
  347. .ant-table-tbody .ant-table-row td {
  348. padding-top: 10px;
  349. padding-bottom: 10px;
  350. }
  351. #components-layout-demo-custom-trigger .trigger {
  352. font-size: 18px;
  353. line-height: 64px;
  354. padding: 0 24px;
  355. cursor: pointer;
  356. transition: color .3s;
  357. }
  358. </style>