当前位置:   article > 正文

层级关联,审批人功能

层级关联,审批人功能

 一个需求要求选择一级,下方展示一级的效果

后端给了审批人数据,但是数据需要单独处理

  1. <template>
  2. <div class="box">
  3. <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px">
  4. <el-form-item label="层级" prop="cj">
  5. <el-select v-model="ruleForm.cj" @change="btn" clearable>
  6. <el-option label="一级" :value="1"></el-option>
  7. <el-option label="二级" :value="2"></el-option>
  8. <el-option label="三级" :value="3"></el-option>
  9. <el-option label="四级" :value="4"></el-option>
  10. <el-option label="五级" :value="5"></el-option>
  11. </el-select>
  12. </el-form-item>
  13. <el-form-item label="审批人" required>
  14. <el-timeline class="m-t-20">
  15. <el-timeline-item placement="top" v-for="(item,index) in ruleForm.list" :key="index">
  16. <el-form-item :prop="'list.'+index+'.userName'" :rules="rules.userName">
  17. {{num[index]}}级审批人:
  18. <el-select v-model="item.userName" clearable>
  19. <el-option v-for="(item,index) in option" :key="index" :label="item.userName" :value="item.userName"></el-option>
  20. </el-select>
  21. </el-form-item>
  22. </el-timeline-item>
  23. </el-timeline>
  24. </el-form-item>
  25. <el-form-item>
  26. <el-button @click="submit">提交</el-button>
  27. </el-form-item>
  28. </el-form>
  29. </div>
  30. </template>
  31. <script>
  32. export default {
  33. data () {
  34. return {
  35. ruleForm: {
  36. cj: '',
  37. list: []
  38. },
  39. rules: {
  40. cj: [
  41. { required: true, message: '请选择', trigger: 'change' }
  42. ],
  43. userName: [
  44. { required: true, message: '请选择', trigger: 'change' }
  45. ]
  46. },
  47. num: ['一', '二', '三', '四', '五'],
  48. // 审批人数据
  49. option: [
  50. {
  51. userId: 11020218,
  52. userName: "tumourdata1",
  53. aaa: '1'
  54. },
  55. {
  56. userId: 11020217,
  57. userName: "tumourdata2",
  58. aaa: '12'
  59. },
  60. {
  61. userId: 11020213,
  62. userName: "tumourdata3",
  63. aaa: '13'
  64. }
  65. ]
  66. }
  67. },
  68. methods: {
  69. // 切换层级
  70. btn (val) {
  71. // 后端需要加上标识,选的几级
  72. const selectOptions = [
  73. {
  74. level: 1,
  75. userName: ''
  76. },
  77. {
  78. level: 2,
  79. userName: ''
  80. },
  81. {
  82. level: 3,
  83. userName: ''
  84. },
  85. {
  86. level: 4,
  87. userName: ''
  88. },
  89. {
  90. level: 5,
  91. userName: ''
  92. }
  93. ]
  94. this.ruleForm.list = selectOptions.slice(0, val)
  95. },
  96. // 提交
  97. submit () {
  98. const arr = []
  99. this.ruleForm.list.forEach(item => {
  100. this.option.forEach(item2 => {
  101. if (item2.userName == item.userName) {
  102. arr.push({
  103. ...item2,
  104. level: item.level
  105. })
  106. }
  107. })
  108. })
  109. this.$refs.ruleForm.validate((valid) => {
  110. if (valid) {
  111. // 提交数据
  112. }
  113. })
  114. }
  115. }
  116. }
  117. </script>
  118. <style lang="less" scoped>
  119. .box {
  120. margin: 200px;
  121. border: 1px solid black;
  122. background: #fff;
  123. padding: 30px 0;
  124. }
  125. /deep/ .el-timeline-item__wrapper {
  126. top: -20px;
  127. }
  128. </style>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/118991
推荐阅读
相关标签
  

闽ICP备14008679号