guhongwei 4 tahun lalu
induk
melakukan
696119101c
3 mengubah file dengan 258 tambahan dan 1 penghapusan
  1. 7 0
      src/router/index.js
  2. 6 1
      src/views/classes/name-list.vue
  3. 245 0
      src/views/student/createStu.vue

+ 7 - 0
src/router/index.js

@@ -162,6 +162,13 @@ const routes = [
         meta: { title: '班主任信息', sub: '管理' },
         component: () => import('@/views/directorInfo/index.vue'),
       },
+      // 09-16
+      {
+        path: '/student/createStu',
+        name: 'student_createStu',
+        meta: { title: '学生信息', sub: '管理' },
+        component: () => import('@/views/student/createStu.vue'),
+      },
     ],
   },
   {

+ 6 - 1
src/views/classes/name-list.vue

@@ -9,6 +9,7 @@
           </el-input>
         </el-col>
         <el-col :span="12">
+          <el-button type="primary" size="mini" @click="addstu()">添加学生</el-button>
           <el-button type="primary" size="mini" @click="toComputIsFine()" :disabled="this.defaultOption.classid ? false : true">设置优秀学员</el-button>
         </el-col>
       </el-col>
@@ -81,7 +82,7 @@ export default {
         { label: '性别', prop: 'gender' },
         { label: '民族', prop: 'nation' },
         { label: '学校', prop: 'school_name' },
-        { label: '院系', prop: 'yard' },
+        { label: '院系', prop: 'faculty' },
         { label: '专业', prop: 'major' },
         { label: '职务', prop: 'job' },
         { label: '手机号', prop: 'phone' },
@@ -130,6 +131,10 @@ export default {
         }
       }
     },
+    // 添加
+    addstu() {
+      this.$router.push({ path: '/student/createStu' });
+    },
     toEdit({ data }) {
       this.$router.push({ path: '/student/detail', query: { id: data.id } });
     },

+ 245 - 0
src/views/student/createStu.vue

