index.vue 6.3 KB

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