import { ElTag } from "element-plus"
import { cg_order_type_options, xs_inv_type_list } from "/@/utils/status"
import { h } from "vue"
import { managerStatusOptions, sourceOptions, statusOptions, typeOptions } from "./shared"
import { createTooltip } from "/@/utils/tootip"

export const goodColumns = [
  {
    span: 12,
    field: 'seller_name',
    label: '销售方公司'
  },
  {
    span: 12,
    field: 'buyer_name',
    label: '购买方公司'
  },
  {
    span: 12,
    field: 'goodName',
    label: '订单商品名称'
  },
  {
    span: 12,
    field: 'inv_good_name',
    label: '发票商品名称'
  },
  {
    span: 6,
    label: '商品类型',
    render(_, { good_type }) {
      return h(ElTag, { size: 'small' }, {
        default: () => cg_order_type_options.find(item => item.value == good_type)?.label || '--'
      })
    }
  },
  {
    span: 6,
    field: 'good_code',
    label: '商品代码'
  },
  {
    span: 6,
    field: 'spec',
    label: '规格'
  },
  {
    span: 6,
    field: 'unit',
    label: '单位'
  },
  {
    span: 6,
    field: 'unit_price',
    label: '税前单价'
  },
  {
    span: 6,
    field: 'subunit_price',
    label: '税后单价'
  },
  {
    span: 6,
    field: 'unit_weight',
    label: '重量'
  },
  {
    span: 6,
    field: 'spectral',
    label: '分光'
  },
  {
    field: 'cat_name',
    label: '进项类目',
    span: 24
  }
]


export const orderGoodColumns = [
  {
    field: 'invoiceCode',
    label: '业务编号',
    span: 12
  },
  {
    label: '类型',
    span: 6,
    render(_, row) {
      return h(ElTag, { type: 'primary', size: 'small' }, {
        default: () => typeOptions.find(item => item.value == row.type)?.label
      })
    }
  },
  {
    label: '数据来源',
    span: 6,
    render(_, row) {
      return h(ElTag, { type: 'primary', size: 'small' }, {
        default: () => sourceOptions.find(item => item.value == row.source)?.label
      })
    }
  },
  {
    label: '状态',
    span: 6,
    render(_, row) {
      return h(ElTag, { type: statusOptions.find(item => item.value == row.status)?.type, size: 'small' }, {
        default: () => statusOptions.find(item => item.value == row.status)?.label
      })
    }
  },
  {
    label: '异常原因',
    span: 18,
  },
  {
    label: '销售方公司',
    span: 12,
    render(_, row) {
      return createTooltip(row.seller_name, "销售方公司纳税识别号 : " + row.seller_code, 340)
    }
  },
  {
    label: '订单编号',
    field: 'orderCode',
    span: 6
  },
  {
    label: '订单主编号',
    field: 'cxCode',
    span: 6
  },
  {
    label: '商品名称',
    span: 12,
    render(_, row) {
      return createTooltip(row.goodName, "商品编号 : " + row.goodNo, 340)
    }
  },
  {
    label: '单位',
    field: 'unit',
    span: 6
  },
  {
    label: '商品数量',
    field: 'num',
    span: 6
  },
  {
    label: '商品单价',
    field: 'goodPrice',
    span: 6
  },
  {
    label: '订单总金额',
    field: 'totalPrice',
    span: 6
  },
  {
    label: '税目',
    field: 'cat_code',
    span: 6
  },
  {
    label: '税率',
    span: 6,
    render(_, row) {
      return (Number(row.tax) * 100) + '%'
    }
  },
  {
    label: '购买方公司',
    span: 12,
    render(_, row) {
      return createTooltip(row.buyer_name, "购买方公司纳税识别号 : " + row.buyer_code, 340)
    }
  },
  {
    label: '关联金额',
    field: 'inv_fee',
    span: 6
  },
  {
    label: '发票号码',
    field: 'inv_number',
    span: 6
  },
  {
    label: '发票销售方公司',
    span: 12,
    render(_, row) {
      return createTooltip(row.inv_seller_name, "发票销售方公司编号 : " + row.inv_seller_code, 340)
    }
  },
  {
    label: '发票明细ID',
    span: 6,
    field: 'inv_item_id'
  },
  {
    label: '发票类型',
    span: 6,
    render(_, row) {
      return xs_inv_type_list.find(item => item.value == row.inv_type)?.label
    }
  },
  {
    label: '货物或应税劳务、服务名称',
    span: 12,
    field: 'inv_good_name'
  },
  {
    label: '规格型号',
    span: 6,
    field: 'inv_spec'
  },
  {
    label: '发票商品单位',
    span: 6,
    field: 'inv_unit'
  },
  {
    label: '发票商品数量',
    span: 6,
    field: 'inv_num'
  },
  {
    label: '税前单价',
    span: 6,
    field: 'inv_subprice'
  },
  {
    label: '税前总价',
    span: 6,
    field: 'inv_subtotal'
  },
  {
    label: '发票税率',
    field: 'inv_tax',
    span: 6
  },
  {
    label: '发票税额',
    field: 'inv_tax_total',
    span: 6
  },
  {
    label: '税后单价',
    field: 'inv_price',
    span: 6
  },
  {
    label: '税后单价',
    field: 'inv_total',
    span: 6
  },
  {
    label: '类目编号状态',
    span: 6,
    render(_, row) {
      return h(ElTag, { size: 'small', type: row.cat_diff == '0' ? 'danger' : 'success' }, {
        default: () => row.cat_diff == '0' ? '不一致' : '一致'
      })
    }
  },
  {
    label: '税率状态',
    span: 6,
    render(_, row) {
      return h(ElTag, { size: 'small', type: row.tax_diff == '0' ? 'danger' : 'success' }, {
        default: () => row.tax_diff == '0' ? '不一致' : '一致'
      })
    }
  },
  {
    label: '业务类型',
    span: 6,
    render(_, row) {
      return managerStatusOptions.find((item) => item.value == row.manager_status)?.label
    }
  },
  {
    label: '备注',
    span: 12,
    field: 'remark'
  }
]