name-list.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <div id="name-list">
  3. <list-frame :title="mainTitle" @query="search" :total="total" :needFilter="false" :needAdd="false">
  4. <el-col :span="24" class="printingBtn">
  5. <!-- <el-button type="primary" size="mini" @click="toPrint()">打印名牌</el-button> -->
  6. <el-col :span="12">
  7. <el-input placeholder="请输入学生姓名" v-model="stuname" class="input-with-select">
  8. <el-button slot="append" icon="el-icon-search" @click="search()"></el-button>
  9. </el-input>
  10. </el-col>
  11. <el-col :span="12">
  12. <el-button type="primary" size="mini" @click="addstu()">添加学生</el-button>
  13. <el-button type="primary" size="mini" @click="toComputIsFine()" :disabled="this.defaultOption.classid ? false : true">设置优秀学员</el-button>
  14. </el-col>
  15. </el-col>
  16. <data-table :fields="fields" :data="list" :opera="opera" @edit="toEdit" @delete="toDelete" @post="toPost"> </data-table>
  17. </list-frame>
  18. <el-drawer title="任职" :visible.sync="drawer" direction="rtl" @close="toClose">
  19. <data-form :data="form" :fields="formFields" :rules="rules" :isNew="false">
  20. <template #radios="{item}">
  21. <template v-if="item.model === 'job'">
  22. <el-radio label="1">班长</el-radio>
  23. <el-radio label="0">学委</el-radio>
  24. </template>
  25. </template>
  26. <template #custom="{ item, form }">
  27. <template v-if="item.model === 'gender'">
  28. {{ form[item.model] }}
  29. </template>
  30. </template>
  31. </data-form>
  32. </el-drawer>
  33. </div>
  34. </template>
  35. <script>
  36. import _ from 'lodash';
  37. import listFrame from '@frame/layout/admin/list-frame';
  38. import dataTable from '@frame/components/data-table';
  39. import dataForm from '@frame/components/form';
  40. import { mapState, createNamespacedHelpers } from 'vuex';
  41. const { mapActions } = createNamespacedHelpers('student');
  42. const { mapActions: group } = createNamespacedHelpers('group');
  43. export default {
  44. metaInfo: { title: '班级名单' },
  45. name: 'name-list',
  46. props: {},
  47. components: {
  48. listFrame,
  49. dataTable,
  50. dataForm,
  51. },
  52. data: function() {
  53. var _this = this;
  54. return {
  55. opera: [
  56. {
  57. label: '编辑',
  58. icon: 'el-icon-edit',
  59. method: 'edit',
  60. },
  61. {
  62. label: '删除',
  63. icon: 'el-icon-delete',
  64. method: 'delete',
  65. confirm: true,
  66. display: i => {
  67. // return !_this.groupList.find(stu => {
  68. // return stu.stuid == i.id;
  69. // });
  70. return !_this.groupList.find(stu => stu.stuid == i.id);
  71. },
  72. },
  73. // {
  74. // label: '管理任职',
  75. // icon: 'el-icon-check',
  76. // method: 'post',
  77. // },
  78. ],
  79. fields: [
  80. { label: '姓名', prop: 'name', filter: 'input' },
  81. { label: '性别', prop: 'gender' },
  82. { label: '民族', prop: 'nation' },
  83. { label: '学校', prop: 'school_name' },
  84. { label: '院系', prop: 'faculty' },
  85. { label: '专业', prop: 'major' },
  86. { label: '职务', prop: 'job' },
  87. { label: '手机号', prop: 'phone' },
  88. { label: '是否优秀', prop: 'is_fine', format: i => (i === '0' ? '否' : i === '1' ? '是' : '无资格') },
  89. ],
  90. list: [],
  91. total: 0,
  92. form: {},
  93. drawer: false,
  94. formFields: [
  95. { label: '姓名', model: 'name', type: 'text' },
  96. { label: '性别', model: 'gender', custom: true },
  97. { label: '手机号', model: 'phone', type: 'text' },
  98. { label: '职务', required: true, model: 'job', type: 'radio' },
  99. ],
  100. rules: {},
  101. // 组
  102. groupList: [],
  103. // 查询
  104. // 学生姓名
  105. stuname: '',
  106. };
  107. },
  108. created() {
  109. this.seachGroup();
  110. },
  111. methods: {
  112. ...mapActions(['query', 'delete', 'computedIsFine']),
  113. ...group({ groupQuery: 'query' }),
  114. async seachGroup() {
  115. let classid = this.id;
  116. let res = await this.groupQuery({ classid });
  117. if (this.$checkRes(res)) {
  118. let arr = res.data.map(item => item.students);
  119. arr = _.flattenDeep(arr);
  120. console.log(arr);
  121. this.$set(this, `groupList`, arr);
  122. }
  123. },
  124. async search({ skip = 0, limit = 10, ...info } = {}) {
  125. if (this.id) {
  126. if (this.stuname) info.name = this.stuname;
  127. const res = await this.query({ skip, limit, ...info, classid: this.id });
  128. if (this.$checkRes(res)) {
  129. this.$set(this, `list`, res.data);
  130. this.$set(this, `total`, res.total);
  131. }
  132. }
  133. },
  134. // 添加
  135. addstu() {
  136. this.$router.push({ path: '/student/createStu' });
  137. },
  138. toEdit({ data }) {
  139. this.$router.push({ path: '/student/detail', query: { id: data.id } });
  140. },
  141. async toDelete({ data }) {
  142. const res = await this.delete(data.id);
  143. this.$checkRes(res, '删除成功', '删除失败');
  144. this.search();
  145. },
  146. toPost({ data }) {
  147. this.$set(this, `form`, JSON.parse(JSON.stringify(data)));
  148. this.drawer = true;
  149. },
  150. toClose() {
  151. this.drawer = false;
  152. this.form = {};
  153. },
  154. toreturn() {
  155. window.history.go(-1);
  156. },
  157. // 打印名牌
  158. toPrint() {
  159. this.$router.push({ path: '/classes/namCard', query: { id: this.id } });
  160. },
  161. // 计算优秀学员
  162. async toComputIsFine() {
  163. const res = await this.computedIsFine(this.defaultOption.classid);
  164. if (this.$checkRes(res, '优秀学员设置成功', res.errmsg || '优秀学员设置失败')) this.search();
  165. },
  166. },
  167. computed: {
  168. ...mapState(['user', 'defaultOption']),
  169. id() {
  170. return this.defaultOption.classid;
  171. },
  172. mainTitle() {
  173. let meta = this.$route.meta;
  174. let main = meta.title || '';
  175. let sub = meta.sub || '';
  176. let title = main + sub;
  177. return title;
  178. },
  179. },
  180. watch: {
  181. id: {
  182. handler(val) {
  183. if (val) this.search();
  184. else this.$set(this, `list`, []);
  185. },
  186. immediate: true,
  187. },
  188. },
  189. };
  190. </script>
  191. <style lang="less" scoped>
  192. .printingBtn {
  193. text-align: right;
  194. padding: 10px 0;
  195. }
  196. </style>