<template>
  <a-row :gutter="10">
<!--    <a-col :md="5" :sm="24">-->
<!--      <a-card :bordered="false" style="height: 85vh">-->
<!--        &lt;!&ndash; 按钮操作区域 &ndash;&gt;-->
<!--        <div style="background: #fff;height: 100%; margin-top: 5px">-->
<!--          <a-alert type="info" :showIcon="true">-->
<!--            <div slot="message">-->
<!--              当前选择：<span v-if="this.currSelected.title">{{ getCurrSelectedTitle() }}</span>-->
<!--            </div>-->
<!--          </a-alert>-->
<!--          <div class="tree-container">-->
<!--            <a-col :md="24" :sm="24">-->
<!--              <a-tree-->
<!--                @select="handleSelectChange"-->
<!--                :treeData="this.treeData"-->
<!--                :expandedKeys="iExpandedKeys"-->
<!--                :autoExpandParent="autoExpandParent"-->
<!--                @expand="onExpand"-->
<!--              />-->
<!--            </a-col>-->
<!--          </div>-->
<!--        </div>-->
<!--      </a-card>-->
<!--    </a-col>-->
    <a-col :md="24" :sm="24">
    <BuRiskItemValueList :deviceId="this.deviceId"/>
    </a-col>
  </a-row>
</template>

<script>
import {mixinDevice} from "@/utils/mixin";
import BuRiskItemValueList from "@views/device/BuRiskItemValueList";
import JDictSelectTag from "@comp/dict/JDictSelectTag";
import {getAction} from "@api/manage";

export default {
  name: "BuRiskManagement",
  mixins:[mixinDevice],
  components: {
    BuRiskItemValueList,
    JDictSelectTag
  },
  data () {
    return {
      description: 'HistoryDataList',
      url: {
        treeTest: "/device/buDevice/treeTest",
      },
      treeData:[],
      expandedKeys:[],
      childrenList:[],
      deviceId:'',//1384437889241600001 1#单节落车01
      deviceName:'',
      defaultExpandedKeys:[],
      currSelected: {},
      iExpandedKeys: [],
      loading: false,
      autoExpandParent: true,

    }
  },
  created(){
    this.treeTest()
  },
  methods:{
    treeTest(){
      getAction(this.url.treeTest).then((res) => {
        if (res) {
          res.forEach(type=>{
            this.childrenList = []
            if(type.children.length>0){
              type.children.forEach(device=>{
                this.childrenList.push({title:device.deviceName+device.deviceCode,key:device.id,value: device.id,typeId:device.deviceTypeId})
              })
            }else{
              this.childrenList.push({})
            }
            this.treeData.push({title:type.typeName,key:type.id,value: type.id,children:this.childrenList,selectable:false,})
            this.iExpandedKeys.push(type.id)
          })
        }else{
        }
      })
    },
    onExpand(expandedKeys) {
      this.iExpandedKeys = expandedKeys
      this.autoExpandParent = false
    },
    getCurrSelectedTitle() {
      if(this.deviceId!==''){
        return !this.currSelected.title ? '' : this.currSelected.title
      }else{
        return this.currSelected.title = ''
      }
    },
    handleSelectChange(selectedKeys, event) {
      this.currSelected = Object.assign({}, event.node.dataRef)
      this.deviceName = event.node.dataRef.title;
      if(selectedKeys.length>0){
        this.deviceId = selectedKeys[0]
      }else {
        this.deviceId = '';
      }
      // this.deviceId = event.node.dataRef.key;
    },

  }
}
</script>

<style scoped>
.tree-container {
  height: 75vh; /* 根据需要设置具体高度 */
  overflow-y: auto; /* 垂直滚动条 */
  overflow-x: hidden; /* 隐藏水平滚动条 */
}
</style>