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"
import { channelOptions } from "../../inManager/config/shared"

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: '分光'
  },
  {
    label: '结存数',
    field: 'residue_stock',
    span: 6
  },
  {
    field: 'cat_name',
    label: '进项类目',
    span: 18
  }
]


export const orderGoodColumns = [
  {
    field: 'invoiceCode',
    label: '业务编号',
    span: 6
  },
  {
    label: '导入方式',
    width: 100,
    render(_, row) {
      return h(ElTag, { type: 'primary', size: 'small' }, {
        default: () => channelOptions.find(item => item.value == row.channel)?.label
      })
    }
  },
  {
    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 managerStatusOptions.find((item) => item.value == row.manager_status)?.label
    }
  },
  {
    label: '关联金额',
    span: 6,
    field: 'inv_fee'
  },
  {
    label: '创建人',
    span: 6,
    field: 'apply_name'
  },
  {
    label: '创建时间',
    span: 6,
    field: 'create_time'
  },
  {
    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: 12,
    field: 'remark'
  },
  {
    label: '入账月份',
    span: 6,
    field: 'fz_date'
  },
  {
    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: 12,
    field: 'error_remark'
  },

]

export const importOrderGoodColumns = [
  {
    label: '订单购买方公司',
    span: 12,
    render(_, row) {
      return createTooltip(row.buyer_name, "购买方公司纳税识别号 : " + row.buyer_code, 340)
    }
  },
  {
    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(_, { cat_code, cat_name, tax }) {
      return `${cat_code}-${cat_name}-${(Number(tax)) + '%'}`
    }
  },
  {
    label: '商品类型',
    span: 6,
    render(_, { goodType }) {
      return h(ElTag, { size: 'small' }, {
        default: () => cg_order_type_options.find(item => item.value == goodType)?.label
      })
    }
  },
  {
    label: '商品编号',
    span: 6,
    field: 'goodNo'
  },
  {
    label: '商品名称',
    span: 12,
    field: 'goodName'
  },



  {
    label: '单位',
    field: 'unit',
    span: 6
  },
  {
    label: '商品数量',
    field: 'num',
    span: 6
  },
  {
    label: '商品单价',
    field: 'goodPrice',
    span: 6
  },
  {
    label: '订单总金额',
    field: 'totalPrice',
    span: 6
  },


]


export const importInvoiceGoodColumns = [
  {
    label: '购买方公司',
    span: 12,
    render(_, row) {
      return createTooltip(row.inv_buyer_name, "购买方公司纳税识别号 : " + row.inv_buyer_code, 340)
    }
  },
  {
    label: '销售方公司',
    span: 12,
    render(_, row) {
      return createTooltip(row.inv_seller_name, "销售方公司纳税识别号 : " + row.inv_seller_code, 340)
    }
  },
  {
    label: '发票号码',
    field: 'inv_number',
    span: 6
  },
  {
    label: '开票日期',
    field: 'inv_open_date',
    span: 6
  },
  {
    label: '发票类型',
    span: 6,
    render(_, row) {
      return xs_inv_type_list.find(item => item.value == row.inv_type)?.label
    }
  },
  {
    label: '发票明细ID',
    field: 'inv_item_id',
    span: 6
  },
  {
    label: '货物或应税劳务、服务名称',
    field: 'inv_good_name',
    span: 12,
  },
  {
    label: '类目编号',
    span: 6,
    render(_, row) { return row.inv_cat_code }
  },
  {
    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: '税率',
    span: 6,
    field: 'inv_tax',
    render(_, { inv_tax }) {
      return Number(inv_tax) + '%'
    }
  },
  {
    span: 6,
    label: '税额',
    field: 'inv_tax_total'
  },
  {
    label: '税后单价',
    span: 6,
    field: 'inv_price'
  },
  {
    label: '税后总额',
    span: 6,
    field: 'inv_subtotal'
  }
]