import { ElButton, ElTable, ElTableColumn, ElTag, ElTooltip } from "element-plus"
import { cg_order_type_options, goodTypeOptions, useTypeOptions, xs_inv_type_list } from "/@/utils/status"
import { h } from "vue"
import { managerStatusOptions, sourceOptions, statusOptions, typeOptions } from "./shared"
import { createTooltip } from "/@/utils/tootip"
import { useRenderIcon } from "/@/components/ReIcon/src/hooks"

export const goodColumns_1 = [
  {
    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 goodColumns = [
  {
    span: 8,
    field: 'orderCode',
    label: '确认单编号'
  },
  {
    span: 8,
    field: 'cxCode',
    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 = (handleShowDetail: any, isShowChild = true) => ([
  {
    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,
    field: 'apply_name'
  },
  {
    label: '创建时间',
    span: 6,
    field: 'create_time'
  },
  {
    span: 12,
    label: '订单购买方公司',
    render(_, row) {
      return createTooltip(row.buyer_name, '购买方公司编号:' + row.buyer_code)
    }
  },
  {
    span: 12,
    label: '订单销售方公司',
    render(_, row) {
      return createTooltip(row.seller_name, '销售方公司纳税号:' + row.seller_code)
    }
  },
  {
    span: 6,
    field: 'orderCode',
    label: '订单编号'
  },
  {
    span: 6,
    field: 'cxCode',
    label: '订单主单号'
  },

  {
    label: '商品类型',
    span: 6,
    render(_, row) {
      return h(ElTag, { type: 'primary', size: 'small' }, {
        default: () => goodTypeOptions.find(item => item.value == row.goodType)?.label
      })
    }
  },
  {
    label: '商品名称',
    span: 6,
    render(_, row) {
      return createTooltip(row.goodName, '商品编号:' + row.goodNo, 300)
    }
  },
  {
    span: 6,
    label: '订单单位',
    field: 'unit'
  },
  {
    span: 6,
    label: '商品数量',
    field: 'num'
  },
  {
    span: 6,
    label: '商品单价',
    field: 'goodPrice'
  },
  {
    span: 6,
    label: '订单总金额',
    field: 'totalPrice'
  },
  {
    label: '出库时间',
    span: 6,
    field: 'fz_date'
  },
  // {
  //   span: 6,
  //   label: '平台订单号',
  //   field: 'poCode'
  // },
  {
    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,
  },
  ...(isShowChild ? [{
    label: '出库商品',
    span: 24,
    render(_, { ProductRela }) {
      return h(ElTable, { size: 'small', border: true, style: { width: '100 %' }, data: ProductRela }, [
        h(ElTableColumn, { prop: 'product_id', label: 'ID', width: '60px', showOverflowTooltip: true }),
        h(ElTableColumn, { prop: 'skuCode', label: '商品编号', showOverflowTooltip: true }, null),
        h(ElTableColumn, { prop: 'goodName', label: '商品名称', showOverflowTooltip: true }, null),
        h(ElTableColumn, { prop: 'num', label: '操作数量', showOverflowTooltip: true }),
        h(ElTableColumn, { prop: 'create_time', label: '创建时间', showOverflowTooltip: true }),
        h(ElTableColumn, { label: '操作', showOverflowTooltip: true }, {
          default: ({ row, $index }) => h(ElTooltip, { content: '查看详情', placement: 'top' }, {
            default: () => h(ElButton, {
              onClick: () => handleShowDetail(row.product_id, $index),
              icon: useRenderIcon('eye-view'),
              type: 'primary',
              size: 'small',
              link: true,
            })
          })
        }),
      ])
    }
  }] : [])
])