org-user-list.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  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. >
  153. <UserSearch @search="reload1"></UserSearch>
  154. <!-- 数据表格 -->
  155. <ele-pro-table
  156. ref="table1"
  157. :columns="columns1"
  158. :datasource="datasource1"
  159. :current.sync="userRow"
  160. highlight-current-row
  161. row-key="id"
  162. >
  163. </ele-pro-table>
  164. <template v-slot:footer>
  165. <el-button @click="userShow = false">取消</el-button>
  166. <el-button type="primary" @click="getUser"> 确认 </el-button>
  167. </template>
  168. </ele-modal>
  169. </div>
  170. </template>
  171. <script>
  172. import OrgUserSearch from './org-user-search.vue';
  173. import OrgUserEdit from './org-user-edit.vue';
  174. import importDialog from '@/components/upload/import-dialog.vue';
  175. import addUsers from '@/views/system/user/components/user-edit.vue';
  176. import UserSearch from '@/views/system/user/components/user-search.vue';
  177. import {
  178. getUserPage,
  179. removePersonnel,
  180. unbindLoginName
  181. } from '@/api/system/organization';
  182. import { pageUsers, exportUsers } from '@/api/system/user';
  183. export default {
  184. components: {
  185. importDialog,
  186. OrgUserSearch,
  187. OrgUserEdit,
  188. addUsers,
  189. UserSearch
  190. },
  191. props: {
  192. // 机构id
  193. organizationId: [Number, String],
  194. // 全部机构
  195. organizationList: Array,
  196. institutionList: Array
  197. },
  198. data() {
  199. return {
  200. moudleName: 'mainUser',
  201. showEdit1: false,
  202. userShow: false,
  203. userRow: null,
  204. currentRow: null,
  205. dialogVisible: false,
  206. radio: '2',
  207. // 表格列配置
  208. columns: [
  209. {
  210. columnKey: 'index',
  211. type: 'index',
  212. width: 45,
  213. align: 'center',
  214. showOverflowTooltip: true,
  215. fixed: 'left'
  216. },
  217. {
  218. prop: 'name',
  219. label: '姓名',
  220. slot: 'name',
  221. sortable: 'custom',
  222. showOverflowTooltip: true,
  223. minWidth: 110
  224. },
  225. {
  226. prop: 'jobNumber',
  227. label: '工号',
  228. sortable: 'custom',
  229. showOverflowTooltip: true,
  230. minWidth: 110
  231. },
  232. {
  233. prop: 'loginName',
  234. label: '用户账号',
  235. sortable: 'custom',
  236. showOverflowTooltip: true,
  237. minWidth: 110
  238. },
  239. {
  240. prop: 'sex',
  241. label: '性别',
  242. sortable: 'custom',
  243. showOverflowTooltip: true,
  244. minWidth: 80,
  245. formatter: (_row, _column, cellValue) => {
  246. return cellValue == 1 ? '男' : cellValue == 2 ? '女' : '';
  247. }
  248. },
  249. {
  250. prop: 'status',
  251. label: '状态',
  252. align: 'center',
  253. sortable: 'custom',
  254. width: 80,
  255. formatter: (_row, _column, cellValue) => {
  256. const dom = this.statusOptions.find((item) => {
  257. return item.value == cellValue;
  258. });
  259. return dom ? dom.label : '';
  260. }
  261. },
  262. {
  263. prop: 'createTime',
  264. label: '创建时间',
  265. sortable: 'custom',
  266. showOverflowTooltip: true,
  267. minWidth: 110,
  268. formatter: (_row, _column, cellValue) => {
  269. return this.$util.toDateString(cellValue);
  270. }
  271. },
  272. {
  273. columnKey: 'action',
  274. label: '操作',
  275. width: 200,
  276. align: 'left',
  277. resizable: false,
  278. slot: 'action',
  279. showOverflowTooltip: true
  280. }
  281. ],
  282. // 表格列配置
  283. columns1: [
  284. {
  285. columnKey: 'index',
  286. type: 'index',
  287. width: 55,
  288. align: 'center',
  289. showOverflowTooltip: true,
  290. fixed: 'left',
  291. label: '序号'
  292. },
  293. {
  294. prop: 'loginName',
  295. label: '用户账号',
  296. showOverflowTooltip: true,
  297. minWidth: 110
  298. },
  299. {
  300. prop: 'jobNumber',
  301. label: '工号',
  302. showOverflowTooltip: true,
  303. minWidth: 110
  304. },
  305. {
  306. prop: 'name',
  307. label: '姓名',
  308. showOverflowTooltip: true,
  309. minWidth: 110
  310. },
  311. {
  312. prop: 'phone',
  313. label: '手机号',
  314. showOverflowTooltip: true,
  315. minWidth: 110
  316. },
  317. {
  318. columnKey: 'groupRoleList',
  319. label: '角色',
  320. showOverflowTooltip: true,
  321. minWidth: 110,
  322. formatter: (_row, _column, cellValue) => {
  323. let names = [];
  324. _row.groupRoleList.forEach((item) => {
  325. names.push(...item.roleVOList.map((val) => val.name));
  326. });
  327. return names.toString();
  328. }
  329. },
  330. {
  331. prop: 'createTime',
  332. label: '创建时间',
  333. // sortable: 'custom',
  334. showOverflowTooltip: true,
  335. minWidth: 110,
  336. formatter: (_row, _column, cellValue) => {
  337. return this.$util.toDateString(cellValue);
  338. }
  339. }
  340. ],
  341. // 当前编辑数据
  342. current: null,
  343. // 是否显示编辑弹窗
  344. showEdit: false,
  345. statusOptions: [
  346. { value: 1, label: '全职' },
  347. { value: 2, label: '兼职' },
  348. { value: 3, label: '实习' },
  349. { value: 4, label: '正式' },
  350. { value: 5, label: '试用' },
  351. { value: 6, label: '离职' }
  352. ]
  353. };
  354. },
  355. methods: {
  356. async addUsers(row) {
  357. // this.userRow = null;
  358. this.currentRow = row;
  359. this.dialogVisible = true;
  360. },
  361. setUser() {
  362. this.dialogVisible = false;
  363. if (this.radio == 1) {
  364. this.userShow = true;
  365. } else {
  366. this.showEdit1 = true;
  367. this.$refs.userEdit.userBk(this.currentRow);
  368. }
  369. },
  370. getUser() {
  371. if (!this.userRow) {
  372. this.$message.warning('请选择一条数据!');
  373. return;
  374. }
  375. this.userShow = false;
  376. this.showEdit1 = true;
  377. this.$refs.userEdit.getByData(this.userRow, this.currentRow);
  378. },
  379. /* 表格数据源 */
  380. datasource({ page, limit, where, order }) {
  381. return getUserPage({
  382. ...where,
  383. ...order,
  384. pageNum: page,
  385. size: limit,
  386. groupId: this.organizationId
  387. });
  388. },
  389. /* 表格数据源 */
  390. datasource1({ page, limit, where, order }) {
  391. return pageUsers({ ...where, ...order, pageNum: page, size: limit });
  392. },
  393. /* 刷新表格 */
  394. reload(where) {
  395. this.$refs.table.reload({ pageNum: 1, where: where });
  396. },
  397. reload1(where) {
  398. this.$refs.table1.reload({ pageNum: 1, where: where });
  399. },
  400. exportUsers() {
  401. let where = this.$refs.searchRef.geValue();
  402. this.reload(where)
  403. exportUsers({ ...where, pageNum: 1, size: 10000, groupId: this.organizationId });
  404. },
  405. /* 显示编辑 */
  406. openEdit(row, disabled) {
  407. this.current = row;
  408. this.showEdit = true;
  409. this.$refs.userEditRef.setDisabled(disabled);
  410. },
  411. // 解除绑定
  412. toUnBind(row) {
  413. const loading = this.$loading({ lock: true });
  414. unbindLoginName(row.id)
  415. .then((res) => {
  416. loading.close();
  417. this.$message.success('解绑成功');
  418. this.reload();
  419. })
  420. .catch((e) => {
  421. loading.close();
  422. // this.$message.error(e.message);
  423. });
  424. },
  425. /* 删除 */
  426. remove(row) {
  427. const loading = this.$loading({ lock: true });
  428. removePersonnel([row.id])
  429. .then((msg) => {
  430. loading.close();
  431. this.$message.success(msg);
  432. this.reload();
  433. })
  434. .catch((e) => {
  435. loading.close();
  436. // this.$message.error(e.message);
  437. });
  438. },
  439. /* 更改状态 */
  440. editStatus(row) {
  441. const loading = this.$loading({ lock: true });
  442. updateUserStatus(row.userId, row.status)
  443. .then((msg) => {
  444. loading.close();
  445. this.$message.success(msg);
  446. })
  447. .catch((e) => {
  448. loading.close();
  449. row.status = !row.status ? 1 : 0;
  450. // this.$message.error(e.message);
  451. });
  452. },
  453. uploadFile() {
  454. this.$refs.importDialogRef.open();
  455. }
  456. },
  457. watch: {
  458. // 监听机构id变化
  459. organizationId() {
  460. this.reload();
  461. }
  462. }
  463. };
  464. </script>