org-user-list.vue 12 KB

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