<template>
  <div class="mindmap-wrapper">
    <vue-org-tree
      v-if="treeReady"
      ref="orgTree"
      :treeData="treeData"
      :horizontal="false"
      :collapsable="true"
      :render-content="renderContent"
    />
  </div>
</template>

<script>
import VueOrgTree from 'vue-org-tree'

export default {
  name: 'SystemEquipment',
  components: { VueOrgTree },
  data() {
    return {
      treeReady: false,
      treeData: {
        name: '国家电网有限公司输变电工程机械化施工装备体系',
        expand: true,
        children: [
          {
            name: '架空输电线路工程',
            expand: true,
            children: [
              {
                name: '临时道路修筑',
                expand: true,
                children: [
                  { name: '道路修筑', children: [{ name: '道路修筑装备', children: [{ name: '清障开路车' }] }] },
                  {
                    name: '道路建设',
                    children: [
                      { name: '机械化路搭设装备', children: [{ name: '路面铺收车' }, { name: '滩涂通道板' }] },
                      { name: '机械化桥搭设装备', children: [{ name: '桥梁架收车' }, { name: '动力舟桥' }] },
                      { name: '机械化平台措设装备', children: [{ name: '作业浮箱' }] },
                    ],
                  },
                ],
              },
              {
                name: '物料运输',
                expand: true,
                children: [
                  {
                    name: '物料运输设备',
                    children: [
                      { name: '地面运输装备', children: [{ name: '履带式运输车' }] },
                      { name: '架空运输装备', children: [{ name: '货运索道' }, { name: '轨道式运输车' }] },
                      {
                        name: '空中运输装备',
                        children: [
                          { name: '有人直升机' },
                          { name: '重载无人机' },
                          { name: '系留气球' },
                          { name: '动力飞艇' },
                        ],
                      },
                    ],
                  },
                ],
              },
              {
                name: '基础施工',
                expand: true,
                children: [
                  {
                    name: '基坑开挖',
                    children: [
                      {
                        name: '岩石锚杆钻机(适用孔径90-150mm)',
                        children: [{ name: '分体式岩石锚杆钻机' }, { name: '一体式岩石锚杆钻机' }],
                      },
                      {
                        name: '微型桩钻机(适用孔径200-400mm)',
                        children: [
                          { name: '分体式微型桩钻机' },
                          { name: '轮步式作业平台' },
                          { name: '微型桩潜孔锤钻机' },
                        ],
                      },
                      {
                        name: '挖孔桩钻机(适用孔径600-3200mm)',
                        children: [{ name: '分体式挖孔桩钻机' }, { name: '电建钻机' }, { name: '深基坑作业一体机' }],
                      },
                      {
                        name: '螺旋锚钻机',
                        children: [{ name: '螺旋锚钻机' }],
                      },
                    ],
                  },
                  {
                    name: '钢筋笼制作',
                    children: [
                      {
                        name: '钢筋笼制作装置',
                        children: [{ name: '钢筋笼立式制作装置' }, { name: '钢筋笼卧式制作装置' }],
                      },
                    ],
                  },
                  {
                    name: '泥凝土浇筑',
                    children: [
                      {
                        name: '混凝土浇筑装备',
                        children: [{ name: '混凝土罐车' }, { name: '混凝土泵车' }, { name: '基础养护装置' }],
                      },
                    ],
                  },
                ],
              },
              {
                name: '组塔施工',
                expand: true,
                children: [
                  { name: '塔材组片', children: [{ name: '塔材组片装置', children: [{ name: '塔材组片装置' }] }] },
                  {
                    name: '塔材吊装',
                    children: [
                      { name: '流动式起重机', children: [{ name: '全地面起重机' }, { name: '履带式起重机' }] },
                      {
                        name: '固定式落地物杆',
                        children: [
                          { name: '悬浮物杆' },
                          { name: '落地摇臂抱杆' },
                          { name: '落地平壁抱杆' },
                          { name: '四柱抱杆' },
                        ],
                      },
                      {
                        name: '移动式落地抱杆',
                        children: [{ name: '履带式落地抱杆' }, { name: '轮步式落地抱杆' }],
                      },
                    ],
                  },
                  { name: '塔材紧固', children: [{ name: '塔材紧固装备', children: [{ name: '螺栓紧固机器人' }] }] },
                ],
              },
              {
                name: '架线施工',
                expand: true,
                children: [
                  {
                    name: '跨越施工',
                    children: [
                      { name: '固定式跨越架', children: [{ name: '金属格构式跨越架' }, { name: '悬索式跨越架' }] },
                      {
                        name: '移动式跨越架',
                        children: [{ name: '伞形跨越架' }, { name: '羊角跨越架' }, { name: '照明系统' }],
                      },
                    ],
                  },
                  {
                    name: '导地线展放',
                    children: [
                      {
                        name: '导地线展放装备',
                        children: [{ name: '多旋翼无人机' }, { name: '牵引机' }, { name: '张力机' }],
                      },
                    ],
                  },
                  {
                    name: '紧线挂线',
                    children: [
                      {
                        name: '紧线挂线装备',
                        children: [{ name: '电动紧线机' }, { name: '弧垂监测机器人' }, { name: '自动压接机' }],
                      },
                    ],
                  },
                  { name: '附件安装', children: [{ name: '附件安装装备', children: [{ name: '间隔棒安装机器人' }] }] },
                ],
              },
            ],
          },
          {
            name: '变电站工程',
            expand: true,
            children: [
              {
                name: '变电土建',
                expand: true,
                children: [
                  {
                    name: '地基施工',
                    children: [
                      {
                        name: '地基施工装备',
                        children: [
                          { name: '履带式强夯机' },
                          { name: '压密注浆机' },
                          { name: '挖掘机' },
                          { name: '推土机' },
                          { name: '振动压路机' },
                        ],
                      },
                    ],
                  },
                  {
                    name: '桩基础施工',
                    children: [
                      {
                        name: '装配式基础施工装备',
                        children: [{ name: '液压式压桩机' }, { name: '轮胎式起重机' }],
                      },
                      {
                        name: '现浇式基础施工装备',
                        children: [{ name: '旋挖钻机' }, { name: '混凝土泵车' }],
                      },
                    ],
                  },
                  {
                    name: '建筑物施工',
                    children: [
                      {
                        name: '装配式建筑物施工装备',
                        children: [
                          { name: '轮胎式起重机' },
                          { name: '剪叉式升降平台' },
                          { name: '混凝土摊铺机' },
                          { name: '地坪涂敷机器人' },
                        ],
                      },
                      {
                        name: '现浇式建筑物施工装备',
                        children: [{ name: '塔式起重机' }],
                      },
                    ],
                  },
                  {
                    name: '构筑物施工',
                    children: [
                      {
                        name: '装配式构筑物施工装备',
                        children: [{ name: '预制围墙运输安装一体车' }, { name: '汽车起重机' }, { name: '曲臂升降车' }],
                      },
                      {
                        name: '现浇式构筑物施工装备',
                        children: [{ name: '混凝土搅拌运输车' }, { name: '混凝土泵车' }],
                      },
                    ],
                  },
                  {
                    name: '构支架施工',
                    children: [
                      {
                        name: '构支架施工装备',
                        children: [{ name: '汽车起重机' }, { name: '升降工作平台' }],
                      },
                    ],
                  },
                ],
              },
              {
                name: '电气安装',
                expand: true,
                children: [
                  {
                    name: '一次设备施工',
                    children: [
                      {
                        name: '气体绝缘类设备安装装备',
                        children: [
                          { name: 'GIS运输就位装置' },
                          { name: 'GIS无尘化安装系统' },
                          { name: 'GIS气露监测装置' },
                          { name: 'GIS气室内检机器人' },
                        ],
                      },
                      {
                        name: '油绝缘类设备安装装备',
                        children: [
                          { name: '变电站油气处理集中控制系统' },
                          { name: '主设备安装智能感知装置' },
                          { name: '低电流短路法加热装置' },
                        ],
                      },
                    ],
                  },
                  {
                    name: '二次设备施工',
                    children: [
                      {
                        name: '屏柜安装装备',
                        children: [{ name: '屏柜搬运机' }],
                      },
                      {
                        name: '二次电缆安装装备',
                        children: [
                          { name: '电缆支架安装机器人' },
                          { name: '二次线缆双端协作机器人' },
                          { name: '二次电缆自动敷设机器人' },
                        ],
                      },
                    ],
                  },
                  {
                    name: '试验调试',
                    children: [
                      {
                        name: '变压器电气试验装置',
                        children: [{ name: '变压器一体化检测装置' }],
                      },
                      {
                        name: '耐压试验装置',
                        children: [{ name: 'GIS耐压试验平台' }, { name: 'GIS同频同相耐压试验装置' }],
                      },
                      {
                        name: '局放试验装置',
                        children: [{ name: '变压器局放试验平台' }, { name: '数模一体继保测试仪' }],
                      },
                      {
                        name: '继保调试(通用)装置',
                        children: [{ name: '监控信息一体化自动验收装置' }, { name: '三相通流压综合测试仪' }],
                      },
                      {
                        name: '继保调试(智能站)装置',
                        children: [{ name: '继电保护定值校核仪' }, { name: '数字量继保测试仪' }],
                      },
                      {
                        name: '光缆调试装置',
                        children: [{ name: '光纤测试仪' }],
                      },
                    ],
                  },
                ],
              },
            ],
          },
          {
            name: '电缆（海缆）工程',
            expand: true,
            children: [
              {
                name: '电缆土建施工',
                expand: true,
                children: [
                  {
                    name: '基坑（槽）施工',
                    children: [
                      {
                        name: '直埋装备',
                        children: [{ name: '开/挖槽机' }],
                      },
                      {
                        name: '排管、电缆沟装备',
                        children: [{ name: '反铲挖掘机' }, { name: '装载机' }, { name: '钢板压拔桩机' }],
                      },
                      {
                        name: '明挖隧道装备',
                        children: [
                          { name: '伸缩臂挖掘机' },
                          { name: '锚杆钻机' },
                          { name: '混凝土喷射机' },
                          { name: 'U型盾构' },
                        ],
                      },
                      {
                        name: '暗挖/顶管/盾构工井装备',
                        children: [{ name: '门式起重机' }, { name: '成槽机' }, { name: '铣槽机' }],
                      },
                    ],
                  },
                  {
                    name: '通道掘进施工',
                    children: [
                      {
                        name: '浅埋暗挖隧道装备',
                        children: [
                          { name: '悬臂式隧道掘进机' },
                          { name: '注浆机' },
                          { name: '锚杆台车' },
                          { name: '水磨取芯掘进机' },
                        ],
                      },
                      {
                        name: '钻爆法隧道装备',
                        children: [{ name: '凿岩台车' }],
                      },
                      {
                        name: '顶管隧道装备',
                        children: [
                          { name: '圆形泥水/土压/气压顶管机' },
                          { name: '岩石顶管机' },
                          { name: '微型顶管机' },
                          { name: '矩形/马蹄形顶管机' },
                          { name: '顶盾机' },
                          { name: '中继间' },
                        ],
                      },
                      {
                        name: '盾构隧道装备',
                        children: [{ name: '盾构机' }, { name: '隧道掘进机(TBM)' }],
                      },
                      {
                        name: '定向钻管道装备',
                        children: [{ name: '水平定向钻机' }],
                      },
                    ],
                  },
                  {
                    name: '通道结构施工',
                    children: [
                      {
                        name: '明挖隧道/管廊结构装备',
                        children: [{ name: '铝合金滑动模板' }],
                      },
                      {
                        name: '暗挖隧道结构装备',
                        children: [{ name: '二衬台车' }],
                      },
                      {
                        name: '隧道隔板装备',
                        children: [{ name: '预制隔板拼装机' }],
                      },
                      {
                        name: '支架装备',
                        children: [{ name: '支架安装机器人' }],
                      },
                    ],
                  },
                  {
                    name: '通道结构检测',
                    children: [
                      {
                        name: '超前探测装置',
                        children: [{ name: '水平定向钻机' }, { name: '地质钻机' }],
                      },
                      {
                        name: '结构检测装置',
                        children: [{ name: '隧道检测机器人' }, { name: '管道检测机器人' }, { name: '测绘机器人' }],
                      },
                      {
                        name: '智能化监测装置',
                        children: [{ name: '电缆隧道巡检机器人' }],
                      },
                    ],
                  },
                ],
              },
              {
                name: '电缆GIL敷设',
                expand: true,
                children: [
                  {
                    name: '电缆/GIL运输',
                    children: [
                      {
                        name: '管廊/隧道装备',
                        children: [{ name: 'GIL运输车' }, { name: '电缆牵引机' }, { name: '输送机' }],
                      },
                    ],
                  },
                  {
                    name: '电缆/GIL安装',
                    children: [
                      {
                        name: '隧道装备',
                        children: [
                          { name: 'GIL安装装置' },
                          { name: '电缆敷设成套装备' },
                          { name: '电缆上架装置' },
                          { name: '电缆加热保温车' },
                        ],
                      },
                      {
                        name: '工井排管装备',
                        children: [{ name: '电缆输送机' }],
                      },
                    ],
                  },
                  {
                    name: '电缆附件安装',
                    children: [
                      {
                        name: '隧道装备',
                        children: [{ name: '高压电缆预处理装置' }, { name: '电缆接头缠包机器人' }],
                      },
                    ],
                  },
                  {
                    name: '电缆试验',
                    children: [
                      {
                        name: '耐压试验装置',
                        children: [{ name: '高压电缆GIS终端试验套筒' }, { name: '变频谐振耐压设备' }],
                      },
                      {
                        name: '局放试验装置',
                        children: [{ name: '同步分布式局部放电检测设备' }],
                      },
                      {
                        name: '电缆线路参数测试装置',
                        children: [{ name: '电缆线路参数测试仪' }],
                      },
                    ],
                  },
                ],
              },
              {
                name: '海缆施工',
                expand: true,
                children: [
                  {
                    name: '海缆敷设',
                    children: [
                      {
                        name: '路由勘测装备',
                        children: [{ name: '路由勘测船' }, { name: '路由无人勘测船' }],
                      },
                      {
                        name: '海缆退扭装备',
                        children: [{ name: '电缆电动转盘' }],
                      },
                      {
                        name: '敷设施工装备',
                        children: [
                          { name: '布缆机' },
                          { name: '海缆敷设船' },
                          { name: '埋设犁' },
                          { name: '埋设犁牵引机' },
                          { name: '门型吊架' },
                          { name: '甲板储缆装置' },
                        ],
                      },
                      {
                        name: '辅助施工装备',
                        children: [
                          { name: '施工拖带船' },
                          { name: '施工抛/起锚船' },
                          { name: '施工警戒船' },
                          { name: '水下机器人' },
                        ],
                      },
                    ],
                  },
                ],
              },
            ],
          },
        ],
      },
    }
  },
  mounted() {
    this.expandAll(this.treeData)
    this.treeReady = true
  },
  methods: {
    renderContent(h, data) {
      return h('div', { class: 'custom-node' }, data.name)
    },
    expandAll(node) {
      console.log('🚀 ~ node:', node)
      if (!node) return

      // 确保是响应式的
      this.$set(node, 'expand', true)

      if (node.children && node.children.length) {
        node.children.forEach((child) => {
          this.expandAll(child)
        })
      }
    },
  },
}
</script>

<style scoped>
.mindmap-wrapper {
  width: 100%;
  height: 90vh;
  overflow: auto;
  background: #f7f9fc;
  padding: 20px;
  display: flex;
  justify-content: center;
}

/* 节点卡片样式 */
.custom-node {
  padding: 8px 14px;
  border-radius: 6px;
  background: #ffffff;
  border: 1px solid #dcdfe6;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  font-size: 16px;
  color: #303133;
  white-space: nowrap;
}

/* 根节点突出显示 */
::v-deep .vue-org-tree > .org-tree-node > .org-tree-node-label .custom-node {
  background: #144f99;
  color: #fff;
  border-color: #409eff;
  font-weight: bold;
}

/* 连线颜色 */
.org-tree-node:before,
.org-tree-node:after {
  border-color: #c0c4cc !important;
}

.org-tree-node-children {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.org-tree-node {
  margin-right: 60px;
}
</style>
