default-select.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. this.loading = false;
  88. },
  89. async search({ type, ...info }) {
  90. let res = await _.get(this, `get${type}`)({ ...info });
  91. if (this.$checkRes(res)) {
  92. this.$set(this, `${type}List`, res.data);
  93. if (type == 'plan') {
  94. let planid = _.get(this.options, 'planid');
  95. this.getTermList(planid);
  96. } else if (type == 'planYear') {
  97. // this.checkOption();
  98. }
  99. }
  100. },
  101. async changeList(type, data) {
  102. let obj = { type };
  103. let res;
  104. this.toClear();
  105. this.setVuexOpt();
  106. if (type == 'plan') {
  107. obj[`planyearid`] = data;
  108. await this.search(obj);
  109. }
  110. },
  111. getTermList(planid) {
  112. let r = this.planList.find(f => f.id == planid);
  113. if (r) {
  114. let term = _.get(r, 'termnum', []);
  115. this.$set(this, `termList`, term);
  116. }
  117. this.setVuexOpt();
  118. },
  119. //为了处理班主任的班级列表,先复制,再看看是不是需要查询班级列表
  120. toCheckUserType() {
  121. this.setVuexOpt();
  122. this.options.classid = undefined;
  123. if (this.user.type == 1 || this.user.type == 3) this.getClassOption();
  124. },
  125. setVuexOpt() {
  126. this.changeOpt(this.options);
  127. },
  128. toClear() {
  129. let planid = _.get(this.options, 'planid');
  130. if (planid) {
  131. let res = this.planList.find(f => f.id == planid);
  132. if (!res) this.$set(this.options, 'planid', undefined);
  133. }
  134. let termid = _.get(this.options, 'termid');
  135. if (termid) {
  136. let res = this.planList.find(f => f.id == planid);
  137. if (!res) this.$set(this.options, 'termid', undefined);
  138. }
  139. },
  140. async settingSave() {
  141. let res = await this.sUpdate(this.options);
  142. this.$checkRes(res, '设置成功', res.errmsg);
  143. },
  144. //班主任使用,默认班级
  145. async getClassOption() {
  146. let termid = _.get(this.defaultOption, 'termid');
  147. let planid = _.get(this.defaultOption, 'planid');
  148. if (!termid) return;
  149. let res;
  150. if (this.user.type == 1) {
  151. res = await this.getClassList({ termid: this.defaultOption.termid, headteacherid: this.user.userid });
  152. if (this.$checkRes(res)) this.$set(this, `classList`, res.data);
  153. }
  154. if (this.user.type == 3) {
  155. res = await this.teaclass({ planid: planid, teaid: this.user.userid });
  156. const elm = res.data.filter(item => item.termid == termid);
  157. this.$set(this, `classList`, elm);
  158. }
  159. },
  160. },
  161. watch: {
  162. defaultOption: {
  163. handler(val) {
  164. if (val) {
  165. let opt = _.get(this, `options`);
  166. if (!opt) this.$set(this, `options`, _.cloneDeep(val));
  167. }
  168. },
  169. immediate: true,
  170. deep: true,
  171. },
  172. options: {
  173. immediate: true,
  174. deep: true,
  175. handler(val, oval) {
  176. if (!_.isEqual(val, oval) && val) this.checkOption();
  177. },
  178. },
  179. },
  180. computed: {
  181. ...mapState(['user', 'defaultOption']),
  182. pageTitle() {
  183. return `${this.$route.meta.title}`;
  184. },
  185. },
  186. metaInfo() {
  187. return { title: this.$route.meta.title };
  188. },
  189. };
  190. </script>
  191. <style lang="less" scoped>
  192. .user-menu {
  193. height: 4rem;
  194. .el-col {
  195. margin-left: 10px;
  196. span {
  197. margin-left: 10px;
  198. }
  199. }
  200. }
  201. </style>