<template>
  <div class="pig-batch-logs-view">
    <GenericMonitorList
      :fetchData="fetchPigBatchLogs"
      :columnsConfig="pigBatchLogColumns"
    />
  </div>
</template>

<script setup>
import GenericMonitorList from '../../components/GenericMonitorList.vue';
import { getPigBatchLogs } from '../../api/monitor.js';
import { formatRFC3339 } from '../../utils/format.js';

// 适配通用组件的 fetchData prop
const fetchPigBatchLogs = async (params) => {
  return await getPigBatchLogs(params);
};

// 定义表格的列，依据 swagger.json
const pigBatchLogColumns = [
  {
    title: '记录ID',
    dataIndex: 'id',
    key: 'id',
    sorter: true,
    minWidth: 100,
  },
  {
    title: '猪批次ID',
    dataIndex: 'pig_batch_id',
    key: 'pig_batch_id',
    filterType: 'number',
    sorter: true,
    minWidth: 120,
  },
  {
    title: '变更类型',
    dataIndex: 'change_type',
    key: 'change_type',
    filterType: 'select',
    filterOptions: [
      { text: '死亡', value: '死亡' },
      { text: '淘汰', value: '淘汰' },
      { text: '销售', value: '销售' },
      { text: '购买', value: '购买' },
      { text: '转入', value: '转入' },
      { text: '转出', value: '转出' },
      { text: '盘点校正', value: '盘点校正' },
    ],
    minWidth: 120,
  },
  {
    title: '变更数量',
    dataIndex: 'change_count',
    key: 'change_count',
    sorter: true,
    minWidth: 120,
  },
  {
    title: '变更前数量',
    dataIndex: 'before_count',
    key: 'before_count',
    minWidth: 120,
  },
  {
    title: '变更后数量',
    dataIndex: 'after_count',
    key: 'after_count',
    minWidth: 120,
  },
  {
    title: '发生时间',
    dataIndex: 'happened_at',
    key: 'happened_at',
    sorter: true,
    filterType: 'dateRange',
    formatter: (row, column, cellValue) => formatRFC3339(cellValue),
    minWidth: 180,
  },
  {
    title: '操作员ID',
    dataIndex: 'operator_id',
    key: 'operator_id',
    filterType: 'number',
    minWidth: 120,
  },
  {
    title: '原因',
    dataIndex: 'reason',
    key: 'reason',
    minWidth: 200,
  },
];
</script>

<style scoped>
/* 视图容器样式 */
</style>
