<template>
  <section class="matters-config">
    <ai-list v-if="!showDetail">
      <template #title>
        <ai-title title="事项配置" :isShowBottomBorder="false"></ai-title>
      </template>
      <template slot="tabs">
        <el-tabs class="tabs-page" v-model="currIndex">
          <el-tab-pane v-for="(tab,i) in tabs" :key="i" :label="tab.label" :name="String(i)">
            <component :is="tab.comp" v-if="currIndex==i" :ref="currIndex" :instance="instance" :dict="dict"
                       :permissions="permissions" @goPage="goPage" :tab="currentTab"/>
          </el-tab-pane>
        </el-tabs>
      </template>
    </ai-list>
    <component v-else :is="currentComp" :instance="instance" :dict="dict" :processType="currentTab.value" :row="row" @back="back"/>
  </section>
</template>

<script>
import addConfig from './components/addConfig'
import configList from "./components/configList";
import guidance from "./components/guidance";

export default {
  name: "AppMattersConfig",
  label: '事项配置(秀山)',
  components: {addConfig, guidance},
  props: {
    instance: Function,
    dict: Object,
    permissions: Function
  },
  data() {
    return {
      currIndex: "0",
      row: {},
      currentComp: "",
    }
  },
  computed: {
    tabs() {
      return [
        {label: "网上办事", name: "configList", value: "0", comp: configList, detail: addConfig, permission: ""},
        // {label: "办事指南", name: "configList", value: "2", comp: configList, detail: guidance, permission: ""},
      ]
    },
    currentTab() {
      return this.tabs?.[this.currIndex] || {}
    },
    showDetail() {
      return !!this.$route.query?.id || !!this.$route.query?.processType
    }
  },
  methods: {
    goPage(params) {
      this.row = params.row
      this.currentComp = params.comp
      this.$router.push({query: {processType: this.currentTab.value}})
    },

    back() {
      this.$router.push({query: {}})
    }
  },
  created() {
    this.$router.push({query: {}});
    this.$dict.load("hbDepartment", 'sex', 'nation', 'marital', 'native_place', 'education', 'candidateApproverType', 'scopeCandidates', 'nodeType')
  }
}
</script>

<style lang="scss" scoped>
.matters-config {
  height: 100%;
  background: #f3f6f9;
  overflow: auto;

  .iconfont {
    user-select: none;
    cursor: pointer;
  }
}
</style>
