import { Time } from '/@/components/Time';
import { FormProps, BasicColumn } from '/@/components/Table';
import { h } from 'vue';
import { FormSchema } from '/@/components/Form/index';
import { useI18n } from '/@/hooks/web/useI18n';
const { t } = useI18n();

export const columns: BasicColumn[] = [
        
  {
    title: '订单号',
    dataIndex: 'orderSn',
    ellipsis: false,
    width: 180,
  },
  {
    title: '支付时间',
    dataIndex: 'payTime',
    width: 150,
    customRender: ({ record }) => {
      return (
        record.payTime &&
        h(Time, {
          value: record.payTime,
          mode: 'datetime',
        })
      );
    },
  },
  {
    title: '开票申请时间',
    dataIndex: 'invoiceTime',
    width: 150,
    customRender: ({ record }) => {
      return (
        record.invoiceTime &&
        h(Time, {
          value: record.invoiceTime,
          mode: 'datetime',
        })
      );
    },
  },
  {
    title: '开票金额',
    dataIndex: 'money',
    width: 80,
  },
  {
    title: '开票类型',
    dataIndex: 'type',
    width: 80,
    customRender:({record})=>{
      if(record.type == 2){
        return '普通发票'
      }else{
        return '专用发票'
      }
    }
  },
  {
    title: '发票抬头',
    dataIndex: 'title',
    // slots: { customRender: 'orderType' },
    width: 150,
  },
  {
    title: '纳税人识别号',
    dataIndex: 'code',
    // slots: { customRender: 'orderStatus' },
    width: 180,
  },
  {
    title: '注册地址',
    dataIndex: 'organizedAddress',
    // slots: { customRender: 'orderStatus' },
    width: 180,
  },
  {
    title: '注册电话',
    dataIndex: 'registerPhone',
    // slots: { customRender: 'orderStatus' },
    width: 120,
  },
  {
    title: '开户银行',
    dataIndex: 'bankName',
    // slots: { customRender: 'orderStatus' },
    width: 150,
  },
  {
    title: '银行账号',
    dataIndex: 'bankAccount',
    // slots: { customRender: 'orderStatus' },
    width: 130,
  },
  {
    title: '收件人姓名',
    dataIndex: 'shipName',
    // slots: { customRender: 'orderStatus' },
    width: 120,
  },
  {
    title: '收件人电话',
    dataIndex: 'shipMobile',
    // slots: { customRender: 'orderStatus' },
    width: 110,
  },
  {
    title: '收货地址',
    dataIndex: 'shipAddress',
    // slots: { customRender: 'orderStatus' },
    width: 130,
  },
  {
    title: '邮箱',
    dataIndex: 'email',
    // slots: { customRender: 'orderStatus' },
    width: 150,
  },
  {
    title: '状态',
    dataIndex: 'invoiced',
    // slots: { customRender: 'orderStatus' },
    width: 80,
    customRender:({record})=>{
      if(record.invoiced == 0){
        return '未开票'
      }else{
        return '已开票'
      }
    }
  },
];
export const searchForm: Partial<FormProps> = {
  labelWidth: 100,
  schemas: [
    {
      field: 'invoiceTime',
      label: '开票申请时间',
      component: 'RangePicker',
      componentProps: {
        maxLength: 100,
        valueFormat:'YYYY-MM-DD',
        format: 'YYYY-MM-DD',
      },
      colProps: {
        xl: 7,
        xxl: 7,
      },
    },
    {
      field: 'payTime',
      label: '支付时间',
      component: 'RangePicker',
      componentProps: {
        maxLength: 100,
        valueFormat:'YYYY-MM-DD',
        format: 'YYYY-MM-DD',
      },
      colProps: {
        xl: 7,
        xxl: 7,
      },
    },{
      field: 'orderSn',
      label: '订单号',
      component: 'Input',
      componentProps: {
        maxLength: 100,
      },
      colProps: {
        xl: 6,
        xxl: 6,
      },
    }
  ],
};
export const InvoiceSchemas: FormSchema[] = [
  {
    field: 'type',
    component: 'Input',
    label: t('routes.product.types'),
    slot: 'text',
    colProps: {
      span: 24,
    },
  },
  {
    field: 'version',
    component: 'Input',
    label: t('routes.product.version'),
    required: true,
    colProps: {
      span: 24,
    },
    rules: [
      {
        required: true,
        // @ts-ignore
        validator: async (rule, value) => {
          if (!value) {
            return Promise.reject(t('common.inputText')+t('routes.product.version'));
          }
          if(/.*[\u4e00-\u9fa5]+.*$/.test(value)){
            /* eslint-disable-next-line */
            return Promise.reject('不支持中文字符');
          }
          return Promise.resolve();
        },
        trigger: 'change',
      },
    ],
    componentProps: {
      maxLength: 15,
      onChange: (data) => {
        console.log('data', data);
      },
    },
  },
  {
    field: 'description',
    component: 'InputTextArea',
    required: true,
    label: t('routes.product.description'),
    componentProps: {
      rows:4,
    },
    colProps: {
      span: 24,
    },
  },
]
