cascaderOption.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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.stop="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. console.log('我是子组件')
  98. if(!item.children) {
  99. this.$emit("cascaderOptionClick", item);
  100. }
  101. if(this.radios) {
  102. this.$emit("cascaderOptionClick", item);
  103. }
  104. },
  105. cascaderOptionClick(item) {
  106. this.liClick(item)
  107. }
  108. },
  109. };
  110. </script>
  111. <style scoped lang="scss">
  112. .childComponents {
  113. width: 200px;
  114. position: absolute;
  115. top: -6px;
  116. right: -200px;
  117. height: 274px;
  118. background: #fff;
  119. border: 1px solid #E4E7ED;
  120. border-radius: 4px;
  121. border-top-left-radius: 0px;
  122. border-bottom-left-radius: 0px;
  123. box-sizing: border-box;
  124. margin: 5px 0;
  125. // box-shadow: 0 2px 12px #dfdfdf;
  126. }
  127. .child {
  128. width: 100%;
  129. max-height: 270px;
  130. overflow: auto;
  131. }
  132. .transitionBoxUl {
  133. list-style: none;
  134. padding: 6px 0;
  135. margin: 0;
  136. -webkit-box-sizing: border-box;
  137. box-sizing: border-box;
  138. }
  139. .transitionBoxUl li {
  140. font-size: 14px;
  141. padding: 0 20px;
  142. // position: relative;
  143. white-space: nowrap;
  144. overflow: hidden;
  145. text-overflow: ellipsis;
  146. color: #606266;
  147. height: 34px;
  148. line-height: 34px;
  149. -webkit-box-sizing: border-box;
  150. box-sizing: border-box;
  151. cursor: pointer;
  152. display: flex;
  153. align-items: center;
  154. }
  155. .liHover {
  156. background-color: #F5F7FA;
  157. // color: #409eff !important;
  158. }
  159. .liHover .idxspan {
  160. color: #409eff !important;
  161. font-weight: 700;
  162. }
  163. .transitionBoxUl span {
  164. flex: 1;
  165. width: 110px;
  166. width: 20px;
  167. padding: 0 10px;
  168. white-space: nowrap;
  169. overflow: hidden;
  170. text-overflow: ellipsis;
  171. }
  172. </style>