<!-- 提前/延迟送检申请 -->
<script lang="ts" setup>
import infoList from './list.vue'
import { getDictByCode } from '@/api/system/dict'
const $props = defineProps({
  // 申请类型（字典值，提前/延迟）
  approvalType: {
    type: String,
    required: true,
  },
})
export interface menuType {
  name: string
  comp: any
}
const menu = ref<any[]>([
  { name: '全部', com: infoList, status: '0' },
  { name: '已审批', com: infoList, status: '0' },
  { name: '待审批', com: infoList, status: '1' },
  { name: '审批', com: infoList, status: '2' },
  { name: '草稿箱', com: infoList, status: '0' },
  { name: '审批中', com: infoList, status: '0' },
  { name: '已通过', com: infoList, status: '3' },
  { name: '未通过', com: infoList, status: '4' },
  { name: '已取消', com: infoList, status: '4' },
])
const current = ref('')
const com = shallowRef(infoList)
const currentApprovalStatus = ref('0')
const approvalStatusMap = ref({}) as any
const approvalStatusReserveMap = ref({}) as any
// 获取菜单状态
const getMenuStatus = () => {
  getDictByCode('approvalStatus').then((res) => {
    // 审批状态字典 {1：草稿箱}
    res.data.forEach((item: any) => {
      approvalStatusMap.value[`${item.value}`] = item.name
    })
    // 审批状态字典 {草稿箱: 1}
    res.data.forEach((item: any) => {
      approvalStatusReserveMap.value[item.name] = `${item.value}`
    })
    // console.log(approvalStatusReserveMap.value)
  })
}

watch(current, (newValue) => {
  window.sessionStorage.setItem(`application-${$props.approvalType}`, newValue)
  com.value = menu.value.filter(item => item.name === newValue)[0].com
})

onMounted(async () => {
  await getMenuStatus()
  current.value = ''
  current.value = window.sessionStorage.getItem(`application-${$props.approvalType}`) || '全部'
  com.value = menu.value.filter(item => item.name === current.value)[0].com
})
</script>

<template>
  <div class="container">
    <div class="btns">
      <!-- 三级菜单 -->
      <el-radio-group v-model="current">
        <el-radio-button v-for="item in menu" :key="item.name" :label="item.name">
          {{ item.name }}
        </el-radio-button>
      </el-radio-group>
    </div>
    <!-- 展示区域 -->
    <component :is="com" :status-name="current" :approval-type="approvalType" />
  </div>
</template>

<style lang="scss" scoped>
.container {
  position: relative;

  .btns {
    position: fixed;
    top: 68px;
    right: 15px;
    z-index: 999;
  }
}
</style>

