guhongwei 5 years ago
parent
commit
c0f2a470f7
5 changed files with 173 additions and 14 deletions
  1. 45 0
      src/store/department.js
  2. 8 1
      src/store/index.js
  3. 45 0
      src/store/level.js
  4. 39 0
      src/store/registers.js
  5. 36 13
      src/views/register.vue

+ 45 - 0
src/store/department.js

@@ -0,0 +1,45 @@
+import Vue from 'vue';
+import Vuex from 'vuex';
+import _ from 'lodash';
+Vue.use(Vuex);
+const api = {
+  departmentInfo: `/api/count/department`,
+};
+const state = () => ({});
+const mutations = {};
+
+const actions = {
+  async query({ commit }, { skip = 0, limit = 10, ...info } = {}) {
+    const res = await this.$axios.$get(api.departmentInfo, {
+      skip,
+      limit,
+      ...info,
+    });
+    return res;
+  },
+  async create({ commit }, payload) {
+    const res = await this.$axios.$post(`${api.departmentInfo}`, payload);
+    return res;
+  },
+  async fetch({ commit }, payload) {
+    const res = await this.$axios.$get(`${api.departmentInfo}/${payload}`);
+    return res;
+  },
+  async update({ commit }, { id, ...info } = {}) {
+    const res = await this.$axios.$post(`${api.departmentInfo}/${id}`, {
+      ...info,
+    });
+    return res;
+  },
+  async delete({ commit }, payload) {
+    const res = await this.$axios.$delete(`${api.departmentInfo}/${payload}`);
+    return res;
+  },
+};
+
+export default {
+  namespaced: true,
+  state,
+  mutations,
+  actions,
+};

+ 8 - 1
src/store/index.js

@@ -2,6 +2,9 @@ import Vue from 'vue';
 import Vuex from 'vuex';
 import Vuex from 'vuex';
 import * as ustate from './user/state';
 import * as ustate from './user/state';
 import * as umutations from './user/mutations';
 import * as umutations from './user/mutations';
+import registers from './registers';
+import department from './department';
+import level from './level';
 
 
 Vue.use(Vuex);
 Vue.use(Vuex);
 
 
@@ -9,5 +12,9 @@ export default new Vuex.Store({
   state: { ...ustate },
   state: { ...ustate },
   mutations: { ...umutations },
   mutations: { ...umutations },
   actions: {},
   actions: {},
-  modules: {},
+  modules: {
+    registers,
+    department,
+    level,
+  },
 });
 });

+ 45 - 0
src/store/level.js

@@ -0,0 +1,45 @@
+import Vue from 'vue';
+import Vuex from 'vuex';
+import _ from 'lodash';
+Vue.use(Vuex);
+const api = {
+  levelInfo: `/api/count/level`,
+};
+const state = () => ({});
+const mutations = {};
+
+const actions = {
+  async query({ commit }, { skip = 0, limit = 10, ...info } = {}) {
+    const res = await this.$axios.$get(api.levelInfo, {
+      skip,
+      limit,
+      ...info,
+    });
+    return res;
+  },
+  async create({ commit }, payload) {
+    const res = await this.$axios.$post(`${api.levelInfo}`, payload);
+    return res;
+  },
+  async fetch({ commit }, payload) {
+    const res = await this.$axios.$get(`${api.levelInfo}/${payload}`);
+    return res;
+  },
+  async update({ commit }, { id, ...info } = {}) {
+    const res = await this.$axios.$post(`${api.levelInfo}/${id}`, {
+      ...info,
+    });
+    return res;
+  },
+  async delete({ commit }, payload) {
+    const res = await this.$axios.$delete(`${api.levelInfo}/${payload}`);
+    return res;
+  },
+};
+
+export default {
+  namespaced: true,
+  state,
+  mutations,
+  actions,
+};

+ 39 - 0
src/store/registers.js

@@ -0,0 +1,39 @@
+import Vue from 'vue';
+import Vuex from 'vuex';
+import _ from 'lodash';
+Vue.use(Vuex);
+const api = {
+  registerInfo: `/api/count/user/register`,
+};
+const state = () => ({});
+const mutations = {};
+
+const actions = {
+  async query({ commit }, { skip = 0, limit = 10, ...info } = {}) {
+    const res = await this.$axios.$get(api.registerInfo, { skip, limit, ...info });
+    return res;
+  },
+  async create({ commit }, payload) {
+    const res = await this.$axios.$post(`${api.registerInfo}`, payload);
+    return res;
+  },
+  async fetch({ commit }, payload) {
+    const res = await this.$axios.$get(`${api.registerInfo}/${payload}`);
+    return res;
+  },
+  async update({ commit }, { id, ...info } = {}) {
+    const res = await this.$axios.$post(`${api.registerInfo}/${id}`, { ...info });
+    return res;
+  },
+  async delete({ commit }, payload) {
+    const res = await this.$axios.$delete(`${api.registerInfo}/${payload}`);
+    return res;
+  },
+};
+
+export default {
+  namespaced: true,
+  state,
+  mutations,
+  actions,
+};

