org-user-list.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. <template>
  2. <div>
  3. <!-- 数据表格 -->
  4. <ele-pro-table
  5. ref="table"
  6. :columns="columns"
  7. :datasource="datasource"
  8. height="calc(100vh - 265px)"
  9. full-height="calc(100vh - 116px)"
  10. tool-class="ele-toolbar-form"
  11. cache-key="systemOrgUserTable"
  12. >
  13. <!-- 表头工具栏 -->
  14. <template v-slot:toolbar>
  15. <org-user-search @search="reload" ref="searchRef">
  16. <el-button
  17. size="small"
  18. type="primary"
  19. icon="el-icon-plus"
  20. class="ele-btn-icon"
  21. @click="openEdit()"
  22. >
  23. 添加
  24. </el-button>
  25. <el-button
  26. type="primary"
  27. size="mini"
  28. icon="el-icon-upload2"
  29. plain
  30. @click="uploadFile"
  31. >导入</el-button
  32. >
  33. <el-button
  34. type="primary"
  35. size="mini"
  36. icon="el-icon-download"
  37. plain
  38. @click="exportUsers"
  39. >导出</el-button
  40. >
  41. </org-user-search>
  42. </template>
  43. <!-- 角色列 -->
  44. <template v-slot:roles="{ row }">
  45. <el-tag
  46. v-for="item in row.roles"
  47. :key="item.roleId"
  48. type="primary"
  49. size="mini"
  50. :disable-transitions="true"
  51. >
  52. {{ item.roleName }}
  53. </el-tag>
  54. </template>
  55. <template v-slot:name="{ row }">
  56. <el-link type="primary" :underline="false" @click="openEdit(row, true)">
  57. {{ row.name }}</el-link
  58. >
  59. </template>
  60. <!-- 状态列 -->
  61. <!-- <template v-slot:status="{ row }">
  62. <el-switch
  63. :active-value="0"
  64. :inactive-value="1"
  65. v-model="row.status"
  66. @change="editStatus(row)"
  67. />
  68. </template> -->
  69. <!-- 操作列 -->
  70. <template v-slot:action="{ row }">
  71. <el-link
  72. type="primary"
  73. :underline="false"
  74. icon="el-icon-edit"
  75. @click="openEdit(row)"
  76. >
  77. 修改
  78. </el-link>
  79. <el-link
  80. v-if="row.loginName"
  81. type="primary"
  82. :underline="false"
  83. icon="el-icon-unlock"
  84. @click="toUnBind(row)"
  85. >
  86. 解绑
  87. </el-link>
  88. <el-link
  89. v-if="!row.loginName"
  90. type="primary"
  91. :underline="false"
  92. icon="el-icon-add"
  93. @click="addUsers(row)"
  94. >
  95. 新建账号
  96. </el-link>
  97. <el-popconfirm
  98. class="ele-action"
  99. title="确定要删除此用户吗?"
  100. @confirm="remove(row)"
  101. v-if="!row.loginName"
  102. >
  103. <template v-slot:reference>
  104. <el-link type="danger" :underline="false" icon="el-icon-delete">
  105. 删除
  106. </el-link>
  107. </template>
  108. </el-popconfirm>
  109. </template>
  110. </ele-pro-table>
  111. <!-- 编辑弹窗 -->
  112. <org-user-edit
  113. :data="current"
  114. :visible.sync="showEdit"
  115. :organization-list="organizationList"
  116. :institutionList="institutionList"
  117. :organization-id="organizationId"
  118. @done="reload"
  119. ref="userEditRef"
  120. />
  121. <addUsers
  122. :visible.sync="showEdit1"
  123. @done="reload"
  124. :data="null"
  125. ref="userEdit"
  126. :organizationList="organizationList"
  127. />
  128. <importDialog
  129. :defModule="moudleName"
  130. ref="importDialogRef"
  131. @success="reload"
  132. />
  133. <el-dialog
  134. title="提示"
  135. :visible.sync="dialogVisible"
  136. :before-close="handleClose"
  137. width="400px"
  138. >
  139. <span>是否绑定已有用户?</span>
  140. <el-radio v-model="radio" label="1">是</el-radio>
  141. <el-radio v-model="radio" label="2">否</el-radio>
  142. <span slot="footer" class="dialog-footer">
  143. <el-button @click="dialogVisible = false">取 消</el-button>
  144. <el-button type="primary" @click="setUser">确 定</el-button>
  145. </span>
  146. </el-dialog>
  147. <ele-modal
  148. width="1000px"
  149. :visible="userShow"
  150. :close-on-click-modal="false"
  151. custom-class="ele-dialog-form"
  152. :maxable="true"
  153. >
  154. <UserSearch @search="reload1"></UserSearch>
  155. <!-- 数据表格 -->
  156. <ele-pro-table
  157. ref="table1"
  158. :columns="columns1"
  159. :datasource="datasource1"
  160. :current.sync="userRow"
  161. highlight-current-row
  162. row-key="id"
  163. >
  164. </ele-pro-table>
  165. <template v-slot:footer>
  166. <el-button @click="userShow = false">取消</el-button>
  167. <el-button type="primary" @click="getUser"> 确认 </el-button>
  168. </template>
  169. </ele-modal>
  170. </div>
  171. </template>
  172. <script>
  173. import OrgUserSearch from './org-user-search.vue';
  174. import OrgUserEdit from './org-user-edit.vue';
  175. import importDialog from '@/components/upload/import-dialog.vue';
  176. import addUsers from '@/views/system/user/components/user-edit.vue';
  177. import UserSearch from '@/views/system/user/components/user-search.vue';
  178. import {
  179. getUserPage,
  180. removePersonnel,
  181. unbindLoginName
  182. } from '@/api/system/organization';
  183. import { pageUsers, exportUsers } from '@/api/system/user';
  184. export default {
  185. components: {
  186. importDialog,
  187. OrgUserSearch,
  188. OrgUserEdit,
  189. addUsers,
  190. UserSearch
  191. },
  192. props: {
  193. // 机构id
  194. organizationId: [Number, String],
  195. // 全部机构
  196. organizationList: Array,
  197. institutionList: Array
  198. },
  199. data() {
  200. return {
  201. moudleName: 'mainUser',
  202. showEdit1: false,
  203. userShow: false,
  204. userRow: null,
  205. currentRow: null,
  206. dialogVisible: false,
  207. radio: '2',
  208. // 表格列配置
  209. columns: [
  210. {
  211. columnKey: 'index',
  212. type: 'index',
  213. width: 45,
  214. align: 'center',
  215. showOverflowTooltip: true,
  216. fixed: 'left'
  217. },
  218. {
  219. prop: 'name',
  220. label: '姓名',
  221. slot: 'name',
  222. sortable: 'custom',
  223. showOverflowTooltip: true,
  224. minWidth: 110
  225. },
  226. {
  227. prop: 'jobNumber',
  228. label: '工号',
  229. sortable: 'custom',
  230. showOverflowTooltip: true,
  231. minWidth: 110
  232. },
  233. {
  234. prop: 'loginName',
  235. label: '用户账号',
  236. sortable: 'custom',
  237. showOverflowTooltip: true,
  238. minWidth: 110
  239. },
  240. {
  241. prop: 'sex',
  242. label: '性别',
  243. sortable: 'custom',
  244. showOverflowTooltip: true,
  245. minWidth: 80,
  246. formatter: (_row, _column, cellValue) => {
  247. return cellValue == 1 ? '男' : cellValue == 2 ? '女' : '';
  248. }
  249. },
  250. {
  251. prop: 'status',
  252. label: '状态',
  253. align: 'center',
  254. sortable: 'custom',
  255. width: 80,
  256. formatter: (_row, _column, cellValue) => {
  257. const dom = this.statusOptions.find((item) => {
  258. return item.value == cellValue;
  259. });
  260. return dom ? dom.label : '';
  261. }
  262. },
  263. {
  264. prop: 'isEnabled',
  265. align: 'center',
  266. label: '是否启用',
  267. showOverflowTooltip: true,
  268. formatter: (row, column) => {
  269. return row.isEnabled === 0
  270. ? '停用'
  271. : row.isEnabled === 1
  272. ? '启用'
  273. : '';
  274. }
  275. },
  276. {
  277. prop: 'createTime',
  278. label: '创建时间',
  279. sortable: 'custom',
  280. showOverflowTooltip: true,
  281. minWidth: 110,
  282. formatter: (_row, _column, cellValue) => {
  283. return this.$util.toDateString(cellValue);
  284. }
  285. },
  286. {
  287. columnKey: 'action',
  288. label: '操作',
  289. width: 200,
  290. align: 'left',
  291. resizable: false,
  292. slot: 'action',
  293. showOverflowTooltip: true
  294. }
  295. ],
  296. // 表格列配置
  297. columns1: [
  298. {
  299. columnKey: 'index',
  300. type: 'index',
  301. width: 55,
  302. align: 'center',
  303. showOverflowTooltip: true,
  304. fixed: 'left',
  305. label: '序号'
  306. },
  307. {
  308. prop: 'loginName',
  309. label: '用户账号',
  310. showOverflowTooltip: true,
  311. minWidth: 110
  312. },
  313. {
  314. prop: 'jobNumber',
  315. label: '工号',
  316. showOverflowTooltip: true,
  317. minWidth: 110
  318. },
  319. {
  320. prop: 'name',
  321. label: '姓名',
  322. showOverflowTooltip: true,
  323. minWidth: 110
  324. },
  325. {
  326. prop: 'phone',
  327. label: '手机号',
  328. showOverflowTooltip: true,
  329. minWidth: 110
  330. },
  331. {
  332. columnKey: 'groupRoleList',
  333. label: '角色',
  334. showOverflowTooltip: true,
  335. minWidth: 110,
  336. formatter: (_row, _column, cellValue) => {
  337. let names = [];
  338. _row.groupRoleList.forEach((item) => {
  339. names.push(...item.roleVOList.map((val) => val.name));
  340. });
  341. return names.toString();
  342. }
  343. },
  344. {
  345. prop: 'createTime',
  346. label: '创建时间',
  347. // sortable: 'custom',
  348. showOverflowTooltip: true,
  349. minWidth: 110,
  350. formatter: (_row, _column, cellValue) => {
  351. return this.$util.toDateString(cellValue);
  352. }
  353. }
  354. ],
  355. // 当前编辑数据
  356. current: null,
  357. // 是否显示编辑弹窗
  358. showEdit: false,
  359. statusOptions: [
  360. { value: 1, label: '全职' },
  361. { value: 2, label: '兼职' },
  362. { value: 3, label: '实习' },
  363. { value: 4, label: '正式' },
  364. { value: 5, label: '试用' },
  365. { value: 6, label: '离职' }
  366. ]
  367. };
  368. },
  369. methods: {
  370. async addUsers(row) {
  371. // this.userRow = null;
  372. this.currentRow = row;
  373. this.dialogVisible = true;
  374. },
  375. setUser() {
  376. this.dialogVisible = false;
  377. if (this.radio == 1) {
  378. this.userShow = true;
  379. } else {
  380. this.showEdit1 = true;
  381. this.$refs.userEdit.userBk(this.currentRow);
  382. }
  383. },
  384. getUser() {
  385. if (!this.userRow) {
  386. this.$message.warning('请选择一条数据!');
  387. return;
  388. }
  389. this.userShow = false;
  390. this.showEdit1 = true;
  391. this.$refs.userEdit.getByData(this.userRow, this.currentRow);
  392. },
  393. /* 表格数据源 */
  394. datasource({ page, limit, where, order }) {
  395. return getUserPage({
  396. ...where,
  397. pageNum: page,
  398. orderName: order.order || '',
  399. sortBy: order.sort || '',
  400. size: limit,
  401. groupId: this.organizationId
  402. });
  403. },
  404. /* 表格数据源 */
  405. datasource1({ page, limit, where, order }) {
  406. return pageUsers({ ...where, ...order, pageNum: page, size: limit });
  407. },
  408. /* 刷新表格 */
  409. reload(where) {
  410. this.$refs.table.reload({ pageNum: 1, where: where });
  411. },
  412. reload1(where) {
  413. this.$refs.table1.reload({ pageNum: 1, where: where });
  414. },
  415. exportUsers() {
  416. let where = this.$refs.searchRef.geValue();
  417. this.reload(where);
  418. exportUsers({
  419. ...where,
  420. pageNum: 1,
  421. size: 10000,
  422. groupId: this.organizationId
  423. });
  424. },
  425. /* 显示编辑 */
  426. openEdit(row, disabled) {
  427. this.current = row;
  428. this.showEdit = true;
  429. this.$refs.userEditRef.setDisabled(disabled);
  430. },
  431. // 解除绑定
  432. toUnBind(row) {
  433. const loading = this.$loading({ lock: true });
  434. unbindLoginName(row.id)
  435. .then((res) => {
  436. loading.close();
  437. this.$message.success('解绑成功');
  438. this.reload();
  439. })
  440. .catch((e) => {
  441. loading.close();
  442. // this.$message.error(e.message);
  443. });
  444. },
  445. /* 删除 */
  446. remove(row) {
  447. const loading = this.$loading({ lock: true });
  448. removePersonnel([row.id])
  449. .then((msg) => {
  450. loading.close();
  451. this.$message.success(msg);
  452. this.reload();
  453. })
  454. .catch((e) => {
  455. loading.close();
  456. // this.$message.error(e.message);
  457. });
  458. },
  459. /* 更改状态 */
  460. editStatus(row) {
  461. const loading = this.$loading({ lock: true });
  462. updateUserStatus(row.userId, row.status)
  463. .then((msg) => {
  464. loading.close();
  465. this.$message.success(msg);
  466. })
  467. .catch((e) => {
  468. loading.close();
  469. row.status = !row.status ? 1 : 0;
  470. // this.$message.error(e.message);
  471. });
  472. },
  473. uploadFile() {
  474. this.$refs.importDialogRef.open();
  475. }
  476. },
  477. watch: {
  478. // 监听机构id变化
  479. organizationId() {
  480. this.reload();
  481. }
  482. }
  483. };
  484. </script>