default-select.vue 4.2 KB

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