<script lang="ts" setup name="sourceApprove">
// 溯源供方审批列表
import ListApproval from './components/listApproval.vue' // 全部
import type { IButton } from './list_interface'
import useDictStore from '@/store/modules/dict'
import { getQueryPriceInfo } from '@/api/system/price'
const dictStore = useDictStore()
interface MenuType {
  name: string
  value: any
}
const menus = ref<MenuType[]>([
  { name: '全部', value: '0' },
  { name: '草稿箱', value: '1' },
  { name: '待审批', value: '2' },
  { name: '审批中', value: '3' },
  { name: '已通过', value: '4' },
  { name: '未通过', value: '5' },
  { name: '已取消', value: '6' },
])

const buttonsSet: { [key: string]: IButton[] } = {
  全部: [{ name: '查看', type: 'primary' },
    { name: '同意', type: 'primary' },
    { name: '驳回', type: 'primary' },
    { name: '拒绝', type: 'danger' },
    { name: '取消', type: 'info' },
    { name: '删除', type: 'danger' },
  ],
  草稿箱: [
    { name: '查看', type: 'primary' },
    { name: '编辑', type: 'primary' },
    { name: '提交', type: 'primary' },
    { name: '删除', type: 'danger' },
  ],
  待审批: [
    { name: '查看', type: 'primary' },
    { name: '同意', type: 'primary' },
    { name: '驳回', type: 'primary' },
    { name: '拒绝', type: 'danger' },
    { name: '删除', type: 'danger' },
  ],
  审批中: [
    { name: '查看', type: 'primary' },
  ],
  已通过: [
    { name: '查看', type: 'primary' },
    { name: '删除', type: 'danger' },
  ],
  未通过: [
    { name: '查看', type: 'primary' },
    { name: '删除', type: 'danger' },
  ],
  已取消: [
    { name: '查看', type: 'primary' },
    { name: '删除', type: 'danger' },
  ],

}
// 当前tab
const currentTab = ref('全部')
// 当前审批状态
const currentApprovalStatus = ref('0')
// 当前需要显示的按钮列表
const currentButtons = ref<IButton[]>([])
currentButtons.value = buttonsSet['全部']
// 审批类型字典
const approvalStatusList = dictStore.getApprovalStatus

const $route = useRoute()
if ($route.query && $route.query.type) {
  const currentMenu = menus.value.find(item => item.value == $route.query.type)
  if (currentMenu) {
    currentTab.value = currentMenu?.name
  }
}
watch(currentTab, (newValue) => {
  currentApprovalStatus.value = approvalStatusList[newValue]
  currentButtons.value = buttonsSet[newValue]
}, { deep: true, immediate: true })
</script>

<template>
  <div class="container">
    <div class="btns">
      <!-- 三级菜单-审批状态 -->
      <el-radio-group v-model="currentTab">
        <el-radio-button v-for="item of menus" :key="item.name" :label="item.name">
          {{ item.name }}
        </el-radio-button>
      </el-radio-group>
    </div>
    <!-- 展示区域 -->
    <list-approval :name="currentTab" :status="currentApprovalStatus" :buttons="currentButtons" />
  </div>
</template>

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

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

