<script lang="ts" setup>
/**
 * 平台「仓品审核」列表页
 * 审核弹窗一次提交：主数据 + 总仓同步 + 绑仓三费/入库
 */
import { Page, useVbenModal } from '@vben/common-ui';

import { Image, Tag } from 'ant-design-vue';

import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { TableAction } from '#/components/table-action';

import AuditModalDemo from './components/audit-modal.vue';
import { formOptions } from './config/search';
import { gridOptions } from './config/table';

defineOptions({ name: 'DeliveryWarehouseProductAudit' });

const [Grid, gridApi] = useVbenVxeGrid({
  formOptions,
  gridOptions,
});

const [AuditModal, auditModalApi] = useVbenModal({
  connectedComponent: AuditModalDemo,
});

/**
 * 打开审核弹窗（仅待审可点）
 */
function openAudit(row: Record<string, any>) {
  if (Number(row.audit_status) === 1) {
    return;
  }
  auditModalApi.setData({
    id: row.id,
    values: row,
    gridApi,
  });
  auditModalApi.open();
}

function auditTagColor(status: number) {
  return Number(status) === 1 ? 'green' : 'orange';
}
</script>

<template>
  <Page auto-content-height title="仓品审核">
    <AuditModal />
    <Grid>
      <template #toolbar-actions>
        <TableAction :actions="[]" :drop-down-actions="[]" />
      </template>
      <template #image="{ row }">
        <Image
          v-if="row.image"
          :src="row.image"
          :height="36"
          :width="36"
          :preview="true"
        />
        <span v-else>-</span>
      </template>
      <template #audit_status="{ row }">
        <Tag :color="auditTagColor(row.audit_status)">
          {{ row.audit_status_txt || '-' }}
        </Tag>
      </template>
      <template #status="{ row }">
        <Tag :color="row.status_color || 'default'">
          {{ row.status_txt || '-' }}
        </Tag>
      </template>
      <template #toolbar-tools></template>
      <template #action="{ row }">
        <TableAction
          :actions="[
            {
              label: '审核',
              type: 'link',
              icon: 'mdi:clipboard-check-outline',
              size: 'small',
              ifShow: Number(row.audit_status) !== 1,
              onClick: openAudit.bind(null, row),
            },
          ]"
          :drop-down-actions="[]"
        />
      </template>
    </Grid>
  </Page>
</template>
