experience.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <div id="experience">
  3. <list-frame title="培训心得" @query="search" :total="total" :needFilter="false" :needAdd="false" :needPag="true">
  4. <el-form size="small" :inline="true">
  5. <el-form-item label="班级">
  6. <el-select v-model="searchInfo.classid" placeholder="请选择班级">
  7. <el-option v-for="(c, index) in classList" :key="index" :label="`${c.name.includes('班') ? c.name : `${c.name}班`}`" :value="c._id"></el-option>
  8. </el-select>
  9. </el-form-item>
  10. </el-form>
  11. <export-range @getStudent="toGetStudent" :studentList="studentList" @toExport="toExport"></export-range>
  12. <data-table :fields="fields" :data="list" :opera="opera" @view="toView" @delete="toDelete"></data-table>
  13. </list-frame>
  14. <el-dialog :visible.sync="dialog" title="培训心得" @close="toClose" width="30%">
  15. <data-form :data="form" :fields="formFields" :rules="{}" :needSave="false">
  16. <template #custom="{item, form}">
  17. <template v-if="item.model === 'content'">
  18. <el-input type="textarea" v-model="form[item.model]" :readonly="true" :autosize="{ minRows: 4, maxRows: 20 }"></el-input>
  19. </template>
  20. </template>
  21. </data-form>
  22. </el-dialog>
  23. </div>
  24. </template>
  25. <script>
  26. import _ from 'lodash';
  27. import exportRange from '@/components/export-range.vue';
  28. import listFrame from '@frame/layout/admin/list-frame';
  29. import dataForm from '@frame/components/form';
  30. import dataTable from '@frame/components/data-table';
  31. import { mapState, createNamespacedHelpers } from 'vuex';
  32. const { mapActions: experience } = createNamespacedHelpers('experience');
  33. const { mapActions: classes } = createNamespacedHelpers('classes');
  34. const { mapActions: trainplan } = createNamespacedHelpers('trainplan');
  35. const { mapActions: student } = createNamespacedHelpers('student');
  36. export default {
  37. metaInfo: { title: '培训心得' },
  38. name: 'experience',
  39. props: {},
  40. components: {
  41. listFrame,
  42. dataTable,
  43. dataForm,
  44. exportRange,
  45. },
  46. data: () => ({
  47. opera: [
  48. {
  49. label: '查看',
  50. icon: 'el-icon-view',
  51. method: 'view',
  52. },
  53. {
  54. label: '删除',
  55. icon: 'el-icon-delete',
  56. method: 'delete',
  57. },
  58. ],
  59. fields: [
  60. { label: '姓名', prop: 'stuname' },
  61. { label: '职务', prop: 'stujob' },
  62. ],
  63. list: [],
  64. classList: [],
  65. studentList: [],
  66. searchInfo: {},
  67. total: 0,
  68. dialog: false,
  69. form: {},
  70. formFields: [
  71. { label: '姓名', model: 'stuname', type: 'text' },
  72. { label: '职务', model: 'stujob', type: 'text' },
  73. { label: '培训心得标题', model: 'title', type: 'text' },
  74. { label: '培训心得', model: 'content', custom: true },
  75. ],
  76. }),
  77. async created() {
  78. await this.getOtherList();
  79. },
  80. computed: { ...mapState(['user', 'defaultOption']) },
  81. methods: {
  82. ...classes({ getClass: 'query' }),
  83. ...student({ getStudent: 'query' }),
  84. ...experience(['query', 'export']),
  85. async search({ skip = 0, limit = 10, ...info } = {}) {
  86. this.$set(this, `total`, 0);
  87. const res = await this.query({ ...this.searchInfo, skip, limit });
  88. if (this.$checkRes(res)) {
  89. this.$set(this, `list`, res.data);
  90. this.$set(this, `total`, res.total);
  91. }
  92. },
  93. async getOtherList() {
  94. const { termid } = this.defaultOption;
  95. if (!termid) return;
  96. const res = await this.getClass({ termid });
  97. if (this.$checkRes(res)) {
  98. let duplicate = _.cloneDeep(res.data);
  99. duplicate = duplicate.map(i => {
  100. if (parseInt(i.name)) {
  101. i.order = parseInt(i.name);
  102. } else {
  103. // i.order = i.name;
  104. }
  105. return i;
  106. });
  107. duplicate = _.orderBy(duplicate, ['order'], ['asc']);
  108. this.$set(this, `classList`, duplicate);
  109. }
  110. },
  111. async toGetStudent(classid) {
  112. const bzres = await this.getStudent({ classid, job: '班长' });
  113. const xwres = await this.getStudent({ classid, job: '学委' });
  114. let arr = [];
  115. if (this.$checkRes(bzres)) arr = [...arr, ...bzres.data];
  116. if (this.$checkRes(xwres)) arr = [...arr, ...xwres.data];
  117. this.$set(this, `studentList`, arr);
  118. },
  119. async toExport(data) {
  120. const res = await this.export(data);
  121. if (this.$checkRes(res, '导出成功', res.errmsg || '导出失败')) {
  122. window.open(res.data);
  123. }
  124. },
  125. // 查看
  126. toView({ data }) {
  127. this.$set(this, `form`, data);
  128. this.dialog = true;
  129. },
  130. // 删除
  131. toDelete({ data }) {
  132. console.log(data);
  133. },
  134. // 保存
  135. turnSave({ data }) {},
  136. // 关闭
  137. toClose() {
  138. this.form = {};
  139. this.dialog = false;
  140. },
  141. },
  142. watch: {
  143. defaultOption: {
  144. deep: true,
  145. handler(val, oval) {
  146. this.getOtherList();
  147. },
  148. },
  149. searchInfo: {
  150. deep: true,
  151. handler(val) {
  152. if (val) {
  153. const keys = Object.keys(val);
  154. if (keys.length > 0) this.search();
  155. }
  156. },
  157. },
  158. },
  159. };
  160. </script>
  161. <style lang="less" scoped></style>