<template>
    <div>
        <el-table ref="multipleTable" :data="dataList" tooltip-effect="dark" height="450" style="width: 100%"
        @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55">
            </el-table-column>
            <el-table-column label="ID">
                <template slot-scope="scope">{{ scope.row.id }}</template>
            </el-table-column>
            <el-table-column prop="name" label="名称">
                <template slot-scope="scope">{{ scope.row.name }}</template>
            </el-table-column>
        </el-table>
    </div>
</template>
<script>
  export default {
    data() {
      return {
        dataList: [],
        msg:{
          Id:0,
          Name:'',
          Tier:0,
          ParentId:0,
          Enabled:1,
          IsShow:1,          
        },
        selectRow:[],
      };
    },
    created() {},
    methods: {
      //获取所有菜单
      getList() {
        this.apipost("/api/product/GetProductCategoryTreeList", this.msg, res => {
          if (res.data.resultCode == 1) {
            var dataArray = res.data.data;
            this.dataList=[];
            if (dataArray && dataArray.length > 0) {
              dataArray.forEach(x => {
                 this.dataList.push({
                    id: x.Id,
                    name: x.Name,
                    menuName: x.Name,
                    goodsNum: 3,
                    staticGoods: false,
                    goodsList: [],
                 })
                 if(x.ChildList&&x.ChildList.length>0){
                    x.ChildList.forEach(y=>{
                        this.dataList.push({
                            id: y.Id,
                            name: y.Name,
                            menuName: y.Name,
                            goodsNum: 3,
                            staticGoods: false,
                            goodsList: [],
                        })
                        if(y.ChildList&&y.ChildList.length>0){
                            y.ChildList.forEach(z=>{
                                this.dataList.push({
                                    id: z.Id,
                                    name: z.Name,
                                    menuName: z.Name,
                                    goodsNum: 3,
                                    staticGoods: false,
                                    goodsList: [],
                                })
                            })
                        }
                    })
                 }
              });
            }
          } else {
            this.Info(res.data.message);
          }
        })
      },
      handleSelectionChange(val){
        this.selectRow=JSON.parse(JSON.stringify(val));
      },
      //父组件调用方法
      getChoicedFenlei(){
        return this.selectRow;
      },
      //清空多选方法
      toggleSelection(rows) {
        if (rows) {
          rows.forEach(row => {
            this.$refs.multipleTable.toggleRowSelection(row);
          });
        } else {
          this.$refs.multipleTable.clearSelection();
        }
      },  
    },
    mounted() {
      this.getList();
    }
  };

</script>
