/**
 * 资金退款详情
 */
import { h } from "vue";
import { ElImage, ElTag } from "element-plus";
import { createTooltip } from "/@/utils/tootip";
import { DescriptionColumns } from "/@/components/BasicDescriptions";
import { refundTypeOptions, refundStatusOptions } from "./_options";

export const refundColumns: DescriptionColumns = [
  {
    label: "退款编码",
    span: 6,
    field: "returnCode"
  },
  {
    label: "资金认领编码",
    span: 6,
    field: "logNo"
  },
  {
    label: "资金编码",
    span: 6,
    field: "tradNo"
  },
  {
    label: "退款类型",
    field: "type",
    span: 6,
    render(type) {
      return h(ElTag, null, {
        default: () =>
          refundTypeOptions.find(t => String(t.value) === String(type))?.label
      });
    }
  },
  {
    label: "退款状态",
    field: "status",
    span: 6,
    render(status) {
      return h(ElTag, null, {
        default: () =>
          refundStatusOptions.find(s => String(s.value) === String(status))
            ?.label
      });
    }
  },
  {
    label: "申请人",
    field: "apply_name",
    span: 6,
    render: (apply_name, { apply_id }) =>
      createTooltip(apply_name, "申请人ID : " + apply_id, 90)
  },
  {
    label: "付款公司",
    span: 6,
    field: "trade_out"
  },
  {
    label: "退款时间",
    span: 6,
    field: "addtime"
  },
  {
    label: "交易公司",
    span: 6,
    field: "trade_out"
  },
  {
    label: "收款公司",
    span: 6,
    field: "trade_in"
  },
  {
    label: "交易银行",
    span: 6,
    field: "trade_bank"
  },
  {
    label: "总金额",
    span: 6,
    field: "total_fee"
  },
  {
    label: "余额",
    span: 6,
    field: "balance"
  },
  {
    label: "已认领金额",
    span: 6,
    field: "used_fee"
  },
  {
    label: "认领金额",
    span: 6,
    field: "log_total_fee"
  },
  {
    label: "退款回执",
    field: "return_img",
    span: 6,
    render(img_url) {
      const imgs = img_url ? img_url.split(",") : [];
      return imgs.map(url => {
        return h(ElImage, {
          src: url ,
          style: { height: "20px" },
          previewSrcList: [url ],
          previewTeleported: true,
          'text-key':"91110113MA028K5Y7Y"
        });
      });
    }
  },
  {
    label: "退款原因",
    field: "return_reason",
    span: 6
  },
  {
    label: "备注",
    span: 6,
    field: "remark"
  }
];

const CAPITAL_STATUS = [
  {
    value: "1",
    label: "待审批"
  },
  {
    value: "2",
    label: "审批通过"
  },
  {
    value: "3",
    label: "审批驳回"
  },
  {
    value: "4",
    label: "已解除认领"
  },
  {
    value: "5",
    label: "已取消认领"
  }
];

//认领详情描述列表
export const CAPITAL_COLUMNS: DescriptionColumns = [
  {
    field: "logNo",
    label: "编码",
    width: "180px",
    span: 6
  },
  {
    field: "status",
    label: "状态",
    render(status) {
      return h(ElTag, null, {
        default: () =>
          CAPITAL_STATUS.find(s => s.value === status)?.label || "---"
      });
    }
  },
  {
    field: "addtime",
    label: "认领时间",
    span: 6
  },
  {
    field: "used_fee",
    label: "资金使用金额",
    width: "130px",
    span: 6
  },
  {
    field: "remark",
    label: "备注",
    span: 24
  }
];

export const status_options = [
  {
    label: "未认领",
    value: "1"
  },
  {
    label: "部分认领",
    value: "2"
  },
  {
    label: "已认领",
    value: "3"
  }
];

export const public_columns = [
  {
    label: "资金编码",
    span: 24,
    field: "tradNo"
  },
  {
    label: "状态",
    field: "status",
    slot: "status",
    span: 24,
    render(status) {
      return h(
        ElTag,
        { size: "small" },
        {
          default: () =>
            status_options.find(s => s.value === String(status))?.label
        }
      );
    }
  },
  {
    label: "收入金额",
    span: 24,
    field: "total_fee"
  },
  {
    label: "未认领金额",
    span: 24,
    field: "balance"
  },
  {
    label: "已认领金额",
    span: 24,
    field: "used_fee"
  },
  {
    label: "交易用途",
    span: 24,
    field: "trade_used"
  },
  {
    label: "新建时间",
    span: 24,
    field: "addtime"
  }
];

//收款方
export const description_columns_in = [
  {
    label: "收款公司编码",
    field: "companyNo",
    span: 24
  },
  {
    label: "收款公司名称",
    span: 24,
    field: "companyName"
  },
  {
    label: "收款公司账户",
    span: 24,
    field: "trade_in_account"
  }
];

//付款方
export const description_columns_out = [
  {
    label: "付款单位名称",
    span: 24,
    field: "trade_out"
  },
  {
    label: "账户",
    span: 24,
    field: "trade_account"
  },
  {
    label: "交易时间",
    span: 24,
    field: "trade_time"
  },
  {
    label: "交易行名",
    span: 24,
    field: "trade_bank"
  },
  {
    label: "付款方省市",
    span: 24,
    field: ""
  }
];
