SelectUserModal.vue 7.7 KB

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