UserManagement.vue 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <template>
  2. <div>
  3. <el-dialog class="userDialog" title="用户管理" width="660px" :visible.sync="visible">
  4. <div class="userManagement">
  5. <el-table
  6. v-loading="loading"
  7. :row-style="{ color: '#303133' }"
  8. :header-cell-style="{
  9. backgroundColor: 'rgb(245, 247, 250)',
  10. color: '#606266'
  11. }"
  12. style="width:100%;"
  13. ref="table"
  14. border
  15. :data="admin_user"
  16. >
  17. <el-table-column prop="name" label="员工姓名" width="120">
  18. <template slot-scope="scope">
  19. {{scope.row.user_name}}
  20. </template>
  21. </el-table-column>
  22. <!--<el-table-column prop="date" label="登录账号" width="120">-->
  23. <!--<template slot-scope="scope">-->
  24. <!--{{}}-->
  25. <!--</template>-->
  26. <!--</el-table-column>-->
  27. <el-table-column prop="date" label="最后登录时间" width="180">
  28. <template slot-scope="scope">
  29. <span>{{
  30. scope.row.last_login_time == 0
  31. ? ""
  32. : _parseTime(scope.row.last_login_time, "{y}-{m}-{d} {h}:{i}")
  33. }}</span>
  34. </template>
  35. </el-table-column>
  36. <el-table-column label="操作" >
  37. <template slot-scope="scope" style="text-align: center">
  38. <el-tooltip class="item" effect="dark" content="编辑" placement="top">
  39. <el-button type="primary" icon="el-icon-edit-outline" size="small"
  40. v-if="org.creator != scope.row.user_id && (scope.row.user_id != local_user_id) && !scope.row.is_sub_super_admin"
  41. @click="openForm(scope.row.user_id, role_id)" ></el-button>
  42. </el-tooltip>
  43. <el-tooltip
  44. class="item"
  45. effect="dark"
  46. content="移除"
  47. placement="top"
  48. >
  49. <el-button
  50. type="danger"
  51. size="small"
  52. icon="el-icon-delete"
  53. v-if="scope.row.status == 1 && org.creator != scope.row.user_id && (scope.row.user_id != local_user_id) && !scope.row.is_sub_super_admin"
  54. @click="disableAdminAction(scope.row)"
  55. ></el-button>
  56. </el-tooltip>
  57. <el-tooltip
  58. class="item"
  59. effect="dark"
  60. content="恢复"
  61. placement="top"
  62. >
  63. <el-button
  64. size="small"
  65. type="info"
  66. icon="el-icon-refresh"
  67. v-if="scope.row.status == 0 && org.creator != scope.row.user_id && (scope.row.user_id != local_user_id ) && !scope.row.is_sub_super_admin"
  68. @click="recoverAdminAction(scope.row)"
  69. ></el-button>
  70. </el-tooltip>
  71. </template>
  72. </el-table-column>
  73. </el-table>
  74. </div>
  75. </el-dialog>
  76. <!--<admin-info-form ref="admininfoform"></admin-info-form>-->
  77. <admin-role-info-form ref="admininfoform" @did-edit-admin="didModifyAdmin"></admin-role-info-form>
  78. </div>
  79. </template>
  80. <script>
  81. import { getRoleStaff } from '@/api/role/role'
  82. import { parseTime } from "@/utils";
  83. import { setAdminStatus } from "@/api/role/admin";
  84. // import AdminInfoForm from './AdminInfoForm'
  85. import AdminRoleInfoForm from './AdminRoleInfoForm'
  86. export default {
  87. components: { AdminRoleInfoForm },
  88. data() {
  89. return {
  90. visible: false,
  91. role_id: 0,
  92. admin_user: [],
  93. local_user_id: 0,
  94. org:null,
  95. loading:false,
  96. }
  97. },
  98. methods: {
  99. didModifyAdmin(){
  100. this.GetAllStaff()
  101. this.$refs["admininfoform"].close();
  102. },
  103. openForm(adminId,role_id) {
  104. this.$refs["admininfoform"].open(adminId,role_id);
  105. },
  106. disableAdminAction: function(row) {
  107. this.$msgbox({
  108. title: "提示",
  109. message: "是否确定要移除该用户",
  110. showCancelButton: true,
  111. confirmButtonText: "确定",
  112. cancelButtonText: "取消",
  113. type: "warning",
  114. beforeClose: (action, instance, done) => {
  115. if (action === "confirm") {
  116. instance.confirmButtonLoading = true;
  117. instance.confirmButtonText = "删除中...";
  118. setAdminStatus(row.user_id, false)
  119. .then(rs => {
  120. done();
  121. instance.confirmButtonLoading = false;
  122. const resp = rs.data;
  123. if (resp.state === 1) {
  124. row.status = 0;
  125. } else {
  126. this.$message.error(resp.msg);
  127. }
  128. })
  129. .catch(err => {
  130. done();
  131. instance.confirmButtonLoading = false;
  132. this.$message.error(err);
  133. });
  134. } else {
  135. done();
  136. }
  137. }
  138. });
  139. },
  140. recoverAdminAction: function(row) {
  141. const loading = this.$loading({
  142. lock: true,
  143. text: "正在恢复管理员...",
  144. spinner: "el-icon-loading",
  145. background: "rgba(0, 0, 0, 0.7)"
  146. });
  147. setAdminStatus(row.user_id, true)
  148. .then(rs => {
  149. loading.close();
  150. const resp = rs.data;
  151. if (resp.state === 1) {
  152. row.status = 1;
  153. } else {
  154. this.$message.error(resp.msg);
  155. }
  156. })
  157. .catch(err => {
  158. loading.close();
  159. this.$message.error(err);
  160. });
  161. },
  162. _parseTime(time, format) {
  163. return parseTime(time, format);
  164. },
  165. GetAllStaff: function() {
  166. this.loading = true
  167. getRoleStaff().then(response => {
  168. this.loading = false
  169. if (response.data.state === 1) {
  170. this.admin_user = response.data.data.admins
  171. this.org = response.data.data.org
  172. for (let i = 0; i < this.admin_user.length; i++) {
  173. if (this.admin_user[i].role_ids.length > 0) {
  174. let isExist = -1
  175. let ids = this.admin_user[i].role_ids.split(',')
  176. isExist = ids.indexOf(this.role_id.toString())
  177. if (isExist < 0) {
  178. this.admin_user.splice(i, 1)
  179. i = i - 1
  180. }
  181. }
  182. }
  183. } else {
  184. this.$toast({
  185. message: response.data.msg
  186. })
  187. }
  188. }).catch(err => {
  189. this.loading = false
  190. this.$message.error(err)
  191. })
  192. },
  193. show(role_id) {
  194. this.visible = true
  195. this.role_id = role_id
  196. this.admin_user = []
  197. this.local_user_id = this.$store.getters.xt_user.user.id
  198. this.local_user_id = 597
  199. this.GetAllStaff()
  200. }
  201. }
  202. }
  203. </script>
  204. <style lang="scss" scoped>
  205. .userManagement {
  206. .cell {
  207. text-align: center;
  208. }
  209. }
  210. </style>
  211. <style lang="scss">
  212. .userManagement {
  213. .cell {
  214. text-align: center;
  215. }
  216. }
  217. </style>