/**
 * 采购单详情
 */

import { h } from "vue";
import { ElTag } from "element-plus";
import { createTooltip } from "/@/utils/tootip";
import { DescriptionColumns } from "/@/components/BasicDescriptions";

import {
  cg_order_type_options,
  cg_order_source_options,
  send_status_list,
  sendStatusOptions
} from "/@/utils/status";

export const PURCHASE_STATUS = [
  {
    value: "0",
    label: "未对账"
  },
  {
    value: "1",
    label: "对账"
  }
];

export const PURCHASE_TYPE = [
  {
    value: "1",
    label: "库存"
  },
  {
    value: "2",
    label: "非库存"
  },
  {
    value: "3",
    label: "咨询"
  }
];

export const PURCHAS_SOURCE = [
  {
    value: "1",
    label: "直接下单"
  },
  {
    value: "2",
    label: "咨询"
  },
  {
    value: "3",
    label: "项目"
  },
  {
    value: "4",
    label: "平台"
  },
  {
    value: "5",
    label: "有赞"
  }
];

export const PRODUCT_TYPE = [
  {
    value: "1",
    label: "正常商品"
  },
  {
    value: "2",
    label: "赠品"
  },
  {
    value: "3",
    label: "样品"
  }
];

export const SEND_TYPE = [
  {
    value: "1",
    label: "供应商包邮"
  },
  {
    value: "2",
    label: "公司自提"
  }
];

export const PAY_STATUS = [
  {
    value: "1",
    label: "未付款"
  },
  {
    value: "2",
    label: "部分付款"
  },
  {
    value: "3",
    label: "已付款"
  }
];

//采购单不包含商品的详情
export const purchaseOrderNotIncludeProduceColumns: DescriptionColumns = [
  {
    label: "采购单编码",
    field: "sequenceNo",
    span: 6
  },
  {
    label: "销售订单编码",
    field: "qrdCode",
    span: 6
  },
  {
    label: "采购员",
    field: "ownerName",
    span: 6,
    labelWidth: "80",
    render: (ownerName, { department }) =>
      createTooltip(ownerName, "部门: " + department, 260)
  },
  {
    label: "采购时间",
    span: 6,
    field: "createdTime"
  },
  {
    label: "买入方公司",
    field: "companyName",
    span: 12,
    render: (companyName, { companyNo }) =>
      createTooltip(companyName, "业务企业公司编码 : " + companyNo, 300)
  },
  {
    label: "卖出方公司",
    span: 12,
    field: "supplierName",
    render: (supplierName, { supplierNo }) =>
      createTooltip(supplierName, "供应商编码 : " + supplierNo, 300)
  },
  {
    label: "商品名称",
    field: "goodName",
    span: 24,
    render: (goodName, { goodNo }) =>
      createTooltip(goodName, "商品编码 : " + goodNo, 260)
  },
  {
    label: "对账状态",
    field: "status",
    render(type) {
      return h(ElTag, null, {
        default: () => PURCHASE_STATUS.find(c => c.value == type)?.label
      });
    }
  },
  {
    label: "订单来源",
    field: "cgdSource",
    render(type) {
      return h(ElTag, null, {
        default: () => cg_order_source_options.find(c => c.value == type)?.label
      });
    }
  },
  {
    label: "商品类型",
    field: "cgdType",
    span: 4,
    render(type) {
      return h(ElTag, null, {
        default: () => cg_order_type_options.find(c => c.value == type)?.label
      });
    }
  },
  {
    label: "入库状态",
    field: "sendStatus",
    span: 4,
    render(type) {
      return h(ElTag, null, {
        default: () => sendStatusOptions.find(c => c.value == type)?.label
      });
    }
  },
  {
    label: "销售单发货状态",
    field: "qrdSend",
    span: 4,
    render(data) {
      return h(ElTag, null, {
        default: () => send_status_list.find(c => c.value == data)?.label
      });
    }
  },
  {
    label: "商品数量",
    field: "goodNum"
  },
  {
    label: "已发货数量",
    field: "sendNum"
  },
  {
    label: "未发货数量",
    field: "wsendNum"
  },
  {
    label: "退货数量",
    field: "thNum"
  },
  {
    label: "备库编码",
    field: "bkCode"
  },
  {
    label: "备库人员",
    field: "bkCreater"
  },
  // {
  //   label: "发货方式",
  //   field: "sendType",
  //   render(sendType) {
  //     return h(ElTag, null, {
  //       default: () => cgd_send_type.find(c => c.value == sendType + "")?.label
  //     });
  //   }
  // },
  {
    label: "核算码",
    field: "fundCode",
    span: 12
  },
  {
    label: "分类",
    span: 12,
    field: "cat",
    render(_, { firstCat, secCat, thirdCat }) {
      return h(ElTag, null, {
        default: () => firstCat + "_" + secCat + "_" + thirdCat
      });
    }
  },
  {
    label: "品牌",
    span: 12,
    field: "goodBrand"
  },
  {
    label: "单位",
    field: "goodUnit"
  },

  {
    label: "税率",
    field: "tax"
  },
  {
    label: "单价",
    field: "goodPrice"
  },

  {
    label: "总价",
    field: "totalPrice"
  },
  {
    label: "工艺描述",
    span: 24,
    field: "goodDesc"
  },
  {
    label: "备注",
    span: 24,
    field: "remark"
  }
];

//商品详情
export const purchaseOrderProduceColumns: DescriptionColumns = [
  {
    label: "品牌",
    field: "goodBrand"
  },
  {
    label: "单位",
    field: "goodUnit"
  },
  {
    label: "一级分类",
    field: "firstCat"
  },
  {
    label: "二级分类",
    field: "secCat"
  },
  {
    label: "三级分类",
    field: "thirdCat"
  },
  {
    label: "核算码",
    field: "fundCode"
  },
  {
    label: "工艺描述",
    span: 12,
    field: "goodDesc"
  },
  {
    label: "金价",
    field: "metalsType"
  },
  {
    label: "贵金属类型",
    field: "metalsType"
  },
  {
    label: "贵金属重量",
    field: "weight"
  },
  {
    label: "金价",
    field: "goldPrice"
  },
  {
    label: "物流时间",
    field: "deliveryDay"
  },
  {
    label: "工期时间",
    field: "workDay"
  },
  {
    label: "税率",
    field: "tax"
  },
  {
    label: "裸价",
    field: "barePrice"
  },
  {
    label: "加标费",
    field: "markPrice"
  },
  {
    label: "包装费",
    field: "packPrice"
  },
  {
    label: "开模费",
    field: "costPrice"
  },
  {
    label: "物流费",
    field: "deliveryPrice"
  },
  {
    label: "单价",
    field: "goodPrice"
  },
  {
    label: "是否库存",
    field: "isStock",
    render(type) {
      return h(ElTag, null, {
        default: () => (type == "0" ? "非库存" : "库存")
      });
    }
  },
  {
    label: "商品数量",
    field: "goodNum"
  },
  {
    label: "总价",
    field: "totalPrice"
  }
];

export const purchaseOrderColumns = [
  ...purchaseOrderProduceColumns,
  ...purchaseOrderNotIncludeProduceColumns
];
