default-select.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 || user.type == 3">
  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. const { mapActions: lesson } = createNamespacedHelpers('lesson');
  55. export default {
  56. name: 'default-select',
  57. props: {},
  58. components: {},
  59. data: function() {
  60. return {
  61. loading: true,
  62. options: undefined,
  63. planYearList: [],
  64. planList: [],
  65. termList: [],
  66. classList: [],
  67. };
  68. },
  69. async created() {
  70. // this.$set(this, `options`, _.cloneDeep(this.defaultOption));
  71. this.search({ type: 'planYear' });
  72. // this.checkOption();
  73. // if (this.user.type == 1 || this.user.type == 3) this.getClassOption();
  74. // this.loading = false;
  75. },
  76. methods: {
  77. ...mapMutations(['deleteUser', 'changeOpt']),
  78. ...trainBatch({ getplanYear: 'query' }),
  79. ...trainplan({ getplan: 'query' }),
  80. ...setting({ sFetch: 'fetch', sUpdate: 'update' }),
  81. ...classes({ getClassList: 'query' }), //仅供班主任使用
  82. ...lesson({ teaclass: 'teaclass' }), //仅供老师使用
  83. checkOption() {
  84. if (_.get(this.options, 'planid')) {
  85. this.search({ type: 'plan', planyearid: _.get(this.options, 'planyearid') });
  86. }
  87. if (this.user.type == 1 || this.user.type == 3) this.getClassOption();
  88. this.loading = false;
  89. },
  90. async search({ type, ...info }) {
  91. let res = await _.get(this, `get${type}`)({ ...info });
  92. if (this.$checkRes(res)) {
  93. this.$set(this, `${type}List`, res.data);
  94. if (type == 'plan') {
  95. let planid = _.get(this.options, 'planid');
  96. this.getTermList(planid);
  97. }
  98. }
  99. },
  100. async changeList(type, data) {
  101. let obj = { type };
  102. let res;
  103. this.toClear();
  104. this.setVuexOpt();
  105. if (type == 'plan') {
  106. obj[`planyearid`] = data;
  107. await this.search(obj);
  108. }
  109. },
  110. getTermList(planid) {
  111. let r = this.planList.find(f => f.id == planid);
  112. if (r) {
  113. let term = _.get(r, 'termnum', []);
  114. this.$set(this, `termList`, term);
  115. }
  116. this.setVuexOpt();
  117. },
  118. //为了处理班主任的班级列表,先复制,再看看是不是需要查询班级列表
  119. toCheckUserType() {
  120. this.setVuexOpt();
  121. this.options.classid = undefined;
  122. if (this.user.type == 1 || this.user.type == 3) this.getClassOption();
  123. },
  124. setVuexOpt() {
  125. this.changeOpt(this.options);
  126. },
  127. toClear() {
  128. let planid = _.get(this.options, 'planid');
  129. if (planid) {
  130. let res = this.planList.find(f => f.id == planid);
  131. if (!res) this.$set(this.options, 'planid', undefined);
  132. }
  133. let termid = _.get(this.options, 'termid');
  134. if (termid) {
  135. let res = this.planList.find(f => f.id == planid);
  136. if (!res) this.$set(this.options, 'termid', undefined);
  137. }
  138. },
  139. async settingSave() {
  140. let res = await this.sUpdate(this.options);
  141. this.$checkRes(res, '设置成功', res.errmsg);
  142. },
  143. //班主任使用,默认班级
  144. async getClassOption() {
  145. let termid = _.get(this.defaultOption, 'termid');
  146. let planid = _.get(this.defaultOption, 'planid');
  147. if (!termid) return;
  148. let res;
  149. if (this.user.type == 1) {
  150. res = await this.getClassList({ termid: this.defaultOption.termid, headteacherid: this.user.userid });
  151. if (this.$checkRes(res)) this.$set(this, `classList`, res.data);
  152. }
  153. if (this.user.type == 3) {
  154. res = await this.teaclass({ planid: planid, teaid: this.user.userid });
  155. const elm = res.data.filter(item => item.termid == termid);
  156. this.$set(this, `classList`, elm);
  157. }
  158. },
  159. },
  160. watch: {
  161. defaultOption: {
  162. handler(val) {
  163. if (val) {
  164. let opt = _.get(this, `options`);
  165. if (!opt) this.$set(this, `options`, _.cloneDeep(val));
  166. }
  167. },
  168. immediate: true,
  169. deep: true,
  170. },
  171. options: {
  172. immediate: true,
  173. deep: true,
  174. handler(val, oval) {
  175. if (!_.isEqual(val, oval) && val) this.checkOption();
  176. },
  177. },
  178. },
  179. computed: {
  180. ...mapState(['user', 'defaultOption']),
  181. pageTitle() {
  182. return `${this.$route.meta.title}`;
  183. },
  184. },
  185. metaInfo() {
  186. return { title: this.$route.meta.title };
  187. },
  188. };
  189. </script>
  190. <style lang="less" scoped>
  191. .user-menu {
  192. height: 4rem;
  193. .el-col {
  194. margin-left: 10px;
  195. span {
  196. margin-left: 10px;
  197. }
  198. }
  199. }
  200. </style>