@@ -0,0 +1,245 @@
+<template>
+  <div id="detail">
+    <detail-frame :title="mainTitle" returns="/student/index">
+      <data-form :data="info" :fields="fields" :rules="rules" @save="handleSave" :isNew="isNew" @filterReturn="termChange">
+        <template #options="{item}">
+          <template v-if="item.model === 'school_name'">
+            <el-option v-for="(item, index) in schcoolList" :key="index" :label="item.name" :value="item.name"></el-option>
+          </template>
+          <template v-if="item.model === 'nation'">
+            <el-option v-for="(item, index) in nationList" :key="index" :label="item.name" :value="item.name"></el-option>
+          </template>
+          <!-- 期 -->
+          <template v-if="item.model === 'termid'">
+            <el-option v-for="(item, index) in termList" :key="index" :label="item.term" :value="item._id"></el-option>
+          </template>
+          <!-- 批次 -->
+          <template v-if="item.model === 'batchid'">
+            <el-option v-for="(item, index) in batchList" :key="index" :label="item.batch" :value="item._id"></el-option>
+          </template>
+          <!-- 班级 -->
+          <template v-if="item.model === 'classid'">
+            <el-option v-for="(item, index) in classList" :key="index" :label="item.name" :value="item.id"></el-option>
+          </template>
+        </template>
+        <template #radios="{item}">
+          <template v-if="item.model === 'gender'">
+            <el-radio label="男">男</el-radio>
+            <el-radio label="女">女</el-radio>
+          </template>
+          <template v-else>
+            <el-radio label="1">是</el-radio>
+            <el-radio label="0">否</el-radio>
+          </template>
+          <template v-if="item.model === 'floor'">
+            <el-radio v-for="i in 5" :key="i" :label="`${i}楼`">{{ `${i}楼` }}</el-radio>
+          </template>
+        </template>
+      </data-form>
+    </detail-frame>
+  </div>
+</template>
+
+<script>
+import _ from 'lodash';
+import detailFrame from '@frame/layout/admin/detail-frame';
+import dataForm from '@frame/components/form';
+import { mapState, createNamespacedHelpers } from 'vuex';
+const { mapActions } = createNamespacedHelpers('student');
+const { mapActions: mapNation } = createNamespacedHelpers('nation');
+const { mapActions: mapschool } = createNamespacedHelpers('school');
+const { mapActions: trainplan } = createNamespacedHelpers('trainplan');
+const { mapActions: classes } = createNamespacedHelpers('classes');
+//缺少字典表:学校表,民族表,院系表,专业表
+export default {
+  metaInfo: { title: '学生信息' },
+  name: 'detail',
+  props: {},
+  components: {
+    detailFrame,
+    dataForm,
+  },
+  data: () => ({
+    schcoolList: [],
+    nationList: [],
+    termList: [],
+    batchList: [],
+    classList: [],
+    info: {},
+    fields: [
+      { label: '姓名', required: true, model: 'name' },
+      { label: '性别', required: true, model: 'gender', type: 'radio' },
+      { label: '民族', required: true, model: 'nation', type: 'select' },
+      { label: '身份证号', required: true, model: 'id_number', options: { maxlength: 18 } },
+      { label: '学校', required: true, model: 'school_name', type: 'select' },
+      { label: '院系', required: true, model: 'faculty' },
+      { label: '专业', required: true, model: 'major' },
+      { label: '入学年份', required: true, model: 'entry_year', type: 'year' },
+      { label: '毕业年份', required: true, model: 'finish_year', type: 'year' },
+      { label: '在校曾担任何种职务', model: 'school_job' },
+      { label: '手机号', required: true, model: 'phone', options: { maxlength: 11, minlength: 11 } },
+      { label: 'QQ号', required: true, model: 'qq' },
+      { label: '邮箱', required: true, model: 'email' },
+      { label: '家庭所在地', required: true, model: 'family_place' },
+      { label: '家庭是否困难', required: true, model: 'family_is_hard', type: 'radio' },
+      { label: '是否获得过助学金', required: true, model: 'have_grant', type: 'radio' },
+      { label: '职务', model: 'job' },
+      { label: '期', model: 'termid', type: 'select', filterReturn: true },
+      { label: '批次', model: 'batchid', type: 'select', filterReturn: true },
+      { label: '班级', model: 'classid', type: 'select', filterReturn: true },
+      { label: '是否优秀', model: 'is_fine', type: 'radio' },
+    ],
+    rules: {
+      name: [{ required: true, message: '请输入姓名' }],
+      gender: [{ required: true, message: '请选择性别' }],
+      // nation: [{ required: true, message: '请选择民族' }],
+      id_number: [
+        { required: true, message: '请输入身份证号' },
+        { min: 18, max: 18, message: '请输入18位身份证号码', trigger: 'blur' },
+      ],
+      // school_name: [{ required: true, message: '请选择学校' }],
+      // yard: [{ required: true, message: '请选择院系' }],
+      // major: [{ required: true, message: '请选择专业' }],
+      entry_year: [{ required: true, message: '请选择入学年份' }],
+      finish_year: [{ required: true, message: '请选择毕业年份' }],
+      phone: [
+        { required: true, message: '请输入手机号' },
+        { min: 11, max: 11, message: '请输入11位手机号码', trigger: 'blur' },
+      ],
+      qq: [{ required: true, message: '请输入QQ号' }],
+      email: [{ required: true, message: '请输入邮箱' }],
+      family_place: [{ required: true, message: '请输入家庭所在地' }],
+      family_is_hard: [{ required: true, message: '请选择家庭是否困难' }],
+      have_grant: [{ required: true, message: '请选择是否获得过助学金' }],
+      // term: [{ required: true, message: '请输入期号' }],
+      // batch: [{ required: true, message: '请输入批次' }],
+      // class: [{ required: true, message: '请输入班级' }],
+      is_fine: [{ required: true, message: '请选择是否优秀' }],
+    },
+  }),
+  created() {
+    this.otherList();
+    this.schoolname();
+    this.termSearch();
+  },
+  computed: {
+    ...mapState(['user', 'defaultOption']),
+    id() {
+      return this.$route.query.id;
+    },
+    isNew() {
+      return this.$route.query.id ? false : true;
+    },
+    mainTitle() {
+      let meta = this.$route.meta;
+      let main = meta.title || '';
+      let sub = meta.sub || '';
+      return `${main}${sub}`;
+    },
+    keyWord() {
+      let meta = this.$route.meta;
+      let main = meta.title || '';
+      return main;
+    },
+  },
+  watch: {
+    isNew: {
+      immediate: true,
+      handler(val) {
+        if (val) this.loading = false;
+        else this.search();
+      },
+    },
+  },
+  methods: {
+    ...mapActions(['fetch', 'create', 'update']),
+    ...mapNation({ nation: 'query' }),
+    ...mapschool({ zschool: 'query' }),
+    ...trainplan({ trainplanQuery: 'query' }),
+    ...classes({ classesQuery: 'query' }),
+    async otherList() {
+      const res = await this.nation();
+      if (this.$checkRes(res)) this.$set(this, `nationList`, res.data);
+    },
+    async schoolname() {
+      const res = await this.zschool();
+      if (this.$checkRes(res)) this.$set(this, `schcoolList`, res.data);
+    },
+    // 期
+    async termSearch() {
+      let planid = _.get(this.defaultOption, 'planid');
+      let planyearid = _.get(this.defaultOption, 'planyearid');
+      const res = await this.trainplanQuery({ planyearid: planyearid });
+      var arr = res.data.filter(item => item.id === planid);
+      if (this.$checkRes(arr)) {
+        this.$set(this, `termList`, arr[0].termnum);
+        let { termid, batchid } = this.info;
+        if (termid) this.termChange({ data: termid, model: 'termid' });
+        if (batchid) this.termChange({ data: batchid, model: 'batchid' });
+      }
+    },
+    async search() {
+      const res = await this.fetch(this.id);
+      if (this.$checkRes(res)) {
+        this.$set(this, `info`, res.data);
+        let { batchid, termid } = res.data;
+        if (termid) this.termChange({ data: termid, model: 'termid' });
+        if (batchid) this.termChange({ data: batchid, model: 'batchid' });
+      }
+      this.loading = false;
+    },
+    async handleSave({ isNew, data }) {
+      let planid = _.get(this.defaultOption, 'planid');
+      let planyearid = _.get(this.defaultOption, 'planyearid');
+      let res;
+      let msg;
+      let sch = this.schcoolList.find(f => f.name == data.school_name);
+      console.log(sch);
+      if (sch) data.schid = sch.code;
+      console.log(data);
+      if (isNew) {
+        // data.openid = new Date().getTime();
+        // data.nation = `汉族`;
+        // data.yard = `测试学院`;
+        // data.major = `测试专业`;
+        // data.school_name = `测试学校`;
+        data.planid = planid;
+        data.planyearid = planyearid;
+        res = await this.create(data);
+        msg = `${this.keyWord}添加成功`;
+      } else {
+        res = await this.update(data);
+        msg = `${this.keyWord}修改成功`;
+      }
+      if (this.$checkRes(res, msg)) this.$router.push({ path: '/student/index' });
+    },
+    termChange({ data, model }) {
+      if (model == 'termid') {
+        let res = this.termList.filter(fil => fil._id === data);
+        if (res.length > 0) {
+          this.$set(this, `batchList`, res[0].batchnum);
+          this.$set(this.info, `termname`, res[0].term);
+        }
+      } else if (model == 'batchid') {
+        let res = this.batchList.filter(fil => fil._id === data);
+        if (res.length > 0) {
+          this.$set(this.info, `batchname`, res[0].batch);
+          this.searchClass(data);
+        }
+      } else if (model == 'classid') {
+        let res = this.classList.filter(fil => fil._id === data);
+        if (res.length > 0) {
+          this.$set(this.info, `classname`, res[0].name);
+        }
+      }
+    },
+    // 查询班级
+    async searchClass(id) {
+      const res = await this.classesQuery({ batchid: id });
+      if (this.$checkRes(res)) this.$set(this, `classList`, res.data);
+    },
+  },
+};
+</script>
+
+<style lang="less" scoped></style>