firmTree.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <!-- firmTree.vue -->
  2. <template>
  3. <view>
  4. <view class="item_tree" @click="toggleNode">
  5. <view class="tree_title" :style="{paddingLeft:item.children.length > 0 ? '20rpx' : '0rpx'}">
  6. <view class="card_icon_arrow" v-if="item.children.length > 0">
  7. <u-icon name="arrow-right" v-if="!expanded"></u-icon>
  8. <u-icon name="arrow-down" v-else></u-icon>
  9. </view>
  10. <view class="left_title">
  11. <view class="name_tree_item">{{ item.name }}</view>
  12. <view class="distance_title" v-if="getDistance(item.provStore.lat,item.provStore.lng)">
  13. 距您{{getDistance(item.provStore.lat,item.provStore.lng)}}</view>
  14. </view>
  15. </view>
  16. <view>
  17. <u-button type="primary" size="small" text="确定" @click.native="choice(item)"></u-button>
  18. </view>
  19. </view>
  20. <view v-if="item.children && item.children.length && expanded">
  21. <firm-tree @confirm="confirm" v-for="child in item.children" :key="child.id" :item="child"></firm-tree>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. import calculateDistance from '@/utils/distance.js'
  27. export default {
  28. name: 'firmTree',
  29. props: ['item'],
  30. data() {
  31. return {
  32. expanded: false // 初始状态为折叠
  33. };
  34. },
  35. methods: {
  36. getDistance(value, value1) {
  37. const arr = value + ',' + value1
  38. const arr1 = calculateDistance(arr)
  39. return arr1
  40. },
  41. toggleNode() {
  42. this.expanded = !this.expanded; // 切换展开和折叠状态
  43. },
  44. choice(value) {
  45. this.$emit('confirm', value.id)
  46. },
  47. confirm(cmpCode) {
  48. this.$emit('confirm', cmpCode)
  49. }
  50. }
  51. }
  52. </script>
  53. <style lang="scss" scoped>
  54. .item_tree {
  55. display: flex;
  56. align-items: center;
  57. justify-content: space-between;
  58. padding: 20rpx;
  59. border-bottom: 2rpx solid transparent;
  60. border-image: linear-gradient(to bottom, transparent 50%, #e7e6e4 50%) 0 0 100% 0;
  61. }
  62. .tree_title {
  63. position: relative;
  64. display: flex;
  65. align-items: center;
  66. // padding-left: 20rpx;
  67. }
  68. .card_icon_arrow {
  69. position: absolute;
  70. left: 0rpx;
  71. }
  72. .left_title {
  73. margin-left: 20rpx;
  74. }
  75. .name_tree_item {
  76. color: #303133;
  77. font-size: 28rpx;
  78. font-weight: 500;
  79. }
  80. .distance_title {
  81. margin-top: 10rpx;
  82. font-size: 24rpx;
  83. color: #909399;
  84. }
  85. </style>