LevelSetting.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <div class="all">
  3. <div class="flex-box main">
  4. <div class="flex-5 right">
  5. <div v-show="isActive == 2" class="flex-center-center">
  6. <el-form ref="detailForm" @submit.native.prevent label-width="150px">
  7. <div class="title">绩效等级配置</div>
  8. <div style="height: 30px;"></div>
  9. <ClassSet ref="ClassSet" :inputs="inputs" :inputsStyle="{ paddingLeft: '150px', width: '700px' }" style="margin: 0 auto;">
  10. </ClassSet>
  11. </el-form>
  12. </div>
  13. </div>
  14. </div>
  15. <div class="footer"><el-button type="primary" :loading="loading" @click="save()">保存设置</el-button></div>
  16. </div>
  17. </template>
  18. <script>
  19. import ClassSet from '@/performance/components/public/ClassSet';
  20. export default {
  21. components: { ClassSet },
  22. name: 'BasicsSet',
  23. data() {
  24. return {
  25. loading: false,
  26. isActive: 2,
  27. rules: {},
  28. inputs: [],//分值区间
  29. level_enable: true,//是否开启绩效等级
  30. isSave: true
  31. };
  32. },
  33. watch: {},
  34. created() {
  35. this.getAllSet();
  36. },
  37. mounted() { },
  38. methods: {
  39. // 获取全局设置
  40. getAllSet() {
  41. this.$axiosUser('get', 'api/pro/per/user/base_config').then(res => {
  42. let data = res.data.data;
  43. let levels = data.level_scope.levels;
  44. this.level_enable = data.level_enable;
  45. var inputs = [];
  46. var max = 0;//最大值
  47. if (levels) {
  48. levels.forEach((item, index) => {
  49. var obj;
  50. if (index == 0) {
  51. obj = { name: item.name, max: Number(item.value), min: 0 };
  52. } else {
  53. obj = { name: item.name, max: Number(item.value), min: max };//当不是第一个等级时,最小值为上一个的最大值
  54. }
  55. max = item.value;
  56. inputs.push(obj);
  57. })
  58. this.inputs = inputs
  59. }
  60. })
  61. },
  62. //保存
  63. save() {
  64. let is = true, level_scope = [];
  65. let isSave = this.$refs.ClassSet.isSave
  66. let inputsList = this.$refs.ClassSet.inputsList
  67. if (!isSave) {
  68. return false
  69. }
  70. inputsList.some(item => {
  71. if (!item.name) {
  72. this.$message.error('等级的名称不能为空');
  73. is = false;
  74. return true;
  75. }
  76. if (item.max == 0) {
  77. this.$message.error('最大值不能为空或者0');
  78. is = false;
  79. return true;
  80. }
  81. level_scope.push({ name: item.name, value: Number(item.max) });
  82. })
  83. var level_scopes = {//参数的数据结构
  84. levels: level_scope
  85. };
  86. if (is) {
  87. this.loading = true;
  88. this.$axiosUser('post', 'api/pro/per/user/set_base_config', { level_scope: JSON.stringify(level_scopes) }).then(res => {
  89. this.$message.success('设置成功');
  90. this.getAllSet();
  91. }).finally(() => {
  92. this.loading = false;
  93. })
  94. }
  95. },
  96. // 监听最大值输入
  97. InputBiur(e, index) {
  98. this.isSave = true
  99. var max = this.inputsList[index].max;
  100. var min = this.inputsList[index].min;
  101. if (max == 0) {
  102. return false;
  103. }
  104. if (min >= max) {
  105. this.$message.error('不能小于或等于' + min);
  106. this.$set(this.inputsList[index], 'max', 0);
  107. this.isSave = false
  108. return false;
  109. }
  110. if (this.inputsList[index + 1]) {
  111. this.$set(this.inputsList[index + 1], 'min', max);
  112. }
  113. },
  114. addInput() {
  115. if (this.inputsList.length == 10) {
  116. this.$message.error('最高10个级别');
  117. return false;
  118. }
  119. var max = this.inputsList[this.inputsList.length - 1].max;
  120. this.inputsList.push({ name: '', min: max, max: 0 });
  121. },
  122. deleteInput(index) {
  123. if (index == 0) {
  124. this.$message.error('至少保留一个等级');
  125. return false;
  126. }
  127. var min = this.inputsList[index].min; //获取当前元素最小值
  128. this.inputsList.splice(index, 1);
  129. if (index != this.inputsList.length) {
  130. //当删除不是最后一位时
  131. this.$set(this.inputsList[index], 'min', min);
  132. }
  133. // // this.inputsList.some((item, i) => {
  134. // // if (i == index) {
  135. // this.inputsList.splice(i, 1); //在数组的some方法中,如果return true,就会立即终止这个数组的后续循环
  136. // // return true;
  137. // // }
  138. // // });
  139. },
  140. active(index) {
  141. this.isActive = index;
  142. }
  143. }
  144. };
  145. </script>
  146. <style scoped="scoped">
  147. .all {
  148. width: 100%;
  149. height: 100%;
  150. position: relative;
  151. box-sizing: border-box;
  152. background-color: #fff;
  153. }
  154. .title {
  155. text-align: center;
  156. font-weight: 600;
  157. margin-bottom: 10px;
  158. background-color: #f5f7fa;
  159. padding: 15px;
  160. box-sizing: border-box;
  161. }
  162. .main {
  163. min-height: calc(100% - 40px);
  164. }
  165. .title-f {
  166. margin-bottom: 20px;
  167. }
  168. .footer {
  169. background-color: #fff;
  170. border-top: 1px solid #ebebeb;
  171. height: 40px;
  172. text-align: center;
  173. padding-top: 10px;
  174. }
  175. .checkChild {
  176. background-color: #fbfdff;
  177. margin-left: 20px;
  178. }
  179. .left,
  180. .right {
  181. height: 100%;
  182. overflow: auto;
  183. }
  184. .ul {
  185. border: 1px solid #ebebeb;
  186. height: 100%;
  187. border-bottom: none;
  188. }
  189. .li {
  190. padding: 15px;
  191. position: relative;
  192. }
  193. .li:hover {
  194. background-color: #f5f7fa;
  195. }
  196. .active-li {
  197. color: #409EFF !important;
  198. background-color: #f5f7fa;
  199. }
  200. .active-li::before {
  201. content: '';
  202. position: absolute;
  203. width: 3px;
  204. height: 100%;
  205. background-color: #409EFF;
  206. left: 0;
  207. top: 0;
  208. }
  209. </style>