connectionTree.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <view style="width: 100%;height: 100%">
  3. <scroll-view scroll-y="true" class="left">
  4. <view v-for="(fItem, fIndex) in dataList" :key="fItem+fIndex"
  5. class="row"
  6. :class="[fIndex===showCategoryIndex ?'on':'']"
  7. @tap="showCategory(fIndex)">
  8. <view class="text"
  9. :style="$i18n.locale=='zh'?'':'text-algin:center;'">
  10. {{ $i18n.locale == 'zh' ? fItem[labelZh] : fItem[labelEn] }}
  11. </view>
  12. </view>
  13. </scroll-view>
  14. <block v-for="(fItem, fIndex) in dataList" :key="fItem+fIndex+'1'"
  15. @tap="showCategory(fIndex)">
  16. <scroll-view scroll-y class="right" v-if="fIndex === showCategoryIndex">
  17. <view v-for="(item,index) in fItem[childrenName]" :key="'c'+index"
  18. :class="(item[childrenName]&&item[childrenName].length>0)?'':'cate'">
  19. <view v-if="item[childrenName] && item[childrenName].length>0">
  20. <view :class="{'getCategory':item[childrenName].length>0}">
  21. {{ $i18n.locale=='zh'?item[labelZh]:item[labelEn] }}
  22. </view>
  23. <view class="threemenu">
  24. <view v-for="(i,j) in item[childrenName]" :key="j"
  25. class="cateText"
  26. @click="getCategory(i,j)"
  27. :class="{'cateTextActive':i.ifClick}">
  28. {{$i18n.locale=='zh'?i[labelZh]:i[labelEn]}}
  29. </view>
  30. </view>
  31. </view>
  32. <view v-else>
  33. <view class="cateText"
  34. @click="getCategory(item,index)"
  35. :class="{'cateTextActive':item.ifClick}">
  36. {{ $i18n.locale=='zh'?item[labelZh]:item[labelEn] }}
  37. </view>
  38. </view>
  39. </view>
  40. </scroll-view>
  41. </block>
  42. </view>
  43. </template>
  44. <script>
  45. export default {
  46. name: "connectionTree",
  47. props: {
  48. dataList: {
  49. type: Array,
  50. default: []
  51. },
  52. childrenName: {
  53. type: String,
  54. default: 'children'
  55. },
  56. multiple: {
  57. type: Boolean,
  58. default: false
  59. },
  60. labelZh: {
  61. type: String,
  62. default: 'label'
  63. },
  64. labelEn: {
  65. type: String,
  66. default: 'label'
  67. },
  68. dataListMap:{
  69. type: [Array, Object]
  70. }
  71. },
  72. data() {
  73. return {
  74. showCategoryIndex: 0, // 一级菜单高亮显示序号
  75. }
  76. },
  77. mounted(){
  78. console.log(this.dataList)
  79. },
  80. methods: {
  81. showCategory(index) {
  82. this.showCategoryIndex = index;
  83. },
  84. getCategory(item,index){
  85. if(item[this.childrenName]?.length>0){
  86. return;
  87. }else{
  88. let ifClick = !item.ifClick
  89. if(!this.multiple){
  90. this.$emit('dataListMap', {item,ifClick})
  91. }else{
  92. this.$emit('dataListMap', {item,ifClick})
  93. }
  94. }
  95. setTimeout(()=>{
  96. this.$emit('getCategory',{item:this.dataListMap,index})
  97. },100)
  98. }
  99. }
  100. }
  101. </script>
  102. <style scoped lang="scss">
  103. .left, .right {
  104. position: absolute;
  105. height: 100%;
  106. top: 0;
  107. bottom: 0upx;
  108. }
  109. .left {
  110. width: 24%;
  111. left: 0upx;
  112. background: #F2F2F2;
  113. }
  114. .right {
  115. width: 76%;
  116. left: 24%;
  117. background-color: #fff;
  118. margin-left: 0;
  119. padding: 0 20upx;
  120. }
  121. .row {
  122. width: 100%;
  123. height: 90upx;
  124. display: flex;
  125. align-items: center;
  126. .text {
  127. width: 100%;
  128. position: relative;
  129. font-size: 28upx;
  130. display: flex;
  131. justify-content: center;
  132. color: #3c3c3c;
  133. text-align: center;
  134. .block {
  135. position: absolute;
  136. width: 0upx;
  137. left: 0;
  138. }
  139. }
  140. &.on {
  141. height: 90upx;
  142. background-color: #fff;
  143. .text {
  144. font-size: 30upx;
  145. color: #1677FD;
  146. .block {
  147. width: 6upx;
  148. height: 100%;
  149. left: 10upx;
  150. }
  151. }
  152. }
  153. }
  154. .threemenu {
  155. display: flex;
  156. flex-wrap: wrap;
  157. //.cateText {
  158. // margin: 0 20upx 20upx 0;
  159. // background: #F2F2F2;
  160. // padding: 20upx;
  161. // border-radius: 8upx;
  162. // width: 46%;
  163. // overflow: hidden;
  164. // text-overflow: ellipsis;
  165. // white-space: nowrap;
  166. // text-align: center;
  167. //
  168. // &.active {
  169. // border: 1px solid #1777FE;
  170. // color: #1777FE;
  171. // background: #fff;
  172. // }
  173. //}
  174. }
  175. .getCategory {
  176. height: 90upx;
  177. line-height: 90upx;
  178. font-weight: 700;
  179. color: #0079ef
  180. }
  181. .cate {
  182. display: inline-block;
  183. width: 240upx;
  184. vertical-align: middle;
  185. margin-right: 20upx;
  186. }
  187. .cateText {
  188. padding: 10upx;
  189. margin: 10upx 20upx 10upx 0;
  190. display: inline-block;
  191. width: 240upx;
  192. vertical-align: middle;
  193. background: #f1f2f3;
  194. text-align: center;
  195. }
  196. .cateTextActive {
  197. padding: 10upx;
  198. margin: 10upx 20upx 10upx 0;
  199. display: inline-block;
  200. width: 240upx;
  201. vertical-align: middle;
  202. background-color: #0079ef;
  203. color: #fff;
  204. text-align: center;
  205. }
  206. </style>