瀏覽代碼

转让管理员更新成功

guhongwei 5 年之前
父節點
當前提交
b02606bb7a
共有 2 個文件被更改,包括 31 次插入4 次删除
  1. 5 0
      src/store.js
  2. 26 4
      src/views/info/hr/index.vue

+ 5 - 0
src/store.js

@@ -8,6 +8,8 @@ const api = {
   corpBase: '/api/corp/corps/{corpid}',
   hr: '/api/corp/corps/{corpid}/users', //list,add
   hrImp: '/api/corp/users/{id}', //查询:id:手机号,用户肯定不知道id啊!那就手机号呗;修改:用id
+  // 转让管理员
+  hrChange: '/api/corp/users/{id}/role',
   corpIdentity: '/api/corp/corps/{corpid}/identity',
   corpSchInfo: '/api/corp/corps/{corpid}/schs',
   schs: '/api/corp/schs', //get:按学校查询入驻企业列表;post:申请入驻学校
@@ -189,6 +191,9 @@ export default new Vuex.Store({
         let { info } = data;
         let { passwd, id } = info;
         result = await this.$axios.$post(api.hrImp, { passwd: passwd }, { id: id });
+      } else if (type === 'change') {
+        let { corpid, adminid, id } = data;
+        result = await this.$axios.$post(api.hrChange, { corpid: corpid, adminid: adminid }, { id: id });
       } else {
         result = await this.$axios.$get(api.hr, { corpid: data });
       }

+ 26 - 4
src/views/info/hr/index.vue

@@ -121,7 +121,7 @@ import bind from '@/components/bind.vue';
 // import search from '@/components/search.vue';
 import listNormal from '@/layout/list-normal.vue';
 import _ from 'lodash';
-import { mapActions, mapState } from 'vuex';
+import { mapActions, mapState, mapMutations } from 'vuex';
 export default {
   name: 'index',
   // metaInfo: {
@@ -153,11 +153,13 @@ export default {
   created() {
     this.search();
     this.otherList();
+    this.setUser();
   },
   computed: {
     ...mapState(['user']),
   },
   methods: {
+    ...mapMutations(['setUser']),
     ...mapActions(['getList', 'hrOperation']),
     async search() {
       let result;
@@ -257,12 +259,12 @@ export default {
       console.log(item.mobile);
       let result = await this.hrOperation({ type: 'search', data: { tel: item.mobile } });
       this.$set(this, `formUser`, result.data);
-      console.log(result.data);
       this.dialogUser = true;
     },
     async otherList() {
       let result = await this.hrOperation({ type: 'list', data: this.user.corpid });
       if (`${result.errcode}` === '0') {
+        console.log(result.data);
         this.$set(this, `regionList`, result.data);
       } else {
         this.$message.error(result.errmsg ? result.errmsg : 'error');
@@ -272,9 +274,29 @@ export default {
       let res = this.regionList.filter(item => {
         return `${item.name}` === `${select}`;
       });
+      console.log(res);
     },
-    onSubmitUser() {
-      this.dialogUser = false;
+    async onSubmitUser() {
+      let adminres = this.regionList.filter(item => item.role === '0');
+      let adminid;
+      for (const item of adminres) {
+        adminid = item._id;
+      }
+      let newres = this.regionList.filter(item => item.role === '1');
+      let newid;
+      for (const item of newres) {
+        newid = item._id;
+      }
+      let result = await this.hrOperation({ type: 'change', data: { corpid: this.user.corpid, adminid: adminid, id: newid } });
+      if (`${result.errcode}` === '0') {
+        this.$message.success('修改管理成功');
+        sessionStorage.removeItem('token');
+        sessionStorage.removeItem('user');
+        this.setUser(undefined);
+        this.$router.push('/login');
+      } else {
+        this.$message.error(result.errmsg);
+      }
     },
   },
 };