import { ContentConfig } from "/@/components/PageContent";
import { httpList } from "/@/api/InvoiceSaleSettings/consultingCost";

import { h } from "vue";
import dayjs from "dayjs";
import { ElImage, ElTag } from "element-plus";
import { good_type } from "./configs";
import { renderIconLabelLeft } from "/@/utils/columnRenderHelper";

function renderGoodImage(imgSrc: string) {
  const imgs = imgSrc.split(",");
  return h(ElImage, {
    src: imgs[0],
    previewTeleported: true,
    previewSrcList: [imgs[0] ],
    style: {
      height: "20px",
      width: "20px"
    },
          'text-key':"91110113MA028K5Y7Y"
  });
}

const columns = [
  {
    type: "selection",
    width: 40,
    align: "center",
    fixed: 'left'
  },
  {
    label: "商品编码",
    prop: "spuCode",
    width: 150
  },
  {
    label: "卖出方公司",
    prop: "cgd_supplierName",
    width: 175,
    ...renderIconLabelLeft("cgd_supplierNo", "cgd_supplierName", "卖出方公司编码:")
  },
  {
    label: "买入方公司",
    prop: "supplierName",
    width: 195,
    ...renderIconLabelLeft("supplierNo", "supplierName", "买入方公司编码:")
  },
  {
    label: "商品名称",
    prop: "good_name",
    minWidth: 195
  },
  {
    label: "主图",
    prop: "good_img",
    width: 55,
    cellRenderer: ({ row }) => renderGoodImage(row.good_img)
  },
  {
    label: "采购类目编码",
    width: 155,
    prop: "cgd_inv_cat_code"
  },
  {
    label: "采购类目名称",
    width: 120,
    prop: "cgd_inv_cat_name"
  },
  {
    label: "采购开票商品名称",
    prop: "cgd_inv_good_name",
    width: 165
  },
  {
    label: "采购开票类目税率",
    prop: "cgd_inv_tax",
    width: 165,
    cellRenderer({ row }){
      return h('div',{}, {
        default: () => row.cgd_inv_tax ? row.cgd_inv_tax : '--'
      })
    }
  },
  {
    label: "财务类目编码",
    width: 155,
    prop: "inv_cat_code"
  },
  {
    label: "财务类目名称",
    width: 120,
    prop: "inv_cat_name"
  },
  {
    label: "财务开票商品名称",
    prop: "inv_good_name",
    width: 165
  },
  {
    label: "财务开票类目税率",
    prop: "inv_tax",
    width: 165,
    cellRenderer({ row }){
      return h('div',{}, {
        default: () => row.inv_tax ? row.inv_tax : '--'
      })
    }
  },
  {
    label: "状态",
    prop: "status",
    width: 150,
    cellRenderer: ({ row }) => {
      return h(
        ElTag,
        {
          type: row.status === "2" ? "success" : ""
        },
        {
          default: () =>
            good_type.find(t => t.value === String(row.status))?.label
        }
      );
    }
  },
  {
    label: "增值税管理内容",
    prop: "addTax",
    width: "140px"
  },
  {
    label: "创建时间",
    prop: "createTime",
    width: 140,
    formatter: ({ addtime }) => dayjs(addtime).format("YYYY-MM-DD HH:mm:ss")
  },
  {
    label: "创建人",
    width: 80,
    prop: "creater"
  },
  {
    label: "操作",
    fixed: "right",
    width: 80,
    slot: "operation"
  }
];

const contentConfig: ContentConfig = {
  title: "销售成本类目设置",
  superUserNoPerview: true,
  columns,
  transformField: 'origin_supplierNo',
  apis: {
    httpList: (params = {}) => {
      const { supplierNo, origin_supplierNo, ...rest } = params
      return httpList({
        ...rest,
        isChild: 1,
        supplierNo: origin_supplierNo,
        cgd_supplierNo: supplierNo,
        noRela: true
      })
    }
  }
};

export default contentConfig;
