default-select.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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">
  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. }
  78. }
  79. },
  80. checkOption() {
  81. if (_.get(this.options, 'planid')) {
  82. this.search({ type: 'plan', planyearid: _.get(this.options, 'planyearid') });
  83. }
  84. },
  85. async changeList(type, data) {
  86. let obj = { type };
  87. let res;
  88. this.toClear();
  89. this.setVuexOpt();
  90. if (type == 'plan') {
  91. obj[`planyearid`] = data;
  92. await this.search(obj);
  93. }
  94. },
  95. getTermList(planid) {
  96. let r = this.planList.find(f => f.id == planid);
  97. if (r) {
  98. let term = _.get(r, 'termnum', []);
  99. this.$set(this, `termList`, term);
  100. }
  101. },
  102. setVuexOpt() {
  103. this.changeOpt(this.options);
  104. },
  105. toClear() {
  106. let planid = _.get(this.options, 'planid');
  107. if (planid) {
  108. let res = this.planList.find(f => f.id == planid);
  109. if (!res) this.$set(this.options, 'planid', undefined);
  110. }
  111. let termid = _.get(this.options, 'termid');
  112. if (termid) {
  113. let res = this.planList.find(f => f.id == planid);
  114. if (!res) this.$set(this.options, 'termid', undefined);
  115. }
  116. },
  117. async settingSave() {
  118. let res = await this.sUpdate(this.options);
  119. this.$checkRes(res, '设置成功', res.errmsg);
  120. },
  121. },
  122. watch: {
  123. defaultOption: {
  124. handler(val) {
  125. if (val) {
  126. let opt = _.get(this, `options`);
  127. if (!opt) this.$set(this, `options`, _.cloneDeep(val));
  128. }
  129. },
  130. immediate: true,
  131. deep: true,
  132. },
  133. },
  134. computed: {
  135. ...mapState(['user', 'defaultOption']),
  136. pageTitle() {
  137. return `${this.$route.meta.title}`;
  138. },
  139. },
  140. metaInfo() {
  141. return { title: this.$route.meta.title };
  142. },
  143. };
  144. </script>
  145. <style lang="less" scoped>
  146. .user-menu {
  147. height: 4rem;
  148. .el-col {
  149. margin-left: 10px;
  150. span {
  151. margin-left: 10px;
  152. }
  153. }
  154. }
  155. </style>