<template>
  <div style="padding:20px;">
    <list-item v-for="item in list" :key="item" :item="item" />
  </div>
</template>
<script>
import ListItem from './components/ListItem.vue';
import { activityList } from '@/service/api/activityCenterApi.js';
export default {
  components: { ListItem },
  data() {
    return {
      list: []
    };
  },
  created() {
    this.$store.commit('mutations_breadcrumb', [{ name: '营销管理' }, { name: '微信营销', path: '/wechat' }, { name: '素材库', path: '' }]);
    this.$store.commit('aside_handler', false);
    this.$nextTick(_ => {
      this.$store.commit('aside_handler', true);
    });
  },
  mounted() {
    this.getLIst();
  },
  methods: {
    async getLIst() {
      const { result = [] } = await activityList({ orderBy: 'activity_sort ASC' });
      console.log(result);
      const map = {};
      result.forEach(el => {
        if (map[el.activityCategoryId]) {
          map[el.activityCategoryId].childs.push({ ...el });
        } else {
          map[el.activityCategoryId] = {
            activityCategoryId: el.activityCategoryId,
            categoryName: el.categoryName,
            childs: [{ ...el }]
          };
        }
      });
      this.list = Object.values(map);
    }
  }
};
</script>
