import {
  VuexModule,
  Module,
  getModule,
  Mutation,
  Action
} from "vuex-module-decorators";
import store from "../index";
import { getMenu } from "@/api/menu";
@Module({ dynamic: true, store, name: "menu" })
class Menu extends VuexModule {
  private list = getMenu();
  @Mutation
  public setList(list: IMenu[]) {
    this.list = list;
  }
  get pList() {
    return this.list.filter(({ pId }) => !pId);
  }

  get subList() {
    return (pid: number) => this.list.filter(({ pId }) => pId === pid);
  }

  get info() {
    return (id: number) => this.list.find(x => x.id === id);
  }
}
export default getModule(Menu);
