cascaderOption.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <div class="childComponents">
  3. <div class="child">
  4. <ul class="transitionBoxUl">
  5. <li :class="transitionBoxLiIdx == index ? 'liHover' : ''" v-for="(item, index) in options" :key="index" @mouseover="liMouseOver(index, item)" @click="liClick(item)">
  6. <span :class="item.children ? 'idxspan' : ''" v-if="!radios">{{item.label}}</span>
  7. <span v-if="radios" style="margin-left: -15px">
  8. <el-radio v-model="departmentId" :label="item.value">
  9. <span class="idxspan" style="margin-left: -10px">
  10. <!-- {{item.label}} -->
  11. <ww-open-data type='departmentName' :openid='item.label'></ww-open-data>
  12. </span>
  13. </el-radio>
  14. </span>
  15. <i class="el-icon-arrow-right" v-if="item.children"></i>
  16. </li>
  17. </ul>
  18. </div>
  19. <div v-for="(item, index) in options" :key="index">
  20. <div v-if="item.children">
  21. <cascaderOption :subject="item.children" :radios="radiosFlg" :subjectId="departmentId" v-show="transitionBoxLiIdx == index" @cascaderOptionClick="cascaderOptionClick"></cascaderOption>
  22. </div>
  23. </div>
  24. </div>
  25. </template>
  26. <script>
  27. // 引入里面的
  28. import cascaderOption from "@/components/cascaderOption.vue"
  29. export default {
  30. name: 'cascaderOption',
  31. components: {
  32. cascaderOption
  33. },
  34. props: {
  35. subject:{
  36. type: Array
  37. },
  38. subjectId: {
  39. type: [String, Number]
  40. },
  41. // 是否为单选
  42. radios: {
  43. type: Boolean,
  44. default: false
  45. },
  46. },
  47. watch: {
  48. subject: {
  49. handler(newValue, oldValue) {
  50. console.log(newValue, '子组件')
  51. this.options = newValue
  52. if(newValue) {
  53. this.options = newValue
  54. }
  55. },
  56. deep: true,
  57. },
  58. },
  59. data() {
  60. return {
  61. options: [],
  62. transitionBoxLiIdx: '0',
  63. hoverList: [],
  64. radiosFlg: false, // 是否为单选
  65. departmentId: '',
  66. radioVal: ''
  67. };
  68. },
  69. computed: {},
  70. watch: {
  71. radios: {
  72. handler(newValue, oldValue) {
  73. this.radiosFlg = newValue
  74. },
  75. }
  76. },
  77. created() {},
  78. mounted() {
  79. if(this.subject) {
  80. this.options = JSON.parse(JSON.stringify(this.subject))
  81. }
  82. this.radiosFlg = JSON.parse(JSON.stringify(this.radios))
  83. if(this.subjectId) {
  84. this.departmentId = JSON.parse(JSON.stringify(this.subjectId))
  85. }
  86. },
  87. methods: {
  88. liMouseOver(index, item) {
  89. this.transitionBoxLiIdx = index
  90. if(item.children) {
  91. this.hoverList = item.children
  92. } else {
  93. this.hoverList = []
  94. }
  95. },
  96. liClick(item) {
  97. if(!item.children) {
  98. this.$emit("cascaderOptionClick", item);
  99. }
  100. if(this.radios) {
  101. this.$emit("cascaderOptionClick", item);
  102. }
  103. },
  104. cascaderOptionClick(item) {
  105. this.liClick(item)
  106. }
  107. },
  108. };
  109. </script>
  110. <style scoped lang="scss">
  111. .childComponents {
  112. width: 200px;
  113. position: absolute;
  114. top: -6px;
  115. right: -200px;
  116. height: 274px;
  117. background: #fff;
  118. border: 1px solid #E4E7ED;
  119. border-radius: 4px;
  120. border-top-left-radius: 0px;
  121. border-bottom-left-radius: 0px;
  122. box-sizing: border-box;
  123. margin: 5px 0;
  124. // box-shadow: 0 2px 12px #dfdfdf;
  125. }
  126. .child {
  127. width: 100%;
  128. max-height: 270px;
  129. overflow: auto;
  130. }
  131. .transitionBoxUl {
  132. list-style: none;
  133. padding: 6px 0;
  134. margin: 0;
  135. -webkit-box-sizing: border-box;
  136. box-sizing: border-box;
  137. }
  138. .transitionBoxUl li {
  139. font-size: 14px;
  140. padding: 0 20px;
  141. // position: relative;
  142. white-space: nowrap;
  143. overflow: hidden;
  144. text-overflow: ellipsis;
  145. color: #606266;
  146. height: 34px;
  147. line-height: 34px;
  148. -webkit-box-sizing: border-box;
  149. box-sizing: border-box;
  150. cursor: pointer;
  151. display: flex;
  152. align-items: center;
  153. }
  154. .liHover {
  155. background-color: #F5F7FA;
  156. // color: #409eff !important;
  157. }
  158. .liHover .idxspan {
  159. color: #409eff !important;
  160. font-weight: 700;
  161. }
  162. .transitionBoxUl span {
  163. flex: 1;
  164. width: 110px;
  165. width: 20px;
  166. padding: 0 10px;
  167. white-space: nowrap;
  168. overflow: hidden;
  169. text-overflow: ellipsis;
  170. }
  171. </style>