import { ref } from "vue";
import dayjs from "dayjs";
import { send_status_list } from "/@/utils/status";
export function useColumns() {
  const columns = ref([
    {
      type: "selection",
      width: 40,
      align: "center",
      fixed: "left"
    },
    {
      label: "销售订单编码",
      prop: "sequenceNo",
      width: 150,
      showOverflowTooltip: true
    },
    {
      label: "销售订单主编码",
      prop: "cxCode",
      width: 150,
      showOverflowTooltip: true
    },
    // {
    //   label: "名称",
    //   prop: "name",
    //   minWidth: 160,
    //   showOverflowTooltip: true
    // },
    {
      label: "平台订单编码",
      prop: "poCode",
      width: 150
    },
    {
      label: "商品编码",
      prop: "goodNo",
      width: 150,
      showOverflowTooltip: true
    },
    {
      label: "商品名称",
      prop: "goodName",
      minWidth: 160,
      showOverflowTooltip: true
    },
    {
      label: "平台类型",
      prop: "platform_type",
      width: "80px",
      slot: "platform_type"
    },
    {
      label: "发货状态",
      prop: "sendStatus",
      width: "95px",
      showOverflowTooltip: true,
      cellRenderer: ({ row, props }) => (
        <el-tag
          size={props.size}
          type={
            (
              send_status_list.find(
                item => item.value == row.sendStatus + ""
              ) || {}
            ).type || "info"
          }
          effect="plain"
        >
          {(
            send_status_list.find(item => item.value == row.sendStatus + "") ||
            {}
          ).label || "--"}
        </el-tag>
      )
    },
    {
      label: "客户编码",
      prop: "customerNo",
      width: 150,
      showOverflowTooltip: true
    },
    {
      label: "客户名称",
      prop: "customerName",
      minWidth: 160,
      showOverflowTooltip: true
    },
    {
      label: "订单总金额",
      prop: "totalPrice",
      width: 110,
      showOverflowTooltip: true
    },
    {
      label: "商品数量",
      prop: "goodNum",
      width: 110,
      showOverflowTooltip: true
    },
    {
      label: "未开票数量",
      prop: "winv_num",
      width: 110
    },
    {
      label: "已开票金额",
      prop: "ainv_fee",
      width: 110,
      showOverflowTooltip: true
    },
    {
      label: "开票中金额",
      prop: "inv_fee",
      width: 110,
      showOverflowTooltip: true
    },
    {
      label: "未开票金额",
      prop: "winv_fee",
      width: 110,
      showOverflowTooltip: true
    },
    {
      label: "业务员",
      prop: "ownerName",
      width: 80,
      showOverflowTooltip: true
    },
    {
      label: "创建时间",
      width: 140,
      prop: "createTime",
      showOverflowTooltip: true,
      formatter: ({ addtime }) => dayjs(addtime).format("YYYY-MM-DD HH:mm:ss")
    }
  ]);

  return {
    columns
  };
}

export const order_detail_columns = [
  {
    field: "sequenceNo",
    label: "销售订单编码"
  },
  {
    field: "ownerName",
    label: "销售员"
  },
  {
    field: "department",
    label: "平台名称"
  },
  {
    field: "goodPrice",
    label: "商品单价"
  },
  {
    field: "companyName",
    label: "业务公司名称",
    span: 12
  },
  {
    field: "customerName",
    label: "客户名称",
    span: 12
  },

  {
    field: "goodName",
    label: "商品名称",
    span: 24
  },
  {
    field: "goodNum",
    label: "商品总数量"
  },
  {
    field: "ainv_num",
    label: "已开票数量"
  },
  {
    field: "inv_num",
    label: "开票中数量"
  },
  {
    field: "winv_num",
    label: "未开票数量"
  },
  {
    field: "totalPrice",
    label: "订单总金额"
  },
  {
    field: "ainv_fee",
    label: "已开票金额"
  },
  {
    field: "inv_fee",
    label: "开票中金额"
  },

  {
    field: "winv_fee",
    label: "未开票金额"
  }
];

/**
 * @invoice_addr 公司注册地址
 * @invoice_people  法人
 * @invoice_mobile 联系方式
 * @invoice_code 纳税识别号
 * @invoice_bank 开户行
 * @invoice_bankNo 开户账户
 */
export const convertInvoiceTitle = (title: Record<string, string>) => {
  const {
    company_address,
    mobile,
    company_license,
    bank_name,
    bankNo,
    company_name
  } = title;

  return {
    invoice_addr: company_address,
    invoice_mobile: mobile,
    invoice_code: company_license,
    invoice_bank: bank_name,
    invoice_bankNo: bankNo,
    invoice_title: company_name
  };
};

export const convertInvoiceTitleData = (title: Record<string, string>) => {
  const {
    invoice_addr,
    invoice_mobile,
    invoice_code,
    invoice_bank,
    invoice_bankNo,
    invoice_title
  } = title;

  return {
    invoice_code,
    invoice_title,
    addrAndmobile: invoice_addr + " " + invoice_mobile,
    bankAndBankNo: invoice_bank + " " + invoice_bankNo
  };
};

export const invoice_columns = [
  {
    label: "抬头",
    span: 24,
    field: "invoice_title"
  },
  {
    label: "纳税人识别号",
    span: 24,
    field: "invoice_code"
  },
  {
    label: "地址、电话",
    span: 24,
    field: "addrAndmobile"
  },
  {
    label: "开户行及账号",
    span: 24,
    field: "bankAndBankNo"
  }
];
