yyb
2026-05-22 552ec6b7d8ccc56c379da195fc6c9c74312b1070
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<template>
  <view class="structure-item-wrapper"
        :class="{ 'is-root': level === 0, 'is-last': isLast }">
    <!-- 树形连接线 (非根节点显示) -->
    <template v-if="level > 0">
      <view class="line-v"></view>
      <view class="line-h"></view>
    </template>
    <view class="structure-item-card"
          :class="{ 'has-children': hasChildren }">
      <view class="card-main">
        <view class="item-header"
              @click="toggleExpand">
          <view class="header-left">
            <view v-if="hasChildren"
                  class="expand-icon"
                  :class="{ 'is-expanded': isExpanded }">
              <up-icon name="arrow-right"
                       size="14"
                       color="#999"></up-icon>
            </view>
            <view v-else
                  class="dot-icon"></view>
            <text class="item-title">{{ item.productName || '未选择产品' }}</text>
          </view>
          <up-tag v-if="hasChildren"
                  text="组合"
                  type="primary"
                  size="mini"
                  plain
                  shape="circle" />
        </view>
        <view class="item-body">
          <view class="info-grid">
            <view class="info-item">
              <text class="label">规格型号:</text>
              <text class="value">{{ item.model || '-' }}</text>
            </view>
            <view class="info-item">
              <text class="label">消耗工序:</text>
              <text class="value">{{ getProcessName(item.processId) }}</text>
            </view>
            <view class="info-item">
              <text class="label">单位数量:</text>
              <text class="value highlight">{{ item.unitQuantity || 0 }}</text>
            </view>
            <view class="info-item">
              <text class="label">需求总量:</text>
              <text class="value highlight">{{ item.demandedQuantity || 0 }}</text>
            </view>
            <view class="info-item">
              <text class="label">单位:</text>
              <text class="value">{{ item.unit || '-' }}</text>
            </view>
            <view class="info-item">
              <text class="label">盘数:</text>
              <text class="value">{{ item.diskQuantity || 0 }}</text>
            </view>
          </view>
        </view>
      </view>
    </view>
    <!-- 递归展示子节点 -->
    <view v-if="hasChildren && isExpanded"
          class="children-container">
      <BomStructureItem v-for="(child, index) in item.children"
                        :key="index"
                        :item="child"
                        :level="level + 1"
                        :isLast="index === item.children.length - 1"
                        :processOptions="processOptions" />
    </view>
  </view>
</template>
 
<script setup>
  import { ref, computed, defineProps } from "vue";
 
  const props = defineProps({
    item: {
      type: Object,
      required: true,
    },
    level: {
      type: Number,
      default: 0,
    },
    isLast: {
      type: Boolean,
      default: false,
    },
    processOptions: {
      type: Array,
      default: () => [],
    },
  });
 
  const isExpanded = ref(true);
  const hasChildren = computed(
    () => props.item.children && props.item.children.length > 0
  );
 
  const toggleExpand = () => {
    if (hasChildren.value) {
      isExpanded.value = !isExpanded.value;
    }
  };
 
  const getProcessName = id => {
    const process = props.processOptions.find(p => p.id === id);
    return process ? process.name : "-";
  };
</script>
 
<script>
  export default {
    name: "BomStructureItem",
  };
</script>
 
<style scoped lang="scss">
  .structure-item-wrapper {
    position: relative;
    padding-left: 44rpx;
 
    &.is-root {
      padding-left: 0;
    }
  }
 
  // 垂直连接线段
  .line-v {
    position: absolute;
    left: 18rpx; // 居中于 44rpx 的缩进内
    top: -20rpx; // 向上延伸覆盖上一个节点的 margin-bottom
    bottom: 0;
    width: 2rpx;
    background-color: #ddd;
    z-index: 1;
  }
 
  // 最后一个节点的垂直线只延伸到水平线位置
  .is-last > .line-v {
    bottom: auto;
    height: 60rpx; // 20rpx (top offset) + 40rpx (to horizontal line)
  }
 
  // 水平连接线
  .line-h {
    position: absolute;
    left: 18rpx;
    top: 40rpx; // 对齐到卡片内部图标中心 (padding 24 + icon 32/2)
    width: 26rpx;
    height: 2rpx;
    background-color: #ddd;
    z-index: 1;
  }
 
  .structure-item-card {
    position: relative;
    background: #fff;
    border-radius: 16rpx;
    margin-bottom: 20rpx;
    padding: 24rpx;
    box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
    border: 1rpx solid #f0f0f0;
    transition: all 0.3s;
    z-index: 2;
 
    &:active {
      background-color: #f9f9f9;
    }
 
    &.has-children {
      border-left: 6rpx solid #3c9cff;
    }
  }
 
  .card-main {
    .item-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 20rpx;
 
      .header-left {
        display: flex;
        align-items: center;
        flex: 1;
 
        .expand-icon {
          margin-right: 12rpx;
          transition: transform 0.3s;
          display: flex;
          align-items: center;
          justify-content: center;
          width: 32rpx;
          height: 32rpx;
 
          &.is-expanded {
            transform: rotate(90deg);
          }
        }
 
        .dot-icon {
          width: 12rpx;
          height: 12rpx;
          border-radius: 50%;
          background-color: #ccc;
          margin-right: 20rpx;
          margin-left: 10rpx;
        }
 
        .item-title {
          font-size: 30rpx;
          font-weight: bold;
          color: #333;
          line-height: 1.4;
        }
      }
    }
 
    .item-body {
      .info-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 12rpx 20rpx;
 
        .info-item {
          display: flex;
          font-size: 24rpx;
          line-height: 1.5;
 
          .label {
            color: #999;
            white-space: nowrap;
          }
 
          .value {
            color: #666;
            word-break: break-all;
 
            &.highlight {
              color: #3c9cff;
              font-weight: 500;
            }
          }
        }
      }
    }
  }
 
  .children-container {
    position: relative;
  }
</style>