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

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 = {
  cat_code: [{ required: true, trigger: "change", message: "请选择类目" }],
  inv_tag: [{ required: true, trigger: "change", message: "请选择税率标识" }],
  is_discount: [
    { required: true, trigger: "change", message: "请选择是否包含优惠政策" }
  ],
  inv_good_name: [
    { required: true, trigger: "change", message: "请选择商品名称" }
  ],
  tax: [{ required: true, trigger: "change", message: "请选择税率" }],
  addTax: [
    { required: true, trigger: "change", message: "请选择增值税管理内容" }
  ]
};

export const good_detail_columns = [
  {
    field: "spuCode",
    span: 6,
    label: "商品编码"
  },
  {
    field: "good_name",
    span: 18,
    label: "商品名称"
  },
  {
    field: "is_stock",
    label: "商品类型",
    span: 6,
    render(stock, { isZx, is_stock }) {
      return h(ElTag, null, {
        default: () => Number(isZx) == 1 ? "反馈商品" : stock_type.find(({ value }) => value === String(is_stock))?.label || "--"
      });
    }
  },
  {
    field: "good_img",
    label: "商品图",
    span: 18,
    render(imgSrc) {
      return imgSrc.split(",").map(src =>
        h(ElImage, {
          src,
          previewSrcList: [src],
          style: {
            height: "20px",
            marginRight: "5px"
          }
        })
      );
    }
  },
  {
    field: "cgd_inv_good_name",
    span: 24,
    label: "采购开票商品名称"
  },
  {
    field: "cgd_inv_cat_name",
    label: "采购类目名称",
    span: 12
  },
  {
    field: "cgd_inv_cat_code",
    label: "采购类目编码"
  },
  {
    field: "cgd_inv_tax",
    label: "采购类目税率额"
  },
  {
    field: "inv_good_name",
    span: 24,
    label: "财务开票商品名称"
  },
  {
    field: "inv_cat_name",
    label: "财务类目名称",
    span: 12
  },
  {
    field: "inv_cat_code",
    label: "财务类目编码"
  },
  {
    field: "inv_tax",
    label: "财务类目税率额"
  },
  {
    field: "companyName",
    label: "业务公司名称",
    render: (companyName, { companyNo }) =>
      createTooltip(companyName, "业务公司编码 : " + companyNo, 270),
    span: 12
  },
  {
    field: "supplierName",
    label: "供应商名称",
    render: (supplierName, { supplierNo }) =>
      createTooltip(supplierName, "供应商编码 : " + supplierNo, 270),
    span: 12
  },

  {
    field: "cat_name",
    span: 12,
    label: "分类名称"
  },
  {
    field: "unit_name",
    label: "单位名称"
  },
  {
    field: "status",
    label: "状态",
    render(status) {
      return h(
        ElTag,
        {
          type: status === "2" ? "success" : ""
        },
        {
          default: () => good_type.find(s => s.value === String(status))?.label
        }
      );
    }
  },
  {
    field: "creater",
    label: "创建人",
    span: 12,
  },
  {
    field: "addtime",
    label: "申请时间",
    span: 12,
  },
  {
    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: "不征税"
  }
];
