default-select.vue 6.9 KB

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