org-user-list.vue 13 KB

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