import { ref } from "vue";
import dayjs from "dayjs";
import { send_status_list, inv_status_list } from "/@/utils/status";
export function useColumns() {
  const columns = ref([
    {
      type: "selection",
      reserveSelection: true
    },
    {
      label: "销售订单编号",
      prop: "sequenceNo",
      minWidth: 160,
      showOverflowTooltip: true
    },

    {
      label: "所属平台",
      prop: "department",
      minWidth: 160,
      showOverflowTooltip: true
    },
    {
      label: "商品编码",
      prop: "goodNo",
      minWidth: 160,
      showOverflowTooltip: true
    },
    {
      label: "商品名称",
      prop: "goodName",
      minWidth: 160,
      showOverflowTooltip: true
    },
    {
      label: "企业客户编号",
      prop: "companyNo",
      minWidth: 160,
      showOverflowTooltip: true
    },
    {
      label: "企业客户名称",
      prop: "companyName",
      minWidth: 160,
      showOverflowTooltip: true
    },

    {
      label: "订单总金额",
      prop: "totalPrice",
      minWidth: 110,
      showOverflowTooltip: true
    },

    {
      label: "退货数量",
      prop: "th_fee",
      width: 110,
      showOverflowTooltip: true
    },
    {
      label: "退货金额",
      prop: "th_fee",
      width: 110,
      showOverflowTooltip: true
    },
    {
      label: "发货状态",
      prop: "sendStatus",
      minWidth: 110,
      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: "ainv_fee",
      minWidth: 110,
      showOverflowTooltip: true
    },
    {
      label: "发票核销中",
      prop: "inv_fee",
      minWidth: 110,
      showOverflowTooltip: true
    },
    {
      label: "发票未核销",
      prop: "winv_fee",
      minWidth: 110,
      showOverflowTooltip: true
    },

    {
      label: "发票核销状态",
      prop: "inv_type",
      minWidth: 110,
      showOverflowTooltip: true,
      cellRenderer: ({ row, props }) => (
        <el-tag
          size={props.size}
          type={
            (
              inv_status_list.find(item => item.value == row.inv_status + "") ||
              {}
            ).type || "info"
          }
          effect="plain"
        >
          {(
            inv_status_list.find(item => item.value == row.inv_status + "") ||
            {}
          ).label || "--"}
        </el-tag>
      )
    },
    {
      label: "业务员",
      prop: "ownerName",
      minWidth: 80,
      showOverflowTooltip: true
    },
    {
      label: "创建时间",
      minWidth: 145,
      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: "companyName",
    label: "业务公司名称"
  },
  {
    field: "customerName",
    label: "客户名称"
  },
  {
    field: "goodNum",
    label: "商品数量"
  },
  {
    field: "goodPrice",
    label: "商品单价"
  },
  {
    field: "goodName",
    label: "商品名称"
  },
  {
    field: "inv_fee",
    label: "开票中"
  },
  {
    field: "ainv_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,
    contector,
    mobile,
    company_license,
    bank_name,
    bankNo
  } = title;

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

export const invoice_columns = [
  {
    label: "联系方式",
    field: "invoice_mobile"
  },
  {
    label: "纳税识别号",
    field: "invoice_code"
  },
  {
    label: "开户行",
    field: "invoice_bank"
  },
  {
    label: "开户账户",
    field: "invoice_bankNo"
  },
  {
    label: "公司注册地址",
    field: "invoice_addr"
  }
];
