import { h } from 'vue';
import { NImage } from 'naive-ui';
import { fetchGetAllStoreList } from '@/service/api/goods/desk-category';
import { useAuth } from '@/hooks/business/auth';
import type { FormSchema } from '@/components/zt/Form/types/form';
export const SearchForm: FormSchema[] = [
  {
    label: '门店名称',
    component: 'ApiSelect',
    field: 'shopId',
    componentProps: {
      api: fetchGetAllStoreList,
      labelFeild: 'shopName',
      valueFeild: 'shopId'
    }
  },

  {
    label: '订单类型',
    component: 'NSelect',
    field: 'dvyType',
    componentProps: {
      options: [
        {
          label: '全部',
          value: ''
        },
        {
          label: '快递',
          value: 1
        },
        {
          label: '配送',
          value: 3
        }
      ]
    }
  },
  {
    label: '退款编号',
    component: 'NInput',
    field: 'refundSn'
  },
  {
    label: '订单编号',
    component: 'NInput',
    field: 'orderNumber'
  },
  {
    label: '收货人姓名',
    component: 'NInput',
    field: 'receiver'
  },
  {
    label: '收货人手机号',
    component: 'NInput',
    field: 'userMobile'
  },
  {
    label: '申请方式',
    component: 'NSelect',
    field: 'applyType',
    componentProps: {
      options: [
        {
          label: '仅退款',
          value: 1
        },
        {
          label: '退货退款',
          value: 2
        },
        {
          label: '差价退款',
          value: 5
        }
      ]
    }
  },
  {
    label: '售后状态',
    component: 'NSelect',
    field: 'refundStatus',
    componentProps: {
      options: [
        {
          label: '申请退款',
          value: 1
        },
        {
          label: '退款成功',
          value: 2
        },
        {
          label: '部分退款成功',
          value: 3
        },
        {
          label: '退款失败',
          value: 4
        }
      ]
    }
  },
  {
    label: '下单时间',
    component: 'NDatePicker',
    field: 'createTime',
    componentProps: {
      type: 'datetimerange',
      defaultTime: ['00:00:00', '23:59:59']
    }
  },
  {
    field: 'userAttrType',
    label: '人员属性',
    component: 'dictSelect',
    componentProps: {
      dictCode: 'user_attr_type',
      immediate: true
    },
    show: useAuth().hasAuth('user:attr:type')
  }
];
export enum refundEnum {
  /**
   * 买家申请
   */
  BUYER_APPLY = 10,

  /**
   * 卖家同意
   */
  SELLER_AGREE = 60,

  /**
   * 卖家拒绝
   */
  SELLER_REFUSE = 30,

  /**
   * 退款成功
   */
  REFUND_SUCCESS = 70,
  /**
   * 买家发货
   */
  BUYER_DELIVERY = 65,
  /**
   * 撤回申请
   */
  REVOKE_APPLY = 40
}

export const refundStatus = {
  [refundEnum.BUYER_APPLY]: '买家申请',
  [refundEnum.SELLER_AGREE]: '买家发货',
  [refundEnum.SELLER_REFUSE]: '卖家拒绝',
  [refundEnum.REFUND_SUCCESS]: '退款成功',
  [refundEnum.BUYER_DELIVERY]: '买家发货',
  [refundEnum.REVOKE_APPLY]: '撤回申请'
};

export const TypeText = ['仅退款', '退款退货', '差价退款'];

export const orderColumns: NaiveUI.TableColumn<Api.delivery.OrderRefundSku>[] = [
  {
    title: '退款商品',
    key: 'goods',
    width: 300,
    render: row => {
      const goodsNodes = [
        h(NImage, { src: row.pic, width: 80, height: 80 }),
        h('div', { class: 'ml-2 ' }, [
          h('div', { class: 'text-15px font-semibold' }, row.skuName),
          h('div', { class: 'text-gray' }, `规格：${row.spec || '--'}`)
        ])
      ];
      return h('div', { class: 'flex items-center' }, goodsNodes);
    }
  },
  {
    title: '购买单价（元）',
    key: 'skuPrice',
    width: 150
  },
  {
    title: '购买数量',
    key: 'productCount',
    width: 150,
    render: row => {
      return row.orderItem.prodCount;
    }
  },
  {
    title: '小计/元',
    key: 'productTotalAmount',
    width: 100,
    render: row => {
      return row.orderItem.productTotalAmount;
    }
  },
  {
    title: '退款数量',
    key: 'productCount',
    width: 100
  },
  {
    title: '退款金额',
    key: 'skuPrice',
    width: 100,
    render: row => {
      return (Number(row.skuPrice) * Number(row.productCount)).toFixed(2);
    }
  }
];
// 1-申请原因，2-商家待审核，5-用户待发货，7-待商家收货，10-审核通过，20-驳回，30-退款成功
export enum refundTimeEnum {
  /**
   * 申请原因
   */
  Reason = 1,
  /**
   * 商家待审核
   */
  WaitAudit = 2,
  /**
   * 申请通过
   */
  AuditPass = 3,
  /**
   * 用户待发货
   */
  WaitDelivery = 5,
  /**
   * 待商家收货
   */
  WaitReceive = 7,
  /**
   * 审核通过
   */
  AuditSuccess = 10,
  /**
   * 驳回
   */
  AuditReject = 20,
  /**
   * 退款成功
   */
  RefundSuccess = 30
}

export const refundTime = {
  [refundTimeEnum.Reason]: '申请原因',
  [refundTimeEnum.WaitAudit]: '商家待审核',
  [refundTimeEnum.WaitDelivery]: '用户待发货',
  [refundTimeEnum.WaitReceive]: '待商家收货',
  [refundTimeEnum.AuditSuccess]: '审核通过',
  [refundTimeEnum.AuditReject]: '驳回',
  [refundTimeEnum.RefundSuccess]: '退款成功',
  [refundTimeEnum.AuditPass]: '申请通过'
};
