import { h } from 'vue';
import { NFlex, NImage, NTag } from 'naive-ui';
// import { fetchGetAllStoreList } from '@/service/api/goods/desk-category';
import { fetchGetStoreList } from '@/service/api/xsb-manage/store-info';
import { fetchGetDictDataList } from '@/service/api/system-manage';
// import { useAuth } from '@/hooks/business/auth';
import type { FormSchema } from '@/components/zt/Form/types/form';

export const SearchForm: FormSchema[] = [
  {
    label: '业务类型',
    field: 'businessType',
    component: 'ApiSelect',
    componentProps: {
      api: fetchGetDictDataList,
      labelFeild: 'name',
      valueFeild: 'value',
      resultFeild: 'data.list',
      params: {
        typeCode: 'sys_business_type'
      }
    }
  },
  {
    label: '门店名称',
    component: 'ApiSelect',
    field: 'shopId',
    componentProps: {
      api: fetchGetStoreList,
      resultFeild: 'data.list',
      labelFeild: 'shopName',
      valueFeild: 'shopId'
    }
  },

  // {
  //   label: '订单类型',
  //   component: 'NSelect',
  //   field: 'dvyType',
  //   componentProps: {
  //     options: [
  //       {
  //         label: '全部',
  //         value: ''
  //       },
  //       {
  //         label: '快递',
  //         value: 1
  //       },
  //       {
  //         label: '配送',
  //         value: 3
  //       }
  //     ]
  //   }
  // },
  // {
  //   label: '父订单编号',
  //   component: 'NInput',
  //   field: 'parentOrderNumber'
  // },
  {
    label: '订单编号',
    component: 'NInput',
    field: 'orderNumber'
  },
  {
    label: '收货人姓名',
    component: 'NInput',
    field: 'consigneeName'
  },
  {
    label: '收货人电话',
    component: 'NInput',
    field: 'consigneeMobile'
  },
  // {
  //   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 orderStatusEnum {
  /**
   *
   *  待支付
   */
  WAIT_PAY = 0,
  /**
   * 待发货
   */
  WAIT_DELIVERY = 1,
  /**
   * 订单已接单(待拣货)
   */
  ORDER_ACCEPT = 20,
  /**
   * 订单待配送（拣货完成/自提类订单为待自提）
   */
  ORDER_WAIT_DELIVERY = 30,
  /**
   * 订单配送中
   */
  ORDER_DELIVERY = 40,
  /**
   * 订单取消待审核
   */
  ORDER_CANCEL_WAIT_AUDIT = 50,
  /**
   * 订单已取消
   */
  ORDER_CANCEL = 60,
  /**
   * 订单已送达
   */
  ORDER_ARRIVE = 70,
  /**
   * 订单已完成
   */
  ORDER_COMPLETE = 80
}
/**
 * 发货按钮显示状态
 */
export const ShippingButton = [
  orderStatusEnum.WAIT_DELIVERY,
  orderStatusEnum.ORDER_ACCEPT,
  orderStatusEnum.ORDER_DELIVERY,
  orderStatusEnum.ORDER_WAIT_DELIVERY
];
/**
 *  // 0-待支付 1-待发货，20-订单已接单(待拣货),30-订单待配送（拣货完成/自提类订单为待自提）,40-订单配送中
        // ,50-订单取消待审核,60-订单已取消,70-订单已送达,80-订单已完成
 */
export const orderStatus = {
  [orderStatusEnum.WAIT_PAY]: '待支付',
  [orderStatusEnum.WAIT_DELIVERY]: '待发货',
  [orderStatusEnum.ORDER_ACCEPT]: '订单已接单(待拣货)',
  [orderStatusEnum.ORDER_WAIT_DELIVERY]: '订单待配送（拣货完成/自提类订单为待自提）',
  [orderStatusEnum.ORDER_DELIVERY]: '订单配送中',
  [orderStatusEnum.ORDER_CANCEL_WAIT_AUDIT]: '订单取消待审核',
  [orderStatusEnum.ORDER_CANCEL]: '订单已取消',
  [orderStatusEnum.ORDER_ARRIVE]: '订单已送达',
  [orderStatusEnum.ORDER_COMPLETE]: '订单已完成'
};
export enum yppStatusEnum {
  /**
   *
   *  待支付
   */
  WAIT_PAY = 0,
  /**
   * 已支付
   */
  WAIT_DELIVERY = 1,
  /**
   * 出票成功
   */
  SUCCESS = 4,
  /**
   * 出票失败(退款)
   */
  REFUND_FAIL = 7,
  /**
   * 超时未支付（取消）
   */
  TIMEOUT_CANCEL = 8
}
export const yppStatus = {
  [yppStatusEnum.WAIT_PAY]: '待支付',
  [yppStatusEnum.WAIT_DELIVERY]: '已支付',
  [yppStatusEnum.SUCCESS]: '出票成功',
  [yppStatusEnum.REFUND_FAIL]: '出票失败(退款)',
  [yppStatusEnum.TIMEOUT_CANCEL]: '超时未支付（取消）'
};
/**
 // 1:申请退款 2:退款成功 3:部分退款成功 4:退款失败
 *
 */

