index.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <div class="orgTree van-hairline--bottom">
  3. <tree-select
  4. :addendToBody="true"
  5. @select="onSelect"
  6. v-model="selected"
  7. :options="orgTree"
  8. :clearable="clearable"
  9. label='检查机构'
  10. :backspaceRemoves="false"
  11. :placeholder="placeholder"
  12. :normalizer="tenantIdnormalizer"
  13. :show-count="true"
  14. :noChildrenText="''"
  15. noResultsText="暂无符合条件的数据">
  16. </tree-select>
  17. </div>
  18. </template>
  19. <script>
  20. import TreeSelect from '@riophae/vue-treeselect'
  21. import '@riophae/vue-treeselect/dist/vue-treeselect.css'
  22. import {mapGetters} from "vuex";
  23. export default {
  24. components: {
  25. TreeSelect
  26. },
  27. props: {
  28. //是否展示机构简称
  29. isOrgName:{
  30. type:Boolean,
  31. default:true
  32. },
  33. value: {
  34. type: [String,Number],
  35. default: null
  36. },
  37. placeholder: {
  38. type: String,
  39. default: '请选择机构'
  40. },
  41. clearable:{
  42. type:Boolean,
  43. default:false
  44. }
  45. },
  46. data() {
  47. return {
  48. treeData: [],
  49. selected: null,
  50. }
  51. },
  52. computed: {
  53. ...mapGetters(['orgTree'])
  54. },
  55. watch: {
  56. value: {
  57. handler(val) {
  58. if(!val){
  59. this.selected = null
  60. }else {
  61. this.selected = this.value
  62. }
  63. },
  64. },
  65. },
  66. methods: {
  67. /** treeSelect组件自定义数据*/
  68. tenantIdnormalizer(node, instanceId) {
  69. if (!node.children || !node.children.length) {
  70. delete node.children
  71. }
  72. return {
  73. id: node.id,
  74. label: this.isOrgName? node.shortName: node.name,
  75. children: node.children
  76. }
  77. },
  78. onSelect(value) {
  79. this.$emit('change', value.id)
  80. this.$emit('changeItem', value)
  81. }
  82. },
  83. model: {
  84. prop: 'value',
  85. event: 'change'
  86. }
  87. }
  88. </script>
  89. <style lang="scss">
  90. .orgTree {
  91. font-size: 28px;
  92. svg {
  93. background-size: 22px 22px;
  94. width: 22px;
  95. height: 22px;
  96. }
  97. .vue-treeselect__control {
  98. width: 100%;
  99. height: 90px;
  100. padding: 0 20px;
  101. border-radius: 0;
  102. border: none;
  103. }
  104. .vue-treeselect__icon-warning{
  105. display: none;
  106. }
  107. .vue-treeselect__placeholder,
  108. .vue-treeselect__single-value {
  109. height: 90px;
  110. line-height: 90px;
  111. }
  112. .vue-treeselect__menu {
  113. padding: 20px;
  114. width: 100%;
  115. }
  116. .vue-treeselect__label {
  117. padding: 15px 20px;
  118. }
  119. .vue-treeselect__x-container {
  120. width: 50px;
  121. }
  122. .vue-treeselect__control-arrow-container {
  123. width: 50px;
  124. }
  125. .vue-treeselect--single .vue-treeselect__option--selected {
  126. font-weight: 500;
  127. color: #589eec;
  128. }
  129. .vue-treeselect--open-below .vue-treeselect__menu{
  130. border: 1px solid #cfcfcf;
  131. margin-top:3px;
  132. box-shadow: 0 0 10px 0 rgba(0,0,0,.1);
  133. }
  134. .vue-treeselect--focused:not(.vue-treeselect--open) .vue-treeselect__control{
  135. border-color: #fff;
  136. box-shadow: none;
  137. }
  138. }
  139. </style>