import { ContentConfig } from "/@/components/PageContent";
import { httpList } from "/@/api/InvoiceSales/capitalPool";

import dayjs from "dayjs";
import { h } from "vue";
import { ElTag } from "element-plus";
import { CAPITAL_STATUS } from "/@/utils/details/tragelog";


import {
  xs_order_source_options,
  xs_order_type_options,
  useTypeOptions
} from "/@/utils/status";


import { renderIconLabelLeft } from "/@/utils/columnRenderHelper";

const tagTypeOptions = [
  { value: '0', label: '手动创建' },
  { value: '1', label: '系统创建' }
]

const columns = [
  {
    type: "selection",
    align: "center",
    width: 40,
    fixed: 'left'
  },
  {
    label: "资金认领编码",
    prop: "logNo",
    fixed: "left",
    width: "150px"
  },
  {
    label: '资金批次号/资金编码',
    prop: 'pcCode',
    width: '150px',
    cellRenderer({ row }){
      return h('div', { class: 'flex flex-col' }, {
        default : () => ([
          h('p', null, row.pcCode + '/'),
          h('p', null, row.tradNo),
        ])
      })
    }
  },
  {
    label: "销售订单编码/销售主单号",
    width: "160px",
    cellRenderer({ row }) {
      return h('div', { class: 'flex flex-col' }, {
        default: () => ([
          h('p', null, row.orderCode + '/'),
          h('p', null, row.cxCode),
        ])
      })
    }
  },
  // {
  //   label: "销售主单号",
  //   prop: "cxCode",
  //   width: "160px"
  // },


  {
    label: "状态",
    prop: "status",
    width: 90,
    cellRenderer: ({ row }) => {
      return h(ElTag, null, {
        default: () =>
          CAPITAL_STATUS.find(s => s.value == row.status)?.label || "--"
      });
    }
  },
  {
    label: 'PO编号',
    width: '150px',
    cellRenderer({ row }) {
      return h('div', { class: 'flex flex-col', style: { 'margin': '0px -10px' } }, {
        default: () => ([
          h('p', { class: 'px-[10px]', style: { 'border-bottom': '1px solid #ebeef5', 'min-height': '24px', 'padding': '0 10px' } }, row.order_poCode),
          h('p', { class: 'px-[10px]', style: { 'min-height': '24px', 'padding': '0 10px' } }, row.poCode),
        ])
      })
    }
  },
  {
    label: '商品编号',
    width: '150px',
    cellRenderer({ row }) {
      return h('div', { class: 'flex flex-col', style: { 'margin': '0px -10px' } }, {
        default: () => ([
          h('p', {  style: { 'border-bottom': '1px solid #ebeef5', 'min-height': '24px', 'padding': '0 10px' } }, row.lib_goodNo),
          h('p', {  style: { 'min-height': '24px', 'padding': '0 10px' } }, row.goodNo),
        ])
      })
    }
  },
  {
    label: '商品名称',
    width: '150px',
    cellRenderer({ row }) {
      return h('div', { class: 'flex flex-col', style: { 'margin': '0px -10px' } }, {
        default: () => ([
          h('p', { style: { 'border-bottom': '1px solid #ebeef5', 'min-height': '24px', 'padding': '0 10px' } }, row.lib_goodName),
          h('p', { style: { 'min-height': '24px', 'padding': '0 10px' } }, row.goodName),
        ])
      })
    }
  },
  {
    label: '单价',
    width: '90px',
    cellRenderer({ row }) {
      return h('div', { class: 'flex flex-col', style: { 'margin': '0px -10px' } }, {
        default: () => ([
          h('p', { style: { 'border-bottom': '1px solid #ebeef5', 'min-height': '24px', 'padding': '0 10px' } }, row.lib_price),
          h('p', { style: { 'min-height': '24px', 'padding': '0 10px' } }, row.goodPrice),
        ])
      })
    }
  },
  {
    label: '总价',
    width: '90px',
    cellRenderer({ row }) {
      return h('div', { class: 'flex flex-col', style: { 'margin': '0px -10px' } }, {
        default: () => ([
          h('p', { style: { 'border-bottom': '1px solid #ebeef5', 'min-height': '24px', 'padding': '0 10px' } }, row.lib_total),
          h('p', { style: { 'min-height': '24px', 'padding': '0 10px' } }, row.totalPrice),
        ])
      })
    }
  },
  {
    label: '数量',
    width: '80px',
    cellRenderer({ row }) {
      return h('div', { class: 'flex flex-col', style: { 'margin': '0px -10px' } }, {
        default: () => ([
          h('p', { style: { 'border-bottom': '1px solid #ebeef5', 'min-height': '24px', 'padding': '0 10px' } }, row.lib_goodNum),
          h('p', { style: { 'min-height': '24px', 'padding': '0 10px' } }, row.goodNum),
        ])
      })
    }
  },
  {
    label: "认领金额",
    prop: "total_fee",
    width: "110px"
  },
  // {
  //   label: "平台类型",
  //   prop: "platform",
  //   width: "120px",
  //   cellRenderer({ row }) {
  //     return h(ElTag, null, {
  //       default: () =>
  //         useTypeOptions.find(s => s.value == row.platform_type)?.label || "--"
  //     });
  //   }
  // },
  {
    label: '操作来源',
    width: 150,
    cellRenderer: ({ row }) => {
      return h('div', { class: 'flex' }, {
        default: () => ([
          h(ElTag, { type: row.tag_type == '0' ? 'info' : '', class: 'mr-[5px]' }, {  default: () => tagTypeOptions.find(s => s.value == row.tag_type)?.label || "--" }),
          row.relaNo
        ])
      })
    }
  },
  // {
  //   label: '关联资金编号',
  //   width: 120,
  //   prop: 'relaNo'
  // },
  // {
  //   label: "订单来源",
  //   prop: "qrdSource",
  //   width: "100px",
  //   cellRenderer({ row }) {
  //     return h(ElTag, null, {
  //       default: () =>
  //         xs_order_source_options.find(s => s.value == row.qrdSource)?.label
  //     });
  //   }
  // },
  // {
  //   label: "商品类型",
  //   prop: "qrdType",
  //   width: "100px",
  //   cellRenderer({ row }) {
  //     return h(ElTag, null, {
  //       default: () =>
  //         xs_order_type_options.find(s => s.value == row.qrdType)?.label
  //     });
  //   }
  // },
  {
    label: "平台名称",
    prop: "platName",
    width: "140px",
      cellRenderer({ row }) {
        return h('div', { class: "flex w-full" }, {
          default: () => [
            h(ElTag, { class: 'mr-[5px]' }, { default: () => useTypeOptions.find(s => s.value == row.platform_type)?.label || "--" }),
            row.platName
          ]
        })
      }
  },
  // {
  //   label: "商品名称",
  //   prop: "goodName",
  //   nimWidth: "160px",
  //   ...renderIconLabelLeft('goodNo','goodName','商品编码:')
  // },
  // {
  //   label: "申请人",
  //   prop: "apply_name",
  //   width: "70px"
  // },
  {
    label: "认领人/时间",
    prop: "addtime",
    width: "140px",
    cellRenderer({ row }) {
      return h('div', { class: 'flex flex-col', style: { 'margin': '0px -10px' } }, {
        default: () => ([
          h('p', { class: 'px-[10px]', style: { 'min-height': '24px', 'padding': '0 10px' } }, row.apply_name + '/'),
          h('p', { class: 'px-[10px]', style: { 'min-height': '24px', 'padding': '0 10px' } }, row.addtime),
        ])
      })
    }
  },
  {
    label: "操作",
    fixed: "right",
    width: 80, //后期修改
    slot: "operation"
  }
];

const contentConfig = (isTenThound: boolean): ContentConfig => ({
  title: "",
  showTitle: true,
  columns,
  superUserNoAction: true,
  apis: { 
    httpList: (parameter = {}) => {
      const { date, ...rest } = parameter as any
     if(isTenThound){
      const key='?'
      if(rest.orderCode){
        rest.orderCode=key
      }
      if(rest.cxCode){
        rest.cxCode=key
      }
     }
      return httpList(rest)
    },
    httpAdd: true 
  }
})

export default contentConfig;
