/**
 * 采购单详情
 */

import { h } from "vue";
import { ElTable, ElTableColumn, 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,
  orderTypeCgOptions
} 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",
    span: 8,
    render(type) {
      return h(ElTag, null, {
        default: () => PURCHASE_STATUS.find(c => c.value == type)?.label
      });
    }
  },
  {
    label: "订单来源",
    field: "cgdSource",
    span: 8,
    render(type) {
      return h(ElTag, null, {
        default: () => cg_order_source_options.find(c => c.value == type)?.label
      });
    }
  },
  {
    label: "商品类型",
    field: "cgdType",
    span: 8,
    render(type) {
      return h(ElTag, null, {
        default: () => cg_order_type_options.find(c => c.value == type)?.label
      });
    }
  },
  {
    label: "采购单状态",
    field: "cgd_status",
    span: 4,
    render(type) {
      return h(ElTag, null, {
        default: () => sendStatusOptions.find(c => c.value == type)?.label
      });
    }
  },
  {
    label: "销售单发货状态",
    field: "qrdSend",
    span: 8,
    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: "pay_type",
    span: 6
  },
  {
    label: "核算码",
    field: "fundCode",
    span: 6
  },
  {
    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,
    render(_, context){
      if(!context || !context.orderTax) return ''
      if(context.orderTax.length === 0) return ''
      const {cat_code, cat_name, tax, short_name } = context.orderTax || {}
      return cat_code + '-' + cat_name + '-' +short_name  + '-' + tax + '%'
    }
  },
  {
    label: '开票商品名称',
    span: 18,
    render(_, context){
      if(!context || !context.orderTax) return ''
      const { inv_good_name } = context.orderTax || {}
      return inv_good_name
    }
  },
  // {
  //   label: '商品开票类目编码',
  //   field: 'TODO:CATEGORY',
  //   span: 6
  // },
  // {
  //   label: '货物和劳务名称',
  //   field: 'TODO:CATEGORY',
  //   span: 6
  // },
  // {
  //   label: '商品和服务分类简称',
  //   field: 'TODO:CATEGORY',
  //   span: 6
  // },
  {
    label: '组合品开',
    field: 'open_type',
    span: 6,
    render(open_type){
      return  String(open_type) === "1" ? "原商品开票" : String(open_type) === "2"  ? "子商品开票" : '--' 
    }
  },
  {
    label: "工艺描述",
    span: 24,
    field: "goodDesc"
  },
  {
    label: "备注",
    span: 24,
    field: "remark"
  }
];


export const purchaseOrderNotIncludeProduceChildColumns: 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",
    span: 8,
    render(type) {
      return h(ElTag, null, {
        default: () => PURCHASE_STATUS.find(c => c.value == type)?.label
      });
    }
  },
  {
    label: "订单来源",
    field: "cgdSource",
    span: 8,
    render(type) {
      return h(ElTag, null, {
        default: () => cg_order_source_options.find(c => c.value == type)?.label
      });
    }
  },
  {
    label: "商品类型",
    field: "cgdType",
    span: 8,
    render(type) {
      return h(ElTag, null, {
        default: () => cg_order_type_options.find(c => c.value == type)?.label
      });
    }
  },
  {
    label: "业务类型",
    field: "is_comon",
    span: 8,
    render(data) {
      return h(ElTag, null, {
        default: () => orderTypeCgOptions.find(c => c.value == data)?.label
      });
    }
  },
  {
    label: "入库状态",
    field: "sendStatus",
    span: 8,
    render(type) {
      return h(ElTag, null, {
        default: () => sendStatusOptions.find(c => c.value == type)?.label
      });
    }
  },
  {
    label: "销售单发货状态",
    field: "qrdSend",
    span: 8,
    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: "pay_type",
    span: 6
  },
  {
    label: "核算码",
    field: "fundCode",
    span: 6
  },
  {
    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"
  },
  // {
  //   label: "子商品信息",
  //   span: 24,
  //   render(_,context){
  //     return h(ElTable, {
  //       data: context.child,
  //       border: true,
  //       size: "small",
  //       style: { width: "100%" }
  //     },[
  //       h(ElTableColumn, {
  //         label: "子商品编码",
  //         prop: "spuCode"
  //       }),
  //       h(ElTableColumn, {
  //         label: "子商品名称",
  //         prop: "good_name"
  //       })
  //     ]);
  //   }
  // }
];

//商品详情
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
];
