export-range.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <div id="experience-export">
  3. <!-- <el-button type="primary" size="small" @click="dialog = true">导出</el-button> -->
  4. <!-- <el-dialog title="请选择要导出的范围" width="30%" :visible.sync="dialog" center @close="toClose"> -->
  5. <el-form size="small">
  6. <el-form-item label="年度计划" v-if="useplan">
  7. <el-select clearable v-model="form.planid" @change="toGetTerm">
  8. <el-option v-for="(i, index) in planList" :key="index" :label="i.title" :value="i._id"></el-option>
  9. </el-select>
  10. </el-form-item>
  11. <el-form-item label="期(可选)" v-if="useterm">
  12. <el-select clearable v-model="form.termid" :multiple="mult" @change="selectTerm">
  13. <el-option v-for="(i, index) in termList" :key="index" :label="`第${i.term}期`" :value="i._id"></el-option>
  14. </el-select>
  15. </el-form-item>
  16. <el-form-item label="批(可选)" v-if="usebatch">
  17. <el-select clearable v-model="form.batchid">
  18. <el-option v-for="(i, index) in batchList" :key="index" :label="`第${i.batch}批`" :value="i._id"></el-option>
  19. </el-select>
  20. </el-form-item>
  21. <el-form-item label="班(可选)" v-if="useclass">
  22. <el-select clearable v-model="form.classid" @change="selectClass">
  23. <el-option v-for="(c, index) in classList" :key="index" :label="`${c.name.includes('班') ? c.name : `${c.name}班`}`" :value="c._id"></el-option>
  24. </el-select>
  25. </el-form-item>
  26. <el-form-item label="人(可选)" v-if="usestudent">
  27. <el-select clearable v-model="form.studentid">
  28. <el-option v-for="(i, index) in studentList" :key="index" :label="`${i.name}(${i.job})`" :value="i._id"></el-option>
  29. </el-select>
  30. </el-form-item>
  31. </el-form>
  32. <slot></slot>
  33. <el-row type="flex" justify="space-around" class="btn_bar">
  34. <el-col :span="2">
  35. <el-button type="primary" size="small" @click="toExport">导出</el-button>
  36. </el-col>
  37. </el-row>
  38. <!-- </el-dialog> -->
  39. </div>
  40. </template>
  41. <script>
  42. const _ = require('lodash');
  43. import { mapState, createNamespacedHelpers } from 'vuex';
  44. const { mapActions: experience } = createNamespacedHelpers('experience');
  45. const { mapActions: classes } = createNamespacedHelpers('classes');
  46. const { mapActions: trainplan } = createNamespacedHelpers('trainplan');
  47. export default {
  48. name: 'experience-export',
  49. props: {
  50. studentList: { type: Array, default: () => [] },
  51. useplan: { type: Boolean, default: true },
  52. useterm: { type: Boolean, default: true },
  53. usebatch: { type: Boolean, default: true },
  54. useclass: { type: Boolean, default: true },
  55. usestudent: { type: Boolean, default: true },
  56. mult: { type: Boolean, default: true },
  57. },
  58. components: {},
  59. data: function() {
  60. return {
  61. form: {},
  62. planList: [],
  63. termList: [],
  64. batchList: [],
  65. classList: [],
  66. };
  67. },
  68. async created() {
  69. await this.toGetPlan();
  70. },
  71. methods: {
  72. ...experience(['export']),
  73. ...trainplan({ getPlan: 'query' }),
  74. ...classes({ getClass: 'query' }),
  75. // 查询年度计划
  76. async toGetPlan() {
  77. const res = await this.getPlan();
  78. if (this.$checkRes(res)) this.$set(this, `planList`, res.data);
  79. },
  80. // 找到期列表
  81. async toGetTerm(planid) {
  82. const res = await this.planList.find(f => f._id === planid);
  83. if (!res) return;
  84. const { termnum } = res;
  85. this.$set(this, `termList`, termnum);
  86. },
  87. // 找到批次列表,查询班级列表
  88. async selectTerm(termids = []) {
  89. let termid;
  90. if (this.mult) {
  91. if (termids.length != 1) {
  92. this.$set(this.form, `classid`, undefined);
  93. this.$set(this.form, `batchid`, undefined);
  94. return;
  95. }
  96. termid = _.head(termids);
  97. } else termid = termids;
  98. const r = this.termList.find(f => f._id === termid);
  99. if (!r) return;
  100. const { batchnum } = r;
  101. this.$set(this, `batchList`, batchnum);
  102. const stures = await this.getClass({ termid });
  103. if (this.$checkRes(stures)) {
  104. let duplicate = _.cloneDeep(stures.data);
  105. duplicate = duplicate.map(i => {
  106. if (parseInt(i.name)) {
  107. i.order = parseInt(i.name);
  108. } else {
  109. // i.order = i.name;
  110. }
  111. return i;
  112. });
  113. duplicate = _.orderBy(duplicate, ['order'], ['asc']);
  114. this.$set(this, `classList`, duplicate);
  115. }
  116. },
  117. async selectClass(classid) {
  118. this.$emit('getStudent', classid);
  119. },
  120. //导出
  121. async toExport() {
  122. let dup = _.cloneDeep(this.form);
  123. const keys = Object.keys(dup);
  124. let obj = {};
  125. for (const key of keys) {
  126. if (dup[key] && dup[key] !== '') obj[key] = dup[key];
  127. }
  128. this.$emit('toExport', obj);
  129. this.toClose();
  130. },
  131. toClose() {
  132. this.$set(this, `form`, {});
  133. this.$emit('close');
  134. },
  135. },
  136. computed: {
  137. ...mapState(['user']),
  138. pageTitle() {
  139. return `${this.$route.meta.title}`;
  140. },
  141. },
  142. metaInfo() {
  143. return { title: this.$route.meta.title };
  144. },
  145. };
  146. </script>
  147. <style lang="less" scoped></style>