default-select.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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="12" 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="setVuexOpt()">
  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>
  34. <el-button type="text" size="mini" @click="settingSave" v-if="this.user.type == 0">保存默认值</el-button>
  35. </span>
  36. </el-col>
  37. </el-row>
  38. </div>
  39. </template>
  40. <script>
  41. import _ from 'lodash';
  42. import { mapState, mapMutations, createNamespacedHelpers } from 'vuex';
  43. const { mapActions: trainBatch } = createNamespacedHelpers('trainBatch');
  44. const { mapActions: trainplan } = createNamespacedHelpers('trainplan');
  45. const { mapActions: setting } = createNamespacedHelpers('setting');
  46. export default {
  47. name: 'default-select',
  48. props: {},
  49. components: {},
  50. data: function() {
  51. return {
  52. loading: true,
  53. options: undefined,
  54. planYearList: [],
  55. planList: [],
  56. termList: [],
  57. };
  58. },
  59. async created() {
  60. // this.$set(this, `options`, _.cloneDeep(this.defaultOption));
  61. this.search({ type: 'planYear' });
  62. this.checkOption();
  63. this.loading = false;
  64. },
  65. methods: {
  66. ...mapMutations(['deleteUser', 'changeOpt']),
  67. ...trainBatch({ getplanYear: 'query' }),
  68. ...trainplan({ getplan: 'query' }),
  69. ...setting({ sFetch: 'fetch', sUpdate: 'update' }),
  70. async search({ type, ...info }) {
  71. let res = await _.get(this, `get${type}`)({ ...info });
  72. if (this.$checkRes(res)) {
  73. this.$set(this, `${type}List`, res.data);
  74. if (type == 'plan') {
  75. let planid = _.get(this.options, 'planid');
  76. this.getTermList(planid);
  77. } else if (type == 'planYear') {
  78. // this.checkOption();
  79. }
  80. }
  81. },
  82. checkOption() {
  83. if (_.get(this.options, 'planid')) {
  84. this.search({ type: 'plan', planyearid: _.get(this.options, 'planyearid') });
  85. }
  86. },
  87. async changeList(type, data) {
  88. let obj = { type };
  89. let res;
  90. this.toClear();
  91. this.setVuexOpt();
  92. if (type == 'plan') {
  93. obj[`planyearid`] = data;
  94. await this.search(obj);
  95. }
  96. },
  97. getTermList(planid) {
  98. let r = this.planList.find(f => f.id == planid);
  99. if (r) {
  100. let term = _.get(r, 'termnum', []);
  101. this.$set(this, `termList`, term);
  102. }
  103. this.setVuexOpt();
  104. },
  105. setVuexOpt() {
  106. this.changeOpt(this.options);
  107. },
  108. toClear() {
  109. let planid = _.get(this.options, 'planid');
  110. if (planid) {
  111. let res = this.planList.find(f => f.id == planid);
  112. if (!res) this.$set(this.options, 'planid', undefined);
  113. }
  114. let termid = _.get(this.options, 'termid');
  115. if (termid) {
  116. let res = this.planList.find(f => f.id == planid);
  117. if (!res) this.$set(this.options, 'termid', undefined);
  118. }
  119. },
  120. async settingSave() {
  121. let res = await this.sUpdate(this.options);
  122. this.$checkRes(res, '设置成功', res.errmsg);
  123. },
  124. },
  125. watch: {
  126. defaultOption: {
  127. handler(val) {
  128. if (val) {
  129. let opt = _.get(this, `options`);
  130. if (!opt) this.$set(this, `options`, _.cloneDeep(val));
  131. }
  132. },
  133. immediate: true,
  134. deep: true,
  135. },
  136. },
  137. computed: {
  138. ...mapState(['user', 'defaultOption']),
  139. pageTitle() {
  140. return `${this.$route.meta.title}`;
  141. },
  142. },
  143. metaInfo() {
  144. return { title: this.$route.meta.title };
  145. },
  146. };
  147. </script>
  148. <style lang="less" scoped>
  149. .user-menu {
  150. height: 4rem;
  151. .el-col {
  152. margin-left: 10px;
  153. span {
  154. margin-left: 10px;
  155. }
  156. }
  157. }
  158. </style>