import { ContentConfig } from "/@/components/PageContent";
import { httpAbList } from "/@/api/InvoiceSaleSettings/commodityCost";

import { diffCatOptions, diffTaxOptions } from "./configs"

import dayjs from "dayjs";
import { ElTag } from "element-plus";
import { h } from "vue";

export const stock_type = [
  {
    value: "0",
    label: "非库存商品"
  },
  {
    value: "1",
    label: "库存商品"
  }
];


const columns = [
  {
    label: "商品编码",
    prop: "spuCode",
    width: 150
  },
  {
    label: "商品分类",
    prop: "cat_name",
    width: 150
  },
  {
    label: "商品名称",
    prop: "good_name",
    minWidth: 195
  },
  {
    label: "商品类型",
    prop: "isZx",
    width: 120,
    cellRenderer({ row }) {
      return Number(row.isZx) == 1 ? "反馈商品" : stock_type.find(({ value }) => value === String(row.is_stock))?.label || "--";
    },
  },
  {
    label: "采购商品类目",
    prop: "cgd_inv_cat_name",
    width: 120
  },
  {
    label: "采购商品名称",
    prop: "cgd_inv_good_name",
    width: 120
  },
  {
    label: "采购商品税率",
    prop: "cgd_inv_tax",
    width: 120
  },
  {
    label: "财务商品类目",
    prop: "inv_cat_name",
    width: 120
  },
  {
    label: "财务商品名称",
    prop: "inv_good_name",
    width: 120
  },
  {
    label: "财务商品税率",
    prop: "inv_tax",
    width: 120
  },
  {
    label: "类目是否一致",
    width: 100,
    cellRenderer({ row }) {
      return h(ElTag, {
        type: row.cat_diff === "1" ? "" : "warning"
      }, {
        default: () => diffCatOptions.find(({ value }) => value === row.cat_diff)?.label || "--"
      })
    }
  },
  {
    label: "税率是否一致",
    width: 100,
    cellRenderer({ row }) {
      return h(ElTag, {
        type: row.tax_diff === "1" ? "" : "warning"
      }, {
        default: () => diffTaxOptions.find(({ value }) => value === row.tax_diff)?.label || "--"
      })
    }
  },
  {
    label: "创建时间",
    prop: "createTime",
    width: 140,
    formatter: ({ addtime }) => dayjs(addtime).format("YYYY-MM-DD HH:mm:ss")
  }
];

const contentConfig: ContentConfig = {
  superUserNoPerview: true,
  columns,
  apis: {
    httpList: httpAbList
  }
};

export default contentConfig;
