f5789d85798c5ada613de8849a35ca5f8df0d5ac.svn-base 9.4 KB

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