org-user-list.vue 17 KB

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