import { ContentConfig } from "/@/components/PageContent";
import { httpList } from "/@/api/InvoiceSales/redInk";
import { h } from "vue";
import dayjs from "dayjs";
import { ElTag } from "element-plus";
import { invoiceTypeList, inv_type_list } from "/@/utils/status";

const RED_STATUS = [
  {
    value: "0",
    label: "待提交申请"
  },
  {
    value: "1",
    label: "申请中"
  },
  {
    value: "2",
    label: "待开红冲"
  },
  {
    value: "3",
    label: "红冲开票提交"
  },
  {
    value: "4",
    label: "开票成功"
  },
  {
    value: "5",
    label: "提交申请失败"
  },
  {
    value: "6",
    label: "申请成功开票失败"
  },
  {
    value: "7",
    label: "取消申请"
  }
];

const columns = [
  {
    type: "selection",
    width: 40,
    align: "center",
    hide: ({ checkList }) => !checkList.includes("勾选列")
  },
  {
    label: "序号",
    type: "index",
    width: 70,
    hide: ({ checkList }) => !checkList.includes("序号列")
  },
  {
    label: "红冲申请编码",
    width: 150,
    prop: "invRed"
  },
  {
    label: "红冲申请流水号",
    width: 150,
    prop: "SQBSCQQLSH"
  },
  {
    label: "红冲申请批次号",
    width: 150,
    prop: "SQBSCQQPCH"
  },
  {
    label: "发票类型",
    width: 160,
    prop: "FPLXDM",
    cellRenderer({ row }) { 
      return h(ElTag, null, {
        default: () => invoiceTypeList.find(({ scanValue }) => { 
          // console.log( scanValue, row['FPLXDM'])
          return "0" + scanValue === row['FPLXDM']
        }).label || '--'
      })
    }
  },
  {
    label: "原发票申请编码",
    width: 150,
    prop: "invNo"
  },
  {
    label: "原发票号码",
    width: 130,
    prop: "YFPHM"
  },
  {
    label: "状态",
    prop: "status",
    cellRenderer({ row }) {
      return h(ElTag, null, {
        default: () =>
          RED_STATUS.find(s => s.value === row.status)?.label || "--"
      });
    }
  },
  {
    label: "创建时间",
    prop: "addtime",
    formatter: ({ addtime }) => dayjs(addtime).format("YYYY-MM-DD HH:mm:ss")
  }
  // {
  //   label: "操作",
  //   fixed: "right",
  //   width: 60,
  //   slot: "operation"
  // }
];

const contentConfig: ContentConfig = {
  title: "红字专票信息表",
  columns,
  inv: true,
  superUserNoAction: true,
  notPreview: true,
  // showPreview: ({ status }) => status === "2",
  apis: {
    httpList
  }
};

export default contentConfig;
