

<template>
  <n-card>
    <n-card style="margin: 12px 0px">
      <n-grid :cols="2" style="margin: 10px">
        <n-gi>
          <span class="pgClass">物料名称：</span>
          <span>{{props.baseInfo.materialName}}</span>
        </n-gi>
        <n-gi>
          <span class="pgClass">物料编号：</span>
          <span>{{props.baseInfo.materialCode}}</span>
        </n-gi>
      </n-grid>
      <n-grid :cols="2" style="margin: 10px">
        <n-gi>
          <span class="pgClass">工序名称：</span>
          <span>{{props.baseInfo.processName}}</span>
        </n-gi>
        <n-gi>
          <span class="pgClass">派工编号：</span>
          <span>{{props.baseInfo.assingCode}}</span>
        </n-gi>
      </n-grid>
    </n-card>
    <n-data-table
        :columns="reportRecordsColums"
        size="small"
        :data="submitLogList"
        remote
        :scroll-x="600"
    />

  </n-card>
</template>
<script setup lang="ts">
import { NCard, NDataTable, NGi,NTag, NGrid,DataTableColumns} from "naive-ui";
import {onMounted, ref,h} from "vue";
import { dictDataApi } from '@/api/org'
import { SubmitLog,submitLogApi} from '@/api/submitLog'

const props =defineProps(
    {
      assingId:Number,
      baseInfo:Object
    }
)

//汇报状态字典
const submitStatusOptions = ref<{ label: string; value: any ;class:any}[]>([])


//汇报信息表格
const reportRecordsColums:DataTableColumns<SubmitLog> = [

  { title: '汇报数量', key: 'quantity',align: 'center'},
  { title: '汇报人', key: 'userName',align: 'center' },
  { title: '派工状态', key: 'submitStatus',align: 'center',
    render: (row) => {
      const val = row.submitStatus
      const opt = submitStatusOptions.value.find(o => o.value === val || String(o.value) === String(val))
      if (!opt) return val ?? '-'

      return h(NTag, { type: opt.class, size: 'small' }, { default: () => opt.label })
    }
  },
  { title: '汇报时间', key: 'createTime',align: 'center' },
]

// 加载字典选项
async function loadDictOptions() {
  try {
    const data = await dictDataApi.listByType('submit_status')
    submitStatusOptions.value = data.map(d => ({ label: d.dictLabel, value: (Number(d.dictValue) || d.dictValue),class:d.listClass }))
  }catch {}
}

//加载汇报信息
const submitLogList = ref<SubmitLog[]>([])
async function load() {
  const res = await submitLogApi.loadSumbitLog(props.assingId)
  submitLogList.value = res
}

onMounted(()=>{
  loadDictOptions()
  load()
})
</script>
<style scoped>

</style>