

<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="props.qualityTestingList"
        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 {QualityTesting} from "@/api/qualityTesting.ts";

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

//业务来源字典
const qcSourceTypeOptions =  ref<{ label: string; value: any;class:any }[]>([])
const qcStatusOptions =  ref<{ label: string; value: any;class:any }[]>([])

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

  { title: '质检编号', key: 'qcNo',align: 'center' },
  { title: '来源类型', key: 'sourceType',align: 'center',
    render(row) {
      const val = row.sourceType
      const opt = qcSourceTypeOptions.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: 'totalQty',align: 'center' },
  { title: '已检验数量', key: 'inspectQty',align: 'center' },
  { title: '质检状态', key: 'status',align: 'center',
    render(row) {
      const val = row.status
      const opt = qcStatusOptions.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: 'inspectTime',align: 'center' },
]

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



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

</style>