cascaderOption.vue 4.7 KB

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