import { ContentConfig } from "/@/components/PageContent";
import { httpList, httpAdd } from "/@/api/InvoiceSales/refund";

import dayjs from "dayjs";
import { ElTag, ElImage } from "element-plus";
import { h } from "vue";
import { RETRUN_STATUS } from "/@/utils/details/refund";
import { refund_type } from "./search.config";
import { xs_order_source_options } from "/@/utils/status";

const columns = [
  {
    type: "selection",
    width: 55,
    hide: ({ checkList }) => !checkList.includes("勾选列")
  },
  {
    label: "序号",
    type: "index",
    width: 70,
    hide: ({ checkList }) => !checkList.includes("序号列")
  },
  {
    label: "退款编号",
    prop: "returnCode",
    width: "120px"
  },
  {
    label: "资金认领编号",
    prop: "logNo",
    width: 120
  },
  {
    label: "销售单编号",
    prop: "orderCode",
    width: "120px"
  },
  {
    label: "销售来源",
    prop: "qrdSource",
    width: "120px",
    cellRenderer({ row }) {
      return h(ElTag, null, {
        default: () =>
          xs_order_source_options.find(s => s.value === row.qrdSource)?.label
      });
    }
  },
  {
    label: "商品编号",
    prop: "goodNo",
    width: "120px"
  },
  {
    label: "商品名称",
    prop: "goodName",
    width: "120px"
  },
  // {
  //   label: "商品来源",
  //   prop: "returnCode",
  //   width: "120px"
  // },
  // {
  //   label: "订单所属平台",
  //   prop: "returnCode",
  //   width: "120px"
  // },
  // {
  //   label: "平台订单编号",
  //   prop: "returnCode",
  //   width: "120px"
  // },
  {
    label: "退款回执",
    prop: "return_img",
    width: "120px",
    cellRenderer: ({ row }) => {
      return h(ElImage, {
        src: row.return_img,
        style: { height: "20px" },
        previewSrcList: [row.return_img],
        previewTeleported: true
      });
    }
  },
  {
    label: "退款原因",
    width: "120px",
    prop: "return_reason"
  },
  {
    label: "申请人id",
    width: "120px",
    prop: "apply_id"
  },
  {
    label: "申请人",
    prop: "apply_name"
  },
  {
    label: "退款类型",
    prop: "status",
    width: "120px",
    cellRenderer: ({ row }) => {
      return h(ElTag, null, {
        default: () =>
          refund_type.find(s => s.value === row.type)?.label || "--"
      });
    }
  },
  {
    label: "状态",
    prop: "status",
    cellRenderer: ({ row }) => {
      return h(ElTag, null, {
        default: () =>
          RETRUN_STATUS.find(s => s.value === row.status)?.label || "--"
      });
    }
  },
  {
    label: "退款时间",
    prop: "addtime",
    formatter: ({ addtime }) => dayjs(addtime).format("YYYY-MM-DD HH:mm:ss")
  },
  {
    label: "操作",
    fixed: "right",
    width: 80,
    slot: "operation"
  }
];

const contentConfig: ContentConfig = {
  title: "退款申请管理",
  powers: ["001", "002", "003", "004", "005", "006", "007", "008"],
  columns,
  apis: {
    httpList,
    httpAdd
  }
};

export default contentConfig;
