b80c22dba55b3e5883052d2cf04cc05193fad6b8.svn-base 7.4 KB

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