index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <div id="index">
  3. <list-frame title="学生管理" @query="search" :total="total" :needFilter="false" @add="$router.push({ path: '/student/detail' })">
  4. <el-form :inline="true" size="mini">
  5. <el-form-item label="期">
  6. <el-select v-model="form.termid" placeholder="请选择期数" @change="getBatch">
  7. <el-option v-for="(i, index) in termList" :key="index" :label="`第${i.term}期`" :value="i._id"></el-option>
  8. </el-select>
  9. </el-form-item>
  10. <el-form-item label="批次">
  11. <el-select v-model="form.batchid" placeholder="请先选择期数" @change="getClasses">
  12. <el-option v-for="(i, index) in batchList" :key="index" :label="i.name" :value="i._id"></el-option>
  13. </el-select>
  14. </el-form-item>
  15. <el-form-item label="班级">
  16. <el-select v-model="form.classid" placeholder="请先选择批次">
  17. <el-option v-for="(i, index) in classList" :key="index" :label="i.name" :value="i._id"></el-option>
  18. </el-select>
  19. </el-form-item>
  20. <el-form-item>
  21. <el-button type="primary" @click="search">查询</el-button>
  22. </el-form-item>
  23. </el-form>
  24. <data-table :fields="fields" :data="list" :opera="opera" @turnClass="toTurnClass" @edit="toEdit" @delete="toDelete"></data-table>
  25. </list-frame>
  26. <el-dialog :visible.sync="dialog" title="转班" @close="toClose" width="30%">
  27. <data-form :data="studInfo" :fields="turnFields" :rules="{}" @save="turnSave">
  28. <template #options="{item,form}">
  29. <template v-if="item.model == 'classid'">
  30. <el-option v-for="(i, index) in selectClassList" :key="index" :label="`第${i.batch}批-${i.name}`" :value="i._id"></el-option>
  31. </template>
  32. </template>
  33. </data-form>
  34. </el-dialog>
  35. </div>
  36. </template>
  37. <script>
  38. import listFrame from '@frame/layout/admin/list-frame';
  39. import dataForm from '@frame/components/form';
  40. import dataTable from '@frame/components/data-table';
  41. import { mapState, createNamespacedHelpers } from 'vuex';
  42. const { mapActions } = createNamespacedHelpers('student');
  43. const { mapActions: classes } = createNamespacedHelpers('classes');
  44. const { mapActions: trainplan } = createNamespacedHelpers('trainplan');
  45. export default {
  46. metaInfo: { title: '学生管理' },
  47. name: 'index',
  48. props: {},
  49. components: {
  50. listFrame,
  51. dataTable,
  52. dataForm,
  53. },
  54. data: () => ({
  55. dialog: false,
  56. opera: [
  57. {
  58. label: '编辑',
  59. icon: 'el-icon-edit',
  60. method: 'edit',
  61. },
  62. {
  63. label: '转班',
  64. icon: 'el-icon-refresh',
  65. method: 'turnClass',
  66. },
  67. {
  68. label: '删除',
  69. icon: 'el-icon-delete',
  70. method: 'delete',
  71. confirm: true,
  72. },
  73. ],
  74. fields: [
  75. { label: '姓名', prop: 'name' },
  76. { label: '性别', prop: 'gender' },
  77. { label: '民族', prop: 'nation' },
  78. { label: '身份证号', prop: 'id_number' },
  79. { label: '期', prop: 'termname' },
  80. { label: '批次', prop: 'batchname' },
  81. { label: '班级', prop: 'classname' },
  82. { label: '学校', prop: 'school_name' },
  83. { label: '院系', prop: 'faculty' },
  84. { label: '专业', prop: 'major' },
  85. { label: '手机号', prop: 'phone' },
  86. { label: '邮箱', prop: 'email' },
  87. ],
  88. turnFields: [
  89. { label: '姓名', model: 'name', type: 'text' },
  90. { label: '学校', model: 'school_name', type: 'text' },
  91. { label: '班级', model: 'classid', type: 'select' },
  92. ],
  93. form: {},
  94. studInfo: {},
  95. list: [],
  96. classList: [],
  97. batchList: [],
  98. termList: [],
  99. total: 0,
  100. selectClassList: [],
  101. }),
  102. created() {
  103. this.getPlan();
  104. },
  105. computed: { ...mapState(['user', 'defaultOption']) },
  106. methods: {
  107. ...trainplan({ planfetch: 'fetch' }),
  108. ...mapActions(['query', 'delete', 'update']),
  109. ...classes({ classesquery: 'query' }),
  110. async search({ skip = 0, limit = 10, ...info } = {}) {
  111. const res = await this.query({ skip, limit, termid: this.form.termid, classid: this.form.classid });
  112. if (this.$checkRes(res)) {
  113. this.$set(this, `list`, res.data);
  114. this.$set(this, `total`, res.total);
  115. }
  116. },
  117. toEdit({ data }) {
  118. this.$router.push({ path: '/student/detail', query: { id: data.id } });
  119. },
  120. async toDelete({ data }) {
  121. const res = await this.delete(data.id);
  122. this.$checkRes(res, '删除成功', '删除失败');
  123. this.search();
  124. },
  125. async getPlan() {
  126. const res = await this.planfetch(this.defaultOption.planid);
  127. let terms = res.data.termnum;
  128. this.$set(this, `termList`, terms);
  129. if (this.defaultOption.termid) {
  130. this.form.termid = this.defaultOption.termid;
  131. this.getBatch(this.form.termid);
  132. }
  133. },
  134. getBatch(termid) {
  135. let batchs = this.termList.filter(f => f._id === termid);
  136. if (batchs.length > 0) {
  137. let { batchnum } = batchs[0];
  138. this.$set(this, `batchList`, batchnum);
  139. }
  140. },
  141. async getClasses(batchid) {
  142. const res = await this.classesquery({ batchid });
  143. this.$set(this, `classList`, res.data);
  144. },
  145. async toTurnClass({ data }) {
  146. let { termid } = data;
  147. this.$set(this, `studInfo`, data);
  148. let res = await this.classesquery({ termid });
  149. if (this.$checkRes(res)) this.$set(this, `selectClassList`, res.data);
  150. this.dialog = true;
  151. },
  152. //转班保存
  153. async turnSave({ data }) {
  154. let msg = '转班';
  155. let res = await this.update(data);
  156. if (this.$checkRes(res, `${msg}成功`, res.errmsg || `${msg}失败`)) {
  157. this.search();
  158. this.toClose();
  159. }
  160. },
  161. toClose() {
  162. this.dialog = false;
  163. this.form = {};
  164. },
  165. },
  166. watch: {
  167. defaultOption: {
  168. handler(val) {
  169. this.form.termid = this.defaultOption.termid;
  170. this.getBatch(this.form.termid);
  171. },
  172. deep: true,
  173. },
  174. },
  175. };
  176. </script>
  177. <style lang="less" scoped></style>