export const refundStatus = {
  1: '申请退款',
  2: '退款成功',
  3: '部分退款成功',
  4: '退款失败'
};
/**
 *
 * 配送方式
 */

export const dvyStatus = {
  1: '快递',
  2: '自提',
  3: '即时配送'
};

export const orderColumns: NaiveUI.TableColumn<Api.delivery.OrderItemElement>[] = [
  {
    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: 'price',
    width: 100
  },
  {
    title: '数量',
    key: 'prodCount',
    width: 250,
    render: row => {
      const nodes = [h('div', { class: 'mr-2' }, row.prodCount)];
      if (row.refundSuccessCount) {
        nodes.push(h(NTag, { class: 'ml2', type: 'success' }, () => `退款成功：${row.refundSuccessCount}`));
      }
      if (row.refundIngCount && !row.refundSuccessCount) {
        nodes.push(h(NTag, { class: 'ml2', type: 'error' }, () => `售后处理：${row.refundIngCount}`));
      }
      return h(NFlex, { align: 'center' }, () => nodes);
    }
  },
  {
    title: '小计/元',
    key: 'productTotalAmount',
    width: 100
  }
];

export const orderDJKColumns: NaiveUI.TableColumn<Api.delivery.OrderItemElement>[] = [
  {
    title: '商品',
    key: 'goods',
    width: 300,
    render: row => {
      const goodsNodes = [
        h(NImage, { src: row.goodsImg, 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: 'price',
    width: 100
  },
  {
    title: '数量',
    key: 'goodsNum',
    width: 250,
    render: row => {
      const nodes = [h('div', { class: 'mr-2' }, row.goodsNum)];
      if (row.refundSuccessCount) {
        nodes.push(h(NTag, { class: 'ml2', type: 'success' }, () => `退款成功：${row.refundSuccessCount}`));
      }
      if (row.refundIngCount && !row.refundSuccessCount) {
        nodes.push(h(NTag, { class: 'ml2', type: 'error' }, () => `售后处理：${row.refundIngCount}`));
      }
      return h(NFlex, { align: 'center' }, () => nodes);
    }
  },
  {
    title: '小计/元',
    key: 'productTotalAmount',
    width: 100,
    render: (row: any) => {
      return h('div', {}, (row.goodsNum * 1000 * (row.price * 1000)) / 1000);
    }
  }
];

export const orderDJKLogColumns: NaiveUI.TableColumn<Api.delivery.OrderItemElement>[] = [
  {
    title: '时间',
    key: 'createTime'
  },
  {
    title: '操作',
    key: 'operation'
  },
  {
    title: '操作员',
    key: 'operator'
  },
  {
    title: '备注',
    key: 'remark'
  }
];

export const deliveryInfo: FormSchema[] = [
  {
    label: '配送方式',
    component: 'NGradientText',
    field: 'dvyMethod',
    render() {
      return h('div', {}, '快递');
    }
  },
  {
    label: '收货人姓名',
    component: 'NGradientText',
    field: 'receiver',
    render({ model, field }) {
      return h('div', {}, model[field]);
    }
  },
  {
    label: '收货人手机号',
    component: 'NInput',
    field: 'mobile',
    render({ model, field }) {
      return h('div', {}, model[field]);
    }
  },
  {
    label: '收货地址',
    component: 'NInput',
    field: 'address',

    render({ model, field }) {
      return h('div', {}, model[field]);
    }
  }
];

/**
 * 0:用户手动停止充电；1:客户归属地运营商平台停止充电；2:BMS停止充电；3:充电机设备故障；4:连接器断开；其它:自定义
 */

export const chargeMethod = [
  '用户手动停止充电',
  '客户归属地运营商平台停止充电',
  'BMS停止充电',
  '充电机设备故障',
  '连接器断开',
  '其它'
];

export const businessType = {
  XSB: '星闪豹',
  CD: '充电',
  DYY: '电影演出',
  DJK: '大健康',
  XNSP: '虚拟商品',
  JY: '加油'
};
