default-select.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <div id="default-select">
  3. <el-row type="flex" align="middle" justify="start" class="user-menu" v-loading="loading">
  4. <el-col :span="15" v-if="options">
  5. 当前默认:
  6. <span>
  7. <el-tooltip :disabled="this.user.type != 0" content="点击更改默认批次" effect="dark" placement="bottom">
  8. <el-select
  9. v-model="options.planyearid"
  10. :disabled="this.user.type != 0"
  11. placeholder="未设置培训批次"
  12. size="mini"
  13. @change="data => changeList('plan', data)"
  14. >
  15. <el-option v-for="(i, index) in planYearList" :key="index" :label="i.title" :value="i._id"></el-option>
  16. </el-select>
  17. </el-tooltip>
  18. </span>
  19. <span>
  20. <el-tooltip :disabled="this.user.type != 0" content="点击更改默认年度计划" effect="dark" placement="bottom">
  21. <el-select v-model="options.planid" :disabled="this.user.type != 0" placeholder="未设置年度计划" size="mini" @change="getTermList">
  22. <el-option v-for="(i, index) in planList" :key="index" :label="i.title" :value="i._id"></el-option>
  23. </el-select>
  24. </el-tooltip>
  25. </span>
  26. <span>
  27. <el-tooltip content="点击更改默认期" effect="dark" placement="bottom">
  28. <el-select v-model="options.termid" placeholder="未设置默认期" size="mini" @change="toCheckUserType()">
  29. <el-option v-for="(i, index) in termList" :key="index" :label="`第${i.term}期`" :value="i._id"></el-option>
  30. </el-select>
  31. </el-tooltip>
  32. </span>
  33. <span v-if="user.type == 1">
  34. <el-tooltip content="选择要查看的班级" effect="dark" placement="bottom">
  35. <el-select v-model="options.classid" placeholder="选择要查看的班级" size="mini" @change="setVuexOpt()">
  36. <el-option v-for="(i, index) in classList" :key="index" :label="i.name" :value="i._id"></el-option>
  37. </el-select>
  38. </el-tooltip>
  39. </span>
  40. <span>
  41. <el-button type="text" size="mini" @click="settingSave" v-if="this.user.type == 0">保存默认值</el-button>
  42. </span>
  43. </el-col>
  44. </el-row>
  45. </div>
  46. </template>
  47. <script>
  48. import _ from 'lodash';
  49. import { mapState, mapMutations, createNamespacedHelpers } from 'vuex';
  50. const { mapActions: trainBatch } = createNamespacedHelpers('trainBatch');
  51. const { mapActions: trainplan } = createNamespacedHelpers('trainplan');
  52. const { mapActions: setting } = createNamespacedHelpers('setting');
  53. const { mapActions: classes } = createNamespacedHelpers('classes');
  54. export default {
  55. name: 'default-select',
  56. props: {},
  57. components: {},
  58. data: function() {
  59. return {
  60. loading: true,
  61. options: undefined,
  62. planYearList: [],
  63. planList: [],
  64. termList: [],
  65. classList: [],
  66. };
  67. },
  68. async created() {
  69. // this.$set(this, `options`, _.cloneDeep(this.defaultOption));
  70. this.search({ type: 'planYear' });
  71. this.checkOption();
  72. if (this.user.type == 1) this.getClassOption();
  73. this.loading = false;
  74. },
  75. methods: {
  76. ...mapMutations(['deleteUser', 'changeOpt']),
  77. ...trainBatch({ getplanYear: 'query' }),
  78. ...trainplan({ getplan: 'query' }),
  79. ...setting({ sFetch: 'fetch', sUpdate: 'update' }),
  80. ...classes({ getClassList: 'query' }), //仅供班主任使用
  81. async search({ type, ...info }) {
  82. let res = await _.get(this, `get${type}`)({ ...info });
  83. if (this.$checkRes(res)) {
  84. this.$set(this, `${type}List`, res.data);
  85. if (type == 'plan') {
  86. let planid = _.get(this.options, 'planid');
  87. this.getTermList(planid);
  88. } else if (type == 'planYear') {
  89. // this.checkOption();
  90. }
  91. }
  92. },
  93. checkOption() {
  94. if (_.get(this.options, 'planid')) {
  95. this.search({ type: 'plan', planyearid: _.get(this.options, 'planyearid') });
  96. }
  97. },
  98. async changeList(type, data) {
  99. let obj = { type };
  100. let res;
  101. this.toClear();
  102. this.setVuexOpt();
  103. if (type == 'plan') {
  104. obj[`planyearid`] = data;
  105. await this.search(obj);
  106. }
  107. },
  108. getTermList(planid) {
  109. let r = this.planList.find(f => f.id == planid);
  110. if (r) {
  111. let term = _.get(r, 'termnum', []);
  112. this.$set(this, `termList`, term);
  113. }
  114. this.setVuexOpt();
  115. },
  116. //为了处理班主任的班级列表,先复制,再看看是不是需要查询班级列表
  117. toCheckUserType() {
  118. this.setVuexOpt();
  119. this.options.classid = undefined;
  120. if (this.user.type == 1) this.getClassOption();
  121. },
  122. setVuexOpt() {
  123. this.changeOpt(this.options);
  124. },
  125. toClear() {
  126. let planid = _.get(this.options, 'planid');
  127. if (planid) {
  128. let res = this.planList.find(f => f.id == planid);
  129. if (!res) this.$set(this.options, 'planid', undefined);
  130. }
  131. let termid = _.get(this.options, 'termid');
  132. if (termid) {
  133. let res = this.planList.find(f => f.id == planid);
  134. if (!res) this.$set(this.options, 'termid', undefined);
  135. }
  136. },
  137. async settingSave() {
  138. let res = await this.sUpdate(this.options);
  139. this.$checkRes(res, '设置成功', res.errmsg);
  140. },
  141. //班主任使用,默认班级
  142. async getClassOption() {
  143. let termid = _.get(this.defaultOption, 'termid');
  144. if (!termid) return;
  145. let res = await this.getClassList({ termid: this.defaultOption.termid, headteacherid: this.user.userid });
  146. if (this.$checkRes(res)) this.$set(this, `classList`, res.data);
  147. },
  148. },
  149. watch: {
  150. defaultOption: {
  151. handler(val) {
  152. if (val) {
  153. let opt = _.get(this, `options`);
  154. if (!opt) this.$set(this, `options`, _.cloneDeep(val));
  155. }
  156. },
  157. immediate: true,
  158. deep: true,
  159. },
  160. },
  161. computed: {
  162. ...mapState(['user', 'defaultOption']),
  163. pageTitle() {
  164. return `${this.$route.meta.title}`;
  165. },
  166. },
  167. metaInfo() {
  168. return { title: this.$route.meta.title };
  169. },
  170. };
  171. </script>
  172. <style lang="less" scoped>
  173. .user-menu {
  174. height: 4rem;
  175. .el-col {
  176. margin-left: 10px;
  177. span {
  178. margin-left: 10px;
  179. }
  180. }
  181. }
  182. </style>