index.vue 6.7 KB

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