cascaderOption.vue 6.2 KB

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