<template>
  <div>
    <CommonFilter
      ref="filter"
      action="getCategoryList"
      :actionOption="query[name]"
      :fixedValues="{ parent_id: query[name].parent_id }"
      @on-refresh="$emit('on-refresh')" />
    <CommonWrapper name="category-detail">
      <CommonDetail
        name="category-detail"
        :query="query"
        resetAction="getCategory"
        submitAction="editCategory"
        @on-save="onDetailSave" />
    </CommonWrapper>
  </div>
</template>

<script>
export default {
  name: 'category-list',
  props: {
    query: {
      type: Object,
      required: false,
      default () {
        return {}
      },
    },
    name: {
      type: String,
      required: false,
      default: 'category',
    },
  },
  methods: {
    init () {
      this.$refs.filter.request()
    },
    onDetailSave () {
      this.$stack.go()
      this.init()
    },
  },
}
</script>
