admin.vue 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. <template>
  2. <div class="main-contain">
  3. <div class="position">
  4. <bread-crumb :crumbs="crumbs"></bread-crumb>
  5. <div>
  6. <el-button
  7. type="primary"
  8. size="small"
  9. icon="el-icon-circle-plus-outline"
  10. style="float:left"
  11. @click="openForm(0)">新增</el-button>
  12. <el-button
  13. type="primary"
  14. size="small"
  15. @click="BatchDelete"
  16. >医药师登记</el-button>
  17. </div>
  18. </div>
  19. <div class="app-container">
  20. <el-table
  21. :row-style="{ color: '#303133' }"
  22. :header-cell-style="{
  23. backgroundColor: 'rgb(245, 247, 250)',
  24. color: '#606266'
  25. }"
  26. style="width:100%;"
  27. ref="table"
  28. border
  29. :data="admins"
  30. v-loading="is_loading_admins"
  31. @selection-change="handleSelectionChange"
  32. >
  33. <el-table-column
  34. align="center"
  35. type="selection"
  36. width="55">
  37. </el-table-column>
  38. <el-table-column
  39. label="用户名"
  40. prop="user_name"
  41. min-width="160"
  42. align="center"
  43. ></el-table-column>
  44. <el-table-column
  45. label="最后登录IP"
  46. prop="ip"
  47. min-width="150"
  48. align="center"
  49. ></el-table-column>
  50. <el-table-column
  51. label="最后登录时间"
  52. prop="last_login_time"
  53. min-width="170"
  54. align="center"
  55. >
  56. <template slot-scope="scope">
  57. <span>{{
  58. scope.row.last_login_time == 0
  59. ? ""
  60. : _parseTime(scope.row.last_login_time, "{y}-{m}-{d} {h}:{i}")
  61. }}</span>
  62. </template>
  63. </el-table-column>
  64. <el-table-column
  65. label="角色"
  66. prop="role_name"
  67. min-width="160"
  68. align="center"
  69. ></el-table-column>
  70. <el-table-column label="状态" min-width="100" align="center">
  71. <template slot-scope="scope">
  72. <div
  73. v-if="scope.row.status == 1"
  74. style="color: #67C23A; font-size:20px;"
  75. >
  76. <li class="el-icon-success"></li>
  77. </div>
  78. <div v-else style="color: #F56C6C; font-size:20px;">
  79. <li class="el-icon-error"></li>
  80. </div>
  81. </template>
  82. </el-table-column>
  83. <el-table-column label="操作" width="240" align="center">
  84. <template slot-scope="scope">
  85. <!-- <router-link :to="{ path:'/role/admin/edit', query:{ id:scope.row.user_id }}"> -->
  86. <el-tooltip
  87. class="item"
  88. effect="dark"
  89. content="编辑"
  90. placement="top"
  91. >
  92. <el-button
  93. type="primary"
  94. icon="el-icon-edit-outline"
  95. size="small"
  96. @click="openForm(scope.row.user_id)"
  97. ></el-button>
  98. </el-tooltip>
  99. <!-- </router-link> -->
  100. <el-tooltip
  101. class="item"
  102. effect="dark"
  103. content="移除"
  104. placement="top"
  105. >
  106. <el-button
  107. type="danger"
  108. size="small"
  109. icon="el-icon-delete"
  110. v-if="
  111. scope.row.status == 1 &&
  112. org.creator != scope.row.user_id &&
  113. scope.row.user_id != local_user_id
  114. "
  115. @click="disableAdminAction(scope.row)"
  116. ></el-button>
  117. </el-tooltip>
  118. <el-tooltip
  119. class="item"
  120. effect="dark"
  121. content="恢复"
  122. placement="top"
  123. >
  124. <el-button
  125. size="small"
  126. type="info"
  127. icon="el-icon-refresh"
  128. v-if="
  129. scope.row.status == 0 &&
  130. org.creator != scope.row.user_id &&
  131. scope.row.user_id != local_user_id
  132. "
  133. @click="recoverAdminAction(scope.row)"
  134. ></el-button>
  135. </el-tooltip>
  136. <span v-if="scope.row.user_type == 2">
  137. <el-button type="primary" size="small" icon="el-icon-refresh-left" @click="toReturn(scope.row.user_id,scope.row.is_mark)">
  138. <span v-if="scope.row.is_mark ==0">登记</span>
  139. <span v-if="scope.row.is_mark ==1">撤销</span>
  140. </el-button>
  141. </span>
  142. </template>
  143. </el-table-column>
  144. </el-table>
  145. <el-row style="margin-top: 15px;" v-if="admin_total_count > 10">
  146. <el-col :span="24">
  147. <el-pagination
  148. :total="admin_total_count"
  149. :current-page.sync="current_page"
  150. @current-change="pageChange"
  151. :page-size="10"
  152. layout="total, prev, pager, next, jumper"
  153. ></el-pagination>
  154. </el-col>
  155. </el-row>
  156. <admin-info-form ref="admininfoform"></admin-info-form>
  157. </div>
  158. </div>
  159. </template>
  160. <script>
  161. import { adminMainView, getAdmins, setAdminStatus } from "@/api/role/admin";
  162. import { getRoles } from "@/api/role/role";
  163. import { parseTime } from "@/utils";
  164. import BreadCrumb from "@/xt_pages/components/bread-crumb";
  165. import AdminInfoForm from "./components/AdminInfoForm";
  166. import axios from 'axios'
  167. export default {
  168. name: "adminManage",
  169. data() {
  170. return {
  171. crumbs: [
  172. { path: false, name: "管理中心" },
  173. { path: false, name: "员工管理" }
  174. ],
  175. is_loading_admins: true,
  176. admins: [], // [{user_id, user_name, role_name, title_name, ip, last_login_time, status}]
  177. admin_total_count: 0,
  178. current_page: 1,
  179. roles: [],
  180. is_exist_role: false,
  181. org: null,
  182. isSubSuperAdmin: false,
  183. local_user_id: 0,
  184. selectDrug:[]
  185. };
  186. },
  187. components: {
  188. BreadCrumb,
  189. AdminInfoForm
  190. },
  191. created: function() {
  192. this.local_user_id = this.$store.getters.xt_user.user.id;
  193. let page = 1;
  194. this.getRoles(page);
  195. adminMainView()
  196. .then(rs => {
  197. this.is_loading_admins = false;
  198. var resp = rs.data;
  199. if (resp.state === 1) {
  200. var adminData = resp.data.admins
  201. console.log("数据",adminData)
  202. this.admins.push(...adminData);
  203. this.admin_total_count = resp.data.total_count;
  204. this.is_exist_role = resp.data.is_exist_role;
  205. this.current_page = 1;
  206. this.org = resp.data.org;
  207. this.isSubSuperAdmin = resp.data.isSubSuperAdmin;
  208. //能进入当前页面的角色只有超级管理员和子管理员,如果当前角色是子管理员,需要把超级管理员和其他子管理员的信息去除,子管理员不能编辑超级管理员和其他子管理员信息,
  209. if (this.isSubSuperAdmin) {
  210. //去除管理员信息
  211. for (let i = 0; i < this.admins.length; i++) {
  212. if (this.admins[i].user_id == this.org.creator) {
  213. this.admins.splice(i, 1);
  214. i--;
  215. }
  216. }
  217. //去除其他子管理员信息
  218. for (let i = 0; i < this.admins.length; i++) {
  219. if (
  220. this.admins[i].user_id != this.local_user_id &&
  221. this.admins[i].is_sub_super_admin
  222. ) {
  223. //将自己排除在外
  224. console.log(this.admins[i]);
  225. this.admins.splice(i, 1);
  226. i--;
  227. }
  228. }
  229. }
  230. } else {
  231. this.$message.error(resp.msg);
  232. }
  233. })
  234. .catch(err => {
  235. this.is_loading_admins = false;
  236. this.$message.error(err);
  237. });
  238. },
  239. computed: {
  240. should_update_admins() {
  241. return this.$store.getters.xt_role_temps.did_admins_changed;
  242. }
  243. },
  244. methods: {
  245. getRoles(page) {
  246. getRoles(page)
  247. .then(rs => {
  248. this.loading_roles = false;
  249. const resp = rs.data;
  250. if (resp.state === 1) {
  251. this.roles.push(...resp.data.roles);
  252. } else {
  253. this.$message.error(resp.msg);
  254. }
  255. })
  256. .catch(err => {
  257. this.loading_roles = false;
  258. this.$message.error(err);
  259. });
  260. },
  261. openForm(adminId) {
  262. this.$refs["admininfoform"].open(adminId, this.roles);
  263. },
  264. _parseTime(time, format) {
  265. return parseTime(time, format);
  266. },
  267. requestAdminsWithPage: function(page) {
  268. this.admins.splice(0, this.admins.length);
  269. this.is_loading_admins = true;
  270. getAdmins(page)
  271. .then(rs => {
  272. this.is_loading_admins = false;
  273. const resp = rs.data;
  274. console.log(resp);
  275. if (resp.state === 1) {
  276. var admindata = resp.data.admins
  277. this.admins.push(...admindata);
  278. this.admin_total_count = resp.data.total_count;
  279. } else {
  280. this.$message.error(resp.msg);
  281. }
  282. })
  283. .catch(err => {
  284. this.is_loading_admins = false;
  285. this.$message.error(err);
  286. });
  287. },
  288. addAdminAction: function() {
  289. this.$router.push({ path: "/role/admin/create" });
  290. },
  291. disableAdminAction: function(row) {
  292. this.$msgbox({
  293. title: "提示",
  294. message: "是否确定要移除该用户",
  295. showCancelButton: true,
  296. confirmButtonText: "确定",
  297. cancelButtonText: "取消",
  298. type: "warning",
  299. beforeClose: (action, instance, done) => {
  300. if (action === "confirm") {
  301. instance.confirmButtonLoading = true;
  302. instance.confirmButtonText = "删除中...";
  303. setAdminStatus(row.user_id, false)
  304. .then(rs => {
  305. done();
  306. instance.confirmButtonLoading = false;
  307. const resp = rs.data;
  308. if (resp.state === 1) {
  309. row.status = 0;
  310. } else {
  311. this.$message.error(resp.msg);
  312. }
  313. })
  314. .catch(err => {
  315. done();
  316. instance.confirmButtonLoading = false;
  317. this.$message.error(err);
  318. });
  319. } else {
  320. done();
  321. }
  322. }
  323. });
  324. },
  325. recoverAdminAction: function(row) {
  326. const loading = this.$loading({
  327. lock: true,
  328. text: "正在恢复管理员...",
  329. spinner: "el-icon-loading",
  330. background: "rgba(0, 0, 0, 0.7)"
  331. });
  332. setAdminStatus(row.user_id, true)
  333. .then(rs => {
  334. loading.close();
  335. const resp = rs.data;
  336. if (resp.state === 1) {
  337. row.status = 1;
  338. } else {
  339. this.$message.error(resp.msg);
  340. }
  341. })
  342. .catch(err => {
  343. loading.close();
  344. this.$message.error(err);
  345. });
  346. },
  347. pageChange: function(nextPage) {
  348. this.requestAdminsWithPage(nextPage);
  349. },
  350. // toLogin(){
  351. // var that = this
  352. // axios.get('http://127.0.0.1:9532/sz/api/doctor/get').then(function(response) {
  353. // if (response.data.state == 0) {
  354. // that.$message.error(response.data.msg)
  355. // return false
  356. // } else {
  357. // that.$message({ message: '登记成功', type: 'success' })
  358. // }
  359. // }).catch(function(error) {
  360. // })
  361. // },
  362. BatchDelete() {
  363. if (this.selectDrug.length == 0) {
  364. this.$message.error("请选择要登记的信息");
  365. return false;
  366. }
  367. this.$confirm(
  368. "确认要登记所选记录吗? <br>",
  369. "备案提示",
  370. {
  371. dangerouslyUseHTMLString: true,
  372. confirmButtonText: "确定",
  373. cancelButtonText: "取消",
  374. type: "warning"
  375. }
  376. ).then(() => {
  377. var ids = [];
  378. var idMap = {};
  379. console.log("3333333",this.selectDrug)
  380. for (const index in this.selectDrug) {
  381. ids.push(this.selectDrug[index].user_id);
  382. idMap[this.selectDrug[index].user_id] = this.selectDrug[index].user_id;
  383. }
  384. console.log('ids222222222',ids)
  385. var idss = ids.join(',')
  386. let params = {
  387. ids:idss,
  388. admin_user_id:this.$store.getters.xt_user.user.id
  389. }
  390. console.log("prams222",params)
  391. var that = this
  392. axios.get('http://127.0.0.1:9532/sz/api/doctor/get',{ params: params }).then(function(response) {
  393. if (response.data.state == 0) {
  394. that.$message.error(response.data.msg)
  395. return false
  396. } else {
  397. that.$message({ message: '操作成功', type: 'success' })
  398. that.adminMainView()
  399. }
  400. }).catch(function(error) {
  401. })
  402. });
  403. },
  404. toReturn(id,is_mark){
  405. var that = this
  406. let params = {
  407. 'id':id,
  408. "is_mark":is_mark,
  409. "admin_user_id":this.$store.getters.xt_user.user.id
  410. }
  411. console.log("params222222222",params)
  412. axios.get('http://127.0.0.1:9532/sz/api/medical/get',{params:params}).then(function(response) {
  413. if (response.data.state == 0) {
  414. that.$message.error(response.data.msg)
  415. return false
  416. } else {
  417. // that.$message({ message: '操作成功', type: 'success' })
  418. this.$message.error(response.data.msg)
  419. that.adminMainView()
  420. }
  421. }).catch(function(error) {
  422. })
  423. },
  424. handleSelectionChange(val) {
  425. this.selectDrug = val;
  426. },
  427. },
  428. watch: {
  429. should_update_admins(should_change) {
  430. if (should_change) {
  431. this.requestAdminsWithPage(this.current_page);
  432. }
  433. }
  434. }
  435. };
  436. </script>
  437. <style rel="stylesheet/scss" lang="scss" scoped>
  438. .el-button + .el-button {
  439. margin-left: 0 !important;
  440. }
  441. </style>
  442. <style>
  443. .el-table td,
  444. .el-table th.is-leaf,
  445. .el-table--border,
  446. .el-table--group {
  447. border-color: #d0d3da;
  448. }
  449. .el-table--border::after,
  450. .el-table--group::after,
  451. .el-table::before {
  452. background-color: #d0d3da;
  453. }
  454. </style>