<template>
  <el-cascader
    v-model="selectVal"
    :options="AccList"
    :props="AccListProps"
    @change="handleItemChange">
  </el-cascader>

</template>

<script>

  export default {
    name: 'demo',
    data () {
      return {
        selectVal:[],
        AccList:[],
        AccListProps: {
          value:'ID',
          label:'Name',
          children: 'children'
        },
        getAccListMsg:{
          Id:2,
        },
      }
    },
    methods: {
      handleItemChange(obj){
        let obj1 = this.AccList[obj[0]],
          obj2 = this.AccList[obj[0]].children[obj[1]],
          obj3 = this.AccList[obj[0]].children[obj[1]].children[obj[2]];
        let addMsgList = {
          ID:0,
          AccountId:obj3.ID,
          Type:obj2.ID,
          AccountType:obj1.ID,
          Direct:0,
          Name:obj3.Name + (obj3.BankNo?obj3.BankNo:''),
          IsPublic:obj1.IsPublic,
          isInCheckbox:obj3.Is_Income?true:false,
          isOutCheckbox:obj3.Is_Outcome?true:false,
          allName:obj3.Name + (obj3.BankNo?obj3.BankNo:''),
        }
        this.addMsg.list.push(addMsgList);
        this.selectVal = [];
      },
      getAccList(){
          this.apipost("/api/Destination/GetChildList",this.getAccListMsg , res => {

            if(res.data.resultCode==1){
            function addNum (obj) {

              for (let i = 0; i < obj.length; i++) {
                obj[i]['ID'] = i;
                console.log(obj[i])
                if (obj[i].hasOwnProperty('children')){
                  obj[i].children = addNum(obj[i].children)
                }
              }


              return obj
            }
            this.AccList = addNum(res.data.data)
          }else{

          }
        },null)
      },
    },
    mounted () {
      this.getAccList();

    },
  }

</script>
