export-range.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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" :multiple="mult">
  18. <el-option v-for="(i, index) in batchList" :key="index" :label="i.name" :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" :multiple="mult" @change="selectClass">
  23. <el-option v-for="(c, index) in classList" :key="index" :label="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. // 只要选了期,就重置后面的选项
  91. this.$set(this.form, `classid`, undefined);
  92. this.$set(this.form, `batchid`, undefined);
  93. // 多选单选分开处理
  94. if (this.mult) {
  95. if (termids.length >= 1) {
  96. // 再将选择的期下的批次提取出来,将名字改成带期数的.以便区分
  97. const batchList = [];
  98. const classList = [];
  99. for (const tid of termids) {
  100. // 找期下的批次
  101. const r = this.termList.find(f => f._id === tid);
  102. if (!r) continue;
  103. const { batchnum = [], term } = r;
  104. for (const i of batchnum) {
  105. // 处理批次选项
  106. i.name = `第${term}期-第${i.batch}批`;
  107. batchList.push(i);
  108. // 处理班级选项
  109. const cRes = await this.getClass({ termid: tid, batchid: i._id });
  110. if (this.$checkRes(cRes)) {
  111. const cl = cRes.data;
  112. for (const c of cl) {
  113. c.name = `第${c.term}期-第${c.batch}批-${c.name}班`;
  114. }
  115. classList.push(...cl);
  116. }
  117. }
  118. }
  119. // 批次列表
  120. this.$set(this, `batchList`, batchList);
  121. // 班级列表
  122. this.$set(this, `classList`, classList);
  123. }
  124. } else {
  125. termid = termids;
  126. // 正常找期下的批次,班级
  127. const r = this.termList.find(f => f._id === termid);
  128. if (!r) return;
  129. const { batchnum } = r;
  130. const nbn = batchnum.map(i => {
  131. i.name = `第${r.term}期-第${i.batch}批`;
  132. return i;
  133. });
  134. this.$set(this, `batchList`, nbn);
  135. const stures = await this.getClass({ termid });
  136. if (this.$checkRes(stures)) {
  137. const cl = stures.data;
  138. for (const c of cl) {
  139. c.name = `第${c.term}期-第${c.batch}批-${c.name}班`;
  140. }
  141. this.$set(this, `classList`, cl);
  142. }
  143. }
  144. },
  145. async selectClass(classid) {
  146. this.$emit('getStudent', classid);
  147. },
  148. //导出
  149. async toExport() {
  150. let dup = _.cloneDeep(this.form);
  151. const keys = Object.keys(dup);
  152. let obj = {};
  153. for (const key of keys) {
  154. if (dup[key] && dup[key] !== '') obj[key] = dup[key];
  155. }
  156. this.$emit('toExport', obj);
  157. this.toClose();
  158. },
  159. toClose() {
  160. this.$set(this, `form`, {});
  161. this.$emit('close');
  162. },
  163. },
  164. computed: {
  165. ...mapState(['user']),
  166. pageTitle() {
  167. return `${this.$route.meta.title}`;
  168. },
  169. },
  170. metaInfo() {
  171. return { title: this.$route.meta.title };
  172. },
  173. };
  174. </script>
  175. <style lang="less" scoped></style>