export-range.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 @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. },
  57. components: {},
  58. data: function() {
  59. return {
  60. form: {},
  61. planList: [],
  62. termList: [],
  63. batchList: [],
  64. classList: [],
  65. };
  66. },
  67. async created() {
  68. await this.toGetPlan();
  69. },
  70. methods: {
  71. ...experience(['export']),
  72. ...trainplan({ getPlan: 'query' }),
  73. ...classes({ getClass: 'query' }),
  74. // 查询年度计划
  75. async toGetPlan() {
  76. const res = await this.getPlan();
  77. if (this.$checkRes(res)) this.$set(this, `planList`, res.data);
  78. },
  79. // 找到期列表
  80. async toGetTerm(planid) {
  81. const res = await this.planList.find(f => f._id === planid);
  82. if (!res) return;
  83. const { termnum } = res;
  84. this.$set(this, `termList`, termnum);
  85. },
  86. // 找到批次列表,查询班级列表
  87. async selectTerm(termids = []) {
  88. if (termids.length != 1) {
  89. this.$set(this.form, `classid`, undefined);
  90. this.$set(this.form, `batchid`, undefined);
  91. return;
  92. }
  93. const termid = _.head(termids);
  94. const r = this.termList.find(f => f._id === termid);
  95. if (!r) return;
  96. const { batchnum } = r;
  97. this.$set(this, `batchList`, batchnum);
  98. const stures = await this.getClass({ termid });
  99. if (this.$checkRes(stures)) {
  100. let duplicate = _.cloneDeep(stures.data);
  101. duplicate = duplicate.map(i => {
  102. if (parseInt(i.name)) {
  103. i.order = parseInt(i.name);
  104. } else {
  105. // i.order = i.name;
  106. }
  107. return i;
  108. });
  109. duplicate = _.orderBy(duplicate, ['order'], ['asc']);
  110. this.$set(this, `classList`, duplicate);
  111. }
  112. },
  113. async selectClass(classid) {
  114. this.$emit('getStudent', classid);
  115. },
  116. //导出
  117. async toExport() {
  118. let dup = _.cloneDeep(this.form);
  119. const keys = Object.keys(dup);
  120. let obj = {};
  121. for (const key of keys) {
  122. if (dup[key] && dup[key] !== '') obj[key] = dup[key];
  123. }
  124. this.$emit('toExport', obj);
  125. this.toClose();
  126. },
  127. toClose() {
  128. this.$set(this, `form`, {});
  129. this.$emit('close');
  130. },
  131. },
  132. computed: {
  133. ...mapState(['user']),
  134. pageTitle() {
  135. return `${this.$route.meta.title}`;
  136. },
  137. },
  138. metaInfo() {
  139. return { title: this.$route.meta.title };
  140. },
  141. };
  142. </script>
  143. <style lang="less" scoped></style>