SelectUserModal.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <template>
  2. <div>
  3. <a-modal
  4. centered
  5. :title="title"
  6. :width="1000"
  7. :visible="visible"
  8. @ok="handleOk"
  9. @cancel="handleCancel"
  10. cancelText="关闭">
  11. <!-- 查询区域 -->
  12. <div class="table-page-search-wrapper">
  13. <a-form layout="inline" @keyup.enter.native="searchQuery">
  14. <a-row :gutter="24">
  15. <!-- <a-col :span="10">
  16. <a-form-item label="用户账号">
  17. <a-input placeholder="请输入用户账号" v-model="queryParam.username"></a-input>
  18. </a-form-item>
  19. </a-col> -->
  20. <a-col :span="10">
  21. <a-form-item label="用户名称">
  22. <j-input placeholder="请输入用户名称" v-model="queryParam.realname"></j-input>
  23. </a-form-item>
  24. </a-col>
  25. <a-col :span="10">
  26. <a-form-item label="部门" style="margin-left:8px">
  27. <j-search-select-tag v-model="queryParam.deptName" placeholder="请选择部门"
  28. dict="sys_depart,depart_name,depart_name,org_type='3' or org_code='TBD' order by org_code"/>
  29. </a-form-item>
  30. </a-col>
  31. <a-col :span="8">
  32. <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
  33. <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
  34. <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
  35. </span>
  36. </a-col>
  37. </a-row>
  38. </a-form>
  39. </div>
  40. <!-- table区域-begin -->
  41. <div>
  42. <a-table
  43. size="small"
  44. bordered
  45. rowKey="id"
  46. :columns="columns1"
  47. :dataSource="dataSource1"
  48. :pagination="ipagination"
  49. :loading="loading"
  50. :scroll="{ y: 240 }"
  51. :rowSelection="{selectedRowKeys: selectedRowKeys,onSelectAll:onSelectAll,onSelect:onSelect,onChange: onSelectChange}"
  52. @change="handleTableChange">
  53. </a-table>
  54. </div>
  55. <!-- table区域-end -->
  56. </a-modal>
  57. </div>
  58. </template>
  59. <script>
  60. import JInput from '@/components/jeecg/JInput'
  61. import {filterObj} from '@/utils/util'
  62. import {getAction} from '@/api/manage'
  63. import JSearchSelectTag from '@/components/dict/JSearchSelectTag'
  64. export default {
  65. name: "SelectUserModal",
  66. components: { JInput,JSearchSelectTag},
  67. data() {
  68. return {
  69. title: "添加已有用户",
  70. names: [],
  71. visible: false,
  72. placement: 'right',
  73. description: '',
  74. // 查询条件
  75. queryParam: {},
  76. // 表头
  77. columns1: [
  78. {
  79. title: '#',
  80. dataIndex: '',
  81. key: 'rowIndex',
  82. width: 50,
  83. align: "center",
  84. customRender: function (t, r, index) {
  85. return parseInt(index) + 1;
  86. }
  87. },
  88. {
  89. title: '用户账号',
  90. align: "center",
  91. width: 100,
  92. dataIndex: 'username'
  93. },
  94. {
  95. title: '用户名称',
  96. align: "center",
  97. width: 100,
  98. dataIndex: 'realname'
  99. },
  100. {
  101. title: '性别',
  102. align: "center",
  103. width: 100,
  104. dataIndex: 'sex_dictText'
  105. },
  106. {
  107. title: '电话',
  108. align: "center",
  109. width: 100,
  110. dataIndex: 'phone'
  111. },
  112. {
  113. title: '部门',
  114. align: "center",
  115. width: 150,
  116. dataIndex: 'orgCode'
  117. }
  118. ],
  119. columns2: [
  120. {
  121. title: '用户账号',
  122. align: "center",
  123. dataIndex: 'username',
  124. },
  125. {
  126. title: '用户名称',
  127. align: "center",
  128. dataIndex: 'realname',
  129. },
  130. {
  131. title: '操作',
  132. dataIndex: 'action',
  133. align: "center",
  134. width: 100,
  135. scopedSlots: {customRender: 'action'},
  136. }
  137. ],
  138. //数据集
  139. dataSource1: [],
  140. dataSource2: [],
  141. // 分页参数
  142. ipagination: {
  143. current: 1,
  144. pageSize: 10,
  145. pageSizeOptions: ['10', '20', '30'],
  146. showTotal: (total, range) => {
  147. return range[0] + "-" + range[1] + " 共" + total + "条"
  148. },
  149. showQuickJumper: true,
  150. showSizeChanger: true,
  151. total: 0
  152. },
  153. isorter: {
  154. column: 'createTime',
  155. order: 'desc',
  156. },
  157. loading: false,
  158. selectedRowKeys: [],
  159. selectedRows: [],
  160. url: {
  161. list: "/sys/user/list",
  162. }
  163. }
  164. },
  165. created() {
  166. this.loadData();
  167. },
  168. methods: {
  169. searchQuery() {
  170. this.loadData(1);
  171. },
  172. searchReset() {
  173. this.queryParam = {};
  174. this.loadData(1);
  175. },
  176. handleCancel() {
  177. this.visible = false;
  178. this.selectedRowKeys = []
  179. },
  180. handleOk() {
  181. this.dataSource2 = this.selectedRowKeys;
  182. console.log("data:" + this.dataSource2);
  183. this.$emit("selectFinished", this.dataSource2);
  184. this.visible = false;
  185. },
  186. add() {
  187. this.visible = true;
  188. },
  189. loadData(arg) {
  190. //加载数据 若传入参数1则加载第一页的内容
  191. if (arg === 1) {
  192. this.ipagination.current = 1;
  193. }
  194. var params = this.getQueryParams();//查询条件
  195. getAction(this.url.list, params).then((res) => {
  196. if (res.success) {
  197. this.dataSource1 = res.result.records;
  198. this.ipagination.total = res.result.total;
  199. }
  200. })
  201. },
  202. getQueryParams() {
  203. var param = Object.assign({}, this.queryParam, '');
  204. param.field = this.getQueryField();
  205. param.pageNo = this.ipagination.current;
  206. param.pageSize = this.ipagination.pageSize;
  207. return filterObj(param);
  208. },
  209. getQueryField() {
  210. //TODO 字段权限控制
  211. },
  212. onSelectAll(selected, selectedRows, changeRows) {
  213. if (selected === true) {
  214. for (var a = 0; a < changeRows.length; a++) {
  215. this.dataSource2.push(changeRows[a]);
  216. }
  217. } else {
  218. for (var b = 0; b < changeRows.length; b++) {
  219. this.dataSource2.splice(this.dataSource2.indexOf(changeRows[b]), 1);
  220. }
  221. }
  222. // console.log(selected, selectedRows, changeRows);
  223. },
  224. onSelect(record, selected) {
  225. if (selected === true) {
  226. this.dataSource2.push(record);
  227. } else {
  228. var index = this.dataSource2.indexOf(record);
  229. //console.log();
  230. if (index >= 0) {
  231. this.dataSource2.splice(this.dataSource2.indexOf(record), 1);
  232. }
  233. }
  234. },
  235. onSelectChange(selectedRowKeys, selectedRows) {
  236. this.selectedRowKeys = selectedRowKeys;
  237. this.selectionRows = selectedRows;
  238. },
  239. onClearSelected() {
  240. this.selectedRowKeys = [];
  241. this.selectionRows = [];
  242. },
  243. handleDelete: function (record) {
  244. this.dataSource2.splice(this.dataSource2.indexOf(record), 1);
  245. },
  246. handleTableChange(pagination, filters, sorter) {
  247. //分页、排序、筛选变化时触发
  248. console.log(sorter);
  249. //TODO 筛选
  250. if (Object.keys(sorter).length > 0) {
  251. this.isorter.column = sorter.field;
  252. this.isorter.order = "ascend" == sorter.order ? "asc" : "desc"
  253. }
  254. this.ipagination = pagination;
  255. this.loadData();
  256. }
  257. }
  258. }
  259. </script>
  260. <style lang="less" scoped>
  261. .ant-card-body .table-operator {
  262. margin-bottom: 18px;
  263. }
  264. .ant-table-tbody .ant-table-row td {
  265. padding-top: 15px;
  266. padding-bottom: 15px;
  267. }
  268. .anty-row-operator button {
  269. margin: 0 5px
  270. }
  271. .ant-btn-danger {
  272. background-color: #ffffff
  273. }
  274. .ant-modal-cust-warp {
  275. height: 100%
  276. }
  277. .ant-modal-cust-warp .ant-modal-body {
  278. height: calc(100% - 110px) !important;
  279. overflow-y: auto
  280. }
  281. .ant-modal-cust-warp .ant-modal-content {
  282. height: 90% !important;
  283. overflow-y: hidden
  284. }
  285. </style>