SelectUserModal.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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.workNo"></a-input>
  18. </a-form-item>
  19. </a-col>
  20. <a-col :md="8" :sm="8">
  21. <a-form-item label="姓名">
  22. <a-input placeholder="" v-model="queryParam.realname"></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: 400 }"
  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. width: 100,
  83. dataIndex: 'workNo'
  84. },
  85. {
  86. title: '员工姓名',
  87. align: "center",
  88. width: 100,
  89. dataIndex: 'realname'
  90. },
  91. {
  92. title: '性别',
  93. align: "center",
  94. width: 100,
  95. dataIndex: 'sex_dictText'
  96. },
  97. {
  98. title: '电话',
  99. align: "center",
  100. width: 100,
  101. dataIndex: 'phone'
  102. },
  103. {
  104. title: '部门',
  105. align: "center",
  106. width: 150,
  107. dataIndex: 'orgCodeTxt'
  108. }
  109. ],
  110. columns2: [
  111. {
  112. title: '工号',
  113. align: "center",
  114. dataIndex: 'workNo',
  115. },
  116. {
  117. title: '员工姓名',
  118. align: "center",
  119. dataIndex: 'realname',
  120. },
  121. {
  122. title: '操作',
  123. dataIndex: 'action',
  124. align: "center",
  125. width: 100,
  126. scopedSlots: {customRender: 'action'},
  127. }
  128. ],
  129. //数据集
  130. dataSource1: [],
  131. dataSource2: [],
  132. // 分页参数
  133. ipagination: {
  134. current: 1,
  135. pageSize: 10,
  136. pageSizeOptions: ['10', '20', '30'],
  137. showTotal: (total, range) => {
  138. return range[0] + "-" + range[1] + " 共" + total + "条"
  139. },
  140. showQuickJumper: true,
  141. showSizeChanger: true,
  142. total: 0
  143. },
  144. isorter: {
  145. column: 'createTime',
  146. order: 'desc',
  147. },
  148. loading: false,
  149. selectedRowKeys: [],
  150. selectedRows: [],
  151. url: {
  152. list: "/sys/user/roleUser",
  153. }
  154. }
  155. },
  156. created() {
  157. this.loadData();
  158. },
  159. methods: {
  160. searchQuery() {
  161. this.loadData(1);
  162. },
  163. searchReset() {
  164. this.queryParam = {};
  165. this.loadData(1);
  166. },
  167. handleCancel() {
  168. this.visible = false;
  169. },
  170. handleOk() {
  171. this.dataSource2 = this.selectedRowKeys;
  172. console.log("data:" + this.dataSource2);
  173. this.$emit("selectFinished", this.dataSource2);
  174. this.visible = false;
  175. },
  176. add() {
  177. this.visible = true;
  178. },
  179. loadData(arg) {
  180. this.onClearSelected();
  181. //加载数据 若传入参数1则加载第一页的内容
  182. if (arg === 1) {
  183. this.ipagination.current = 1;
  184. }
  185. var params = this.getQueryParams();//查询条件
  186. getAction(this.url.list, params).then((res) => {
  187. if (res.success) {
  188. this.dataSource1 = res.result.records;
  189. this.ipagination.total = res.result.total;
  190. }
  191. })
  192. },
  193. getQueryParams() {
  194. var param = Object.assign({}, this.queryParam, this.isorter);
  195. param.field = this.getQueryField();
  196. param.pageNo = this.ipagination.current;
  197. param.pageSize = this.ipagination.pageSize;
  198. return filterObj(param);
  199. },
  200. getQueryField() {
  201. //TODO 字段权限控制
  202. },
  203. onSelectAll(selected, selectedRows, changeRows) {
  204. if (selected === true) {
  205. for (var a = 0; a < changeRows.length; a++) {
  206. this.dataSource2.push(changeRows[a]);
  207. }
  208. } else {
  209. for (var b = 0; b < changeRows.length; b++) {
  210. this.dataSource2.splice(this.dataSource2.indexOf(changeRows[b]), 1);
  211. }
  212. }
  213. // console.log(selected, selectedRows, changeRows);
  214. },
  215. onSelect(record, selected) {
  216. if (selected === true) {
  217. this.dataSource2.push(record);
  218. } else {
  219. var index = this.dataSource2.indexOf(record);
  220. //console.log();
  221. if (index >= 0) {
  222. this.dataSource2.splice(this.dataSource2.indexOf(record), 1);
  223. }
  224. }
  225. },
  226. onSelectChange(selectedRowKeys, selectedRows) {
  227. this.selectedRowKeys = selectedRowKeys;
  228. this.selectionRows = selectedRows;
  229. },
  230. onClearSelected() {
  231. this.selectedRowKeys = [];
  232. this.selectionRows = [];
  233. },
  234. handleDelete: function (record) {
  235. this.dataSource2.splice(this.dataSource2.indexOf(record), 1);
  236. },
  237. handleTableChange(pagination, filters, sorter) {
  238. //分页、排序、筛选变化时触发
  239. console.log(sorter);
  240. //TODO 筛选
  241. if (Object.keys(sorter).length > 0) {
  242. this.isorter.column = sorter.field;
  243. this.isorter.order = "ascend" == sorter.order ? "asc" : "desc"
  244. }
  245. this.ipagination = pagination;
  246. this.loadData();
  247. }
  248. }
  249. }
  250. </script>
  251. <style lang="less" scoped>
  252. .ant-card-body .table-operator {
  253. margin-bottom: 18px;
  254. }
  255. .ant-table-tbody .ant-table-row td {
  256. padding-top: 15px;
  257. padding-bottom: 15px;
  258. }
  259. .anty-row-operator button {
  260. margin: 0 5px
  261. }
  262. .ant-btn-danger {
  263. background-color: #ffffff
  264. }
  265. .ant-modal-cust-warp {
  266. height: 100%
  267. }
  268. .ant-modal-cust-warp .ant-modal-body {
  269. height: calc(100% - 110px) !important;
  270. overflow-y: auto
  271. }
  272. .ant-modal-cust-warp .ant-modal-content {
  273. height: 90% !important;
  274. overflow-y: hidden
  275. }
  276. </style>