sagasloudTreeSelect.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <template>
  2. <div class="sgy-select" tabindex="0" @blur="show = false">
  3. <div class="fill" @click="show = !show">
  4. <div class="tags">
  5. <div>
  6. <label>{{label}} :</label>
  7. <span v-if="all">全部</span>
  8. <ul class="items" v-else>
  9. <template v-for="item in value.buildingId" >
  10. {{getTextByValue(item)}}
  11. </template>
  12. <template v-for="item in value.floorId" >
  13. {{getTextByValue(item)}}
  14. </template>
  15. <template v-for="item in value.spaceId" >
  16. {{getTextByValue(item)}}
  17. </template>
  18. </ul>
  19. </div>
  20. </div>
  21. <Icon type="ios-arrow-down" :class="{rotate: show}"/>
  22. </div>
  23. <div class="list" v-if="show">
  24. <ul>
  25. <li class="clear" @click="clearSelect">清空选项</li>
  26. <sgy-tree ref="sgyTree" :treeList="list" @on-change="onChange"></sgy-tree>
  27. </ul>
  28. </div>
  29. </div>
  30. </template>
  31. <script>
  32. import Tree from './tree.vue'
  33. // import { log } from 'util'
  34. export default {
  35. model: {
  36. prop: 'value',
  37. event: 'input'
  38. },
  39. components: {
  40. 'sgy-tree': Tree
  41. },
  42. props: {
  43. value: {},
  44. list: {
  45. type: Array,
  46. default: () => []
  47. },
  48. label: ""
  49. },
  50. data () {
  51. return {
  52. show: false
  53. }
  54. },
  55. computed: {
  56. all () {
  57. return this.value.buildingId.length == 0 && this.value.floorId.length == 0 && this.value.spaceId.length == 0
  58. }
  59. },
  60. mounted () {
  61. },
  62. methods: {
  63. onChange (val) {
  64. this.$emit('input', val)
  65. this.$emit('onChange')
  66. },
  67. clearSelect () {
  68. let obj = {
  69. buildingId: [],
  70. floorId: [],
  71. spaceId: []
  72. }
  73. this.$emit('input', obj)
  74. // 清空checked
  75. this.$refs['sgyTree'].setTreeList(this.list)
  76. },
  77. getTextByValue (value) {
  78. for (let i of this.list) {
  79. if (i.value == value) {
  80. return i.title
  81. } else if (i.children && i.children.length > 0) {
  82. for (let j of i.children) {
  83. if (j.value == value) {
  84. return j.title
  85. } else if (j.children && j.children.length > 0) {
  86. for (let k of j.children) {
  87. if (k.value == value) {
  88. return k.title
  89. }
  90. }
  91. }
  92. }
  93. }
  94. }
  95. return value
  96. }
  97. }
  98. }
  99. </script>
  100. <style scoped lang="less" style="text/less">
  101. .rotate {
  102. transform: rotate(180deg);
  103. }
  104. .sgy-select {
  105. outline: none;
  106. width:280px;
  107. position: relative;
  108. z-index: 2;
  109. .fill {
  110. vertical-align: middle;
  111. width: 100%;
  112. height:34px;
  113. border-radius: 4px;
  114. box-shadow: none;
  115. border: 1px solid #ccc;
  116. padding: 0 2px;
  117. cursor: pointer;
  118. display: flex;
  119. align-items: center;
  120. justify-content: space-between;
  121. background: #fff;
  122. overflow: hidden;
  123. text-overflow: ellipsis;
  124. white-space: nowrap;
  125. &:hover,
  126. &:active,
  127. &:focus {
  128. outline: none;
  129. border-color: #2d8cf0;
  130. }
  131. i.rotate,.ivu-icon-ios-arrow-down {
  132. margin-right: 10px;
  133. transition: transform 0.3s ease-in-out;
  134. }
  135. .tags {
  136. > div {
  137. display: flex;
  138. margin-top: 9px;
  139. label{
  140. font-size: 14px;
  141. color: #212830;
  142. padding-left: 3px;
  143. }
  144. span {
  145. display: inline-block;
  146. font-size: 14px;
  147. padding-right: 5px;
  148. padding-left: 5px;
  149. border-radius: 2px;
  150. color: #212830;
  151. }
  152. ul {
  153. display: inline-block;
  154. font-size: 14px;
  155. color: #212830;
  156. width: 140px;
  157. white-space: nowrap;
  158. overflow: hidden;
  159. text-overflow: ellipsis;
  160. padding-left: 5px;
  161. margin-bottom:-3px;
  162. li {
  163. display: inline-block;
  164. padding-right: 5px;
  165. padding-left: 9px;
  166. }
  167. }
  168. }
  169. }
  170. }
  171. .list {
  172. //margin-top: 5px;
  173. z-index: 3;
  174. ul {
  175. border: 1px solid #E0E0E0;
  176. box-shadow: 0 1px 6px 0 rgba(0,0,0,0.12);
  177. border-radius: 4px;
  178. background-color: #fff;
  179. width: 95%;
  180. position: absolute;
  181. max-height: 338px;
  182. overflow: auto;
  183. .clear {
  184. color: #728DEE;
  185. padding-left: 15px;
  186. }
  187. li {
  188. padding: 5px;
  189. cursor: pointer;
  190. &:hover {
  191. background-color: #f5f7fa;
  192. }
  193. &.actived {
  194. color:#2d8cf0;
  195. }
  196. i{
  197. margin-right: 8px;
  198. }
  199. }
  200. }
  201. }
  202. }
  203. </style>