import shopUserApi, { type editMoneyRequest } from "@/api/account/shopUser";
import type { IModalConfig } from "@/components/CURD/types";
import { min } from "lodash";

// 增减或者减少余额的类型
export interface optuions {
  label: string;
  value: string | number;
}
export const addOptions: optuions[] = [
  { label: '增加充值', value: 'adminIn' },
  { label: '增加消费退款', value: 'adminRefund' },
]
export const reduceOptions: optuions[] = [
  { label: '扣除消费', value: 'adminOut' },
  { label: '扣除充值退款', value: 'adminInOut' },
]


const modalConfig: IModalConfig<editMoneyRequest> = {
  pageName: "sys:user",
  dialog: {
    title: "增减余额",
    width: 800,
    draggable: true,
  },
  pk: "id",
  form: {
    labelWidth: 140,
  },
  formAction: function (data) {
    return shopUserApi.editMoney(data.shopid, data);
  },
  beforeSubmit(data) {
    console.log("提交之前处理", data);
  },
  formItems: [
    {
      label: "用户昵称",
      prop: "nickName",
      rules: [{ required: false, message: "请输入用户昵称", trigger: "blur" }],
      type: "input",
      disabled: true,
      attrs: {
        placeholder: "请输入用户昵称",
      },
      col: {
        xs: 24,
        sm: 12,
      },
    },
    {
      label: "钱包余额",
      prop: "amount",
      disabled: true,
      rules: [{ required: false, message: "", trigger: "blur" }],
      type: "input",
      attrs: {
        placeholder: "",
      },
      col: {
        xs: 24,
        sm: 12,
      },
    },
    {
      type: "radio",
      label: "增减余额",
      prop: "type",
      rules: [{ required: true, message: "增减余额", trigger: "blur" }],
      initialValue: 1,
      options: [
        { label: '增加', value: 1 },
        { label: '减少', value: 0 },
      ],
      col: {
        xs: 24,
        sm: 12,
      },
      watch() {

      }
    },
    {
      label: "金额",
      prop: "money",
      rules: [{ required: false, message: "请输入要增加或者减少的金额", trigger: "blur" }],
      type: "input-number",
      attrs: {
        placeholder: "请输入要增加或者减少的金额",
        min: 0,
      },
      col: {
        xs: 24,
        sm: 12,
      },
      initialValue: 0
    },
    {
      label: "类型",
      prop: "bizEnum",
      rules: [{ required: true, message: "请选择类型", trigger: "blur" }],
      type: "radio-button",
      attrs: {
        placeholder: "请选择类型",
      },
      options: addOptions,
    },
    {
      label: "备注",
      prop: "remark",
      rules: [{ required: false, message: "请输入备注", trigger: "blur" }],
      type: "textarea",
      attrs: {
        placeholder: "请输入备注",
      },
    },
    // {
    //   label: "钱包余额",
    //   prop: "amount",
    //   rules: [{ required: false, message: "请输入钱包余额", trigger: "blur" }],
    //   type: "input-number",
    //   attrs: {
    //     placeholder: "请输入钱包余额",
    //   },
    //   col: {
    //     xs: 24,
    //     sm: 12,
    //   },
    // },
    // {
    //   type: "radio",
    //   label: "是否会员",
    //   prop: "isVip",
    //   options: [
    //     { label: '是', value: 1 },
    //     { label: '否', value: 0 },
    //   ],
    // },
  ],
};


// 如果有异步数据会修改配置的，推荐用reactive包裹，而纯静态配置的可以直接导出
export default reactive(modalConfig);
