org-user-list.vue 16 KB

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