org-user-list.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. </org-user-search>
  26. </template>
  27. <!-- 角色列 -->
  28. <template v-slot:roles="{ row }">
  29. <el-tag
  30. v-for="item in row.roles"
  31. :key="item.roleId"
  32. type="primary"
  33. size="mini"
  34. :disable-transitions="true"
  35. >
  36. {{ item.roleName }}
  37. </el-tag>
  38. </template>
  39. <!-- 状态列 -->
  40. <!-- <template v-slot:status="{ row }">
  41. <el-switch
  42. :active-value="0"
  43. :inactive-value="1"
  44. v-model="row.status"
  45. @change="editStatus(row)"
  46. />
  47. </template> -->
  48. <!-- 操作列 -->
  49. <template v-slot:action="{ row }">
  50. <el-link
  51. type="primary"
  52. :underline="false"
  53. icon="el-icon-edit"
  54. @click="openEdit(row)"
  55. >
  56. 修改
  57. </el-link>
  58. <el-link
  59. v-if="row.loginName"
  60. type="primary"
  61. :underline="false"
  62. icon="el-icon-unlock"
  63. @click="toUnBind(row)"
  64. >
  65. 解绑
  66. </el-link>
  67. <el-popconfirm
  68. class="ele-action"
  69. title="确定要删除此用户吗?"
  70. @confirm="remove(row)"
  71. >
  72. <template v-slot:reference>
  73. <el-link type="danger" :underline="false" icon="el-icon-delete">
  74. 删除
  75. </el-link>
  76. </template>
  77. </el-popconfirm>
  78. </template>
  79. </ele-pro-table>
  80. <!-- 编辑弹窗 -->
  81. <org-user-edit
  82. :data="current"
  83. :visible.sync="showEdit"
  84. :organization-list="organizationList"
  85. :organization-id="organizationId"
  86. @done="reload"
  87. />
  88. </div>
  89. </template>
  90. <script>
  91. import OrgUserSearch from './org-user-search.vue';
  92. import OrgUserEdit from './org-user-edit.vue';
  93. import { getUserPage , removePersonnel , unbindLoginName } from '@/api/system/organization';
  94. export default {
  95. components: { OrgUserSearch, OrgUserEdit },
  96. props: {
  97. // 机构id
  98. organizationId: [Number,String],
  99. // 全部机构
  100. organizationList: Array
  101. },
  102. data() {
  103. return {
  104. // 表格列配置
  105. columns: [
  106. {
  107. columnKey: 'index',
  108. type: 'index',
  109. width: 45,
  110. align: 'center',
  111. showOverflowTooltip: true,
  112. fixed: 'left'
  113. },
  114. {
  115. prop: 'name',
  116. label: '姓名',
  117. sortable: 'custom',
  118. showOverflowTooltip: true,
  119. minWidth: 110
  120. },
  121. {
  122. prop: 'jobNumber',
  123. label: '工号',
  124. sortable: 'custom',
  125. showOverflowTooltip: true,
  126. minWidth: 110
  127. },
  128. {
  129. prop: 'loginName',
  130. label: '用户账号',
  131. sortable: 'custom',
  132. showOverflowTooltip: true,
  133. minWidth: 110
  134. },
  135. {
  136. prop: 'sex',
  137. label: '性别',
  138. sortable: 'custom',
  139. showOverflowTooltip: true,
  140. minWidth: 80,
  141. formatter: (_row, _column, cellValue) => {
  142. return cellValue==1?'男':(cellValue==2?'女':'');
  143. }
  144. },
  145. {
  146. prop: 'status',
  147. label: '状态',
  148. align: 'center',
  149. sortable: 'custom',
  150. width: 80,
  151. formatter: (_row, _column, cellValue) => {
  152. const dom = this.statusOptions.find(item => {
  153. return item.value == cellValue
  154. })
  155. return dom?dom.label:'';
  156. }
  157. },
  158. {
  159. prop: 'createTime',
  160. label: '创建时间',
  161. sortable: 'custom',
  162. showOverflowTooltip: true,
  163. minWidth: 110,
  164. formatter: (_row, _column, cellValue) => {
  165. return this.$util.toDateString(cellValue);
  166. }
  167. },
  168. {
  169. columnKey: 'action',
  170. label: '操作',
  171. width: 200,
  172. align: 'left',
  173. resizable: false,
  174. slot: 'action',
  175. showOverflowTooltip: true
  176. }
  177. ],
  178. // 当前编辑数据
  179. current: null,
  180. // 是否显示编辑弹窗
  181. showEdit: false,
  182. statusOptions:[
  183. {value:1,label:'全职'},
  184. {value:2,label:'兼职'},
  185. {value:3,label:'实习'},
  186. {value:4,label:'正式'},
  187. {value:5,label:'试用'},
  188. {value:6,label:'离职'}
  189. ],
  190. };
  191. },
  192. methods: {
  193. /* 表格数据源 */
  194. datasource({ page, limit, where, order }) {
  195. return getUserPage({
  196. ...where,
  197. ...order,
  198. pageNum:page,
  199. size:limit,
  200. groupId: this.organizationId
  201. });
  202. },
  203. /* 刷新表格 */
  204. reload(where) {
  205. this.$refs.table.reload({ pageNum: 1, where: where });
  206. },
  207. /* 显示编辑 */
  208. openEdit(row) {
  209. this.current = row;
  210. this.showEdit = true;
  211. },
  212. // 解除绑定
  213. toUnBind(row){
  214. const loading = this.$loading({ lock: true });
  215. unbindLoginName(row.id).then(res=>{
  216. loading.close();
  217. this.$message.success('解绑成功');
  218. this.reload();
  219. })
  220. .catch((e) => {
  221. loading.close();
  222. // this.$message.error(e.message);
  223. });
  224. },
  225. /* 删除 */
  226. remove(row) {
  227. const loading = this.$loading({ lock: true });
  228. removePersonnel([row.id])
  229. .then((msg) => {
  230. loading.close();
  231. this.$message.success(msg);
  232. this.reload();
  233. })
  234. .catch((e) => {
  235. loading.close();
  236. this.$message.error(e.message);
  237. });
  238. },
  239. /* 更改状态 */
  240. editStatus(row) {
  241. const loading = this.$loading({ lock: true });
  242. updateUserStatus(row.userId, row.status)
  243. .then((msg) => {
  244. loading.close();
  245. this.$message.success(msg);
  246. })
  247. .catch((e) => {
  248. loading.close();
  249. row.status = !row.status ? 1 : 0;
  250. this.$message.error(e.message);
  251. });
  252. }
  253. },
  254. watch: {
  255. // 监听机构id变化
  256. organizationId() {
  257. this.reload();
  258. }
  259. }
  260. };
  261. </script>