name-list.vue 6.5 KB

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