import { h } from "vue";
import { ElImage, ElTag } from "element-plus";
import { createTooltip } from "/@/utils/tootip";

import { verification, required } from "/@/utils/verification";

export const diffCatOptions = [
  { value: "0", label: "无" },
  { value: "1", label: "类目一致" },
  { value: "2", label: "类目不一致" }
];

export const diffTaxOptions = [
  { value: "0", label: "无" },
  { value: "1", label: "税率一致" },
  { value: "2", label: "税率不一致" }
];

export const good_type = [
  {
    value: "0",
    label: "待采购设置"
  },
  {
    value: "1",
    label: "待财务设置"
  },
  {
    value: "2",
    label: "已设置完成"
  }
];

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

//类目新增校验规则
export const cost_rules = verification(
  required("tax", "请选择税率"),
  required("cat_code", "请选择类目"),
  required("inv_tag", "请选择税率标识"),
  required("addTax", "请选择增值税管理内容"),
  required("inv_good_name", "请选择商品名称"),
  required("is_discount", "请选择是否包含优惠政策")
);

export const good_detail_columns = [
  {
    field: "spuCode",
    span: 6,
    label: "商品编码"
  },
  {
    field: "good_name",
    span: 18,
    label: "商品名称"
  },
  {
    field: "is_stock",
    label: "商品类型",
    span: 6,
    render(_, { isZx, is_stock }) {
      return h(ElTag, null, {
        default: () => Number(isZx) == 1 ? "反馈商品" : stock_type.find(({ value }) => value === String(is_stock))?.label || "--"
      });
    }
  },
  {
    field: "inv_good_name",
    span: 18,
    label: "开票商品名称"
  },
  {
    field: "companyName",
    label: "业务公司名称",
    render: (_, { companyNo, companyName }) =>
      createTooltip(companyName, "业务公司编码 : " + companyNo, 270),
    span: 8
  },
  {
    field: "supplierName",
    label: "供应商名称",
    render: (_, { supplierNo, supplierName }) =>
      createTooltip(supplierName, "供应商编码 : " + supplierNo, 270),
    span: 8
  },
  {
    label: "源头供应商",
    render: (_, { cgd_supplierNo, cgd_supplierName }) =>
      createTooltip(cgd_supplierName, "供应商编码 : " + cgd_supplierNo, 270),
    span: 8
  },

  {
    field: "cat_name",
    span: 12,
    label: "分类名称"
  },
  {
    field: "unit_name",
    label: "单位名称"
  },
  {
    field: "status",
    label: "是否设置开票类目",
    render(status) {
      return h(ElTag, null, {
        default: () => good_type.find(s => s.value === String(status))?.label
      });
    }
  },
  {
    field: "inv_cat_name",
    label: "类目名称",
    span: 12
  },
  {
    field: "inv_cat_code",
    label: "类目编码"
  },
  {
    field: "inv_tax",
    label: "类目税率额"
  },
  {
    field: "good_img",
    label: "商品图",
    span: 12,
    render(imgSrc) {
      return imgSrc.split(",").map(src =>
        h(ElImage, {
          src,
          previewSrcList: [src],
          style: {
            height: "20px",
            marginRight: "5px"
          }
        })
      );
    }
  },
  {
    field: "creater",
    label: "创建人"
  },
  {
    field: "addtime",
    label: "申请时间"
  },
  {
    field: "after_sales",
    span: 24,
    label: "售后说明"
  },
  {
    field: "craft_desc",
    span: 24,
    label: "工艺说明"
  }
];



export const inv_tag = [
  // {
  //   value: "0",
  //   label: "非零税率"
  // },
  {
    value: "1",
    label: "免税"
  },
  {
    value: "2",
    label: "不征税"
  },
  {
    value: "3",
    label: "零税率"
  }
];

export const add_tax = [
  {
    value: "免税",
    label: "免税"
  },
  {
    value: "不征税",
    label: "不征税"
  }
];
