<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>
    <el-pagination
      style="text-align: center"
      background
      @current-change="handleCurrentChange"
      :page-size="msg.pageSize"
      layout="prev, pager, next"
      :total="total"
    >
    </el-pagination>
  </div>
</template>
<script>
export default {
  data() {
    return {
      dataList: [],
      msg: {
        pageIndex: 1,
        pageSize: 20,
        Name: "",
        IsShow: 0,
      },
      selectRow: [],
      total: 0,
    };
  },
  created() {},
  methods: {
    //获取所有菜单
    getList() {
      this.apipost("/api/Miai/GetForumPageList", this.msg, (res) => {
        if (res.data.resultCode == 1) {
          this.total = res.data.data.count;
          var dataArray = res.data.data.pageData;
          console.log(42, dataArray);
          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();
      }
    },
    handleCurrentChange(val) {
      this.msg.pageIndex = val;
      this.getList();
    },
  },
  mounted() {
    this.getList();
  },
};
</script>