+ 36 - 13
src/views/register.vue

@@ -22,7 +22,7 @@
                     <el-input v-model="form.name" placeholder="请输入姓名"></el-input>
                     <el-input v-model="form.name" placeholder="请输入姓名"></el-input>
                   </el-form-item>
                   </el-form-item>
                   <el-form-item label="手机号" prop="phone">
                   <el-form-item label="手机号" prop="phone">
-                    <el-input v-model="form.phone" placeholder="请输入手机号"></el-input>
+                    <el-input v-model="form.phone" placeholder="请输入手机号" maxlength="11"></el-input>
                   </el-form-item>
                   </el-form-item>
                   <el-form-item label="密码" prop="passwd">
                   <el-form-item label="密码" prop="passwd">
                     <el-input v-model="form.passwd" placeholder="请输入密码" show-password></el-input>
                     <el-input v-model="form.passwd" placeholder="请输入密码" show-password></el-input>
@@ -53,7 +53,7 @@
                     </el-select>
                     </el-select>
                   </el-form-item>
                   </el-form-item>
                   <el-form-item label="担任职务" prop="level_id" v-if="form.type == '0' || form.type == '1'">
                   <el-form-item label="担任职务" prop="level_id" v-if="form.type == '0' || form.type == '1'">
-                    <el-select v-model="form.level_id" filterable @change="selectChild">
+                    <el-select v-model="form.level_id" filterable>
                       <el-option v-for="(item, index) in levelList" :key="index" :value="item.id" :label="item.name"></el-option>
                       <el-option v-for="(item, index) in levelList" :key="index" :value="item.id" :label="item.name"></el-option>
                     </el-select>
                     </el-select>
                   </el-form-item>
                   </el-form-item>
@@ -128,6 +128,9 @@ import menus from '@/layout/common/menus.vue';
 import foot from '@/layout/common/foot.vue';
 import foot from '@/layout/common/foot.vue';
 import upload from '@/components/uploadone.vue';
 import upload from '@/components/uploadone.vue';
 import { mapState, createNamespacedHelpers } from 'vuex';
 import { mapState, createNamespacedHelpers } from 'vuex';
+const { mapActions: registers } = createNamespacedHelpers('registers');
+const { mapActions: department } = createNamespacedHelpers('department');
+const { mapActions: level } = createNamespacedHelpers('level');
 export default {
 export default {
   name: 'register',
   name: 'register',
   props: {},
   props: {},
@@ -168,6 +171,7 @@ export default {
       },
       },
       // 部门
       // 部门
       deptList: [],
       deptList: [],
+      dept_id: '',
       // 职务
       // 职务
       levelList: [],
       levelList: [],
       // 学历
       // 学历
@@ -202,26 +206,45 @@ export default {
       ],
       ],
     };
     };
   },
   },
-  created() {},
+  created() {
+    this.searchInfo();
+  },
   methods: {
   methods: {
+    ...registers(['create']),
+    ...department({ departmentQuery: 'query', departmentFetch: 'fetch' }),
+    ...level({ levelQuery: 'query', levelFetch: 'fetch' }),
+    // 部门
+    async searchInfo() {
+      let res = await this.departmentQuery();
+      if (this.$checkRes(res)) {
+        this.$set(this, `deptList`, res.data);
+      }
+    },
+    // 职务
+    async selectChild(dept_id) {
+      let res = await this.levelQuery(dept_id);
+      if (this.$checkRes(res)) {
+        this.$set(this, `levelList`, res.data);
+      }
+    },
+    // 提交
     submitForm(formName) {
     submitForm(formName) {
-      this.$refs[formName].validate(valid => {
+      this.$refs[formName].validate(async valid => {
         if (valid) {
         if (valid) {
-          alert('submit!');
+          let res = await this.create(this.form);
+          if (this.$checkRes(res)) {
+            this.$message({
+              message: '恭喜你,注册成功',
+              type: 'success',
+            });
+            this.$router.push({ path: '/login' });
+          }
         } else {
         } else {
           console.log('error submit!!');
           console.log('error submit!!');
           return false;
           return false;
         }
         }
       });
       });
     },
     },
-    selectChild(type_id) {
-      console.log(type_id);
-      // let res = this.columnList.filter(fil => fil.id === product_type_id);
-      // if (res.length > 0) {
-      //   this.$set(this.form, `product_type_name`, res[0].name);
-      // }
-      // this.$forceUpdate();
-    },
     uploadSuccess({ type, data }) {
     uploadSuccess({ type, data }) {
       this.$set(this.form, `${type}`, data.uri);
       this.$set(this.form, `${type}`, data.uri);
     },
     },