import Api from "@/api/account/payType";
import type { IContentConfig } from "@/components/CURD/types";
import { ElMessage } from "element-plus";

const contentConfig: IContentConfig = {
  pageName: "sys:user",
  // ✅ 开启拖动排序
  rowDraggable: true,
  table: {
    border: true,
    highlightCurrentRow: true,

    // ✅ 拖动完成后调用接口
    onRowDrop: async ({ row, oldIndex, newIndex }) => {
      try {
        await Api.sort({
          id: row.id,
          oldIndex,
          newIndex,
        });
        ElMessage.success("排序成功");
      } catch (e) {
        ElMessage.error("排序失败");
      }
    },
  },
  pagination: false,
  indexAction: function (params) {
    return Api.getList();
  },
  modifyAction: async function (data) {
    const res = await Api.edit(data);
    ElMessage.success(res ? "修改成功" : "修改失败");
    return res;
  },
  pk: "id",
  toolbar: [],
  defaultToolbar: ["refresh", "filter", "search"],
  cols: [
    // ✅ 拖动图标列
    {
      label: "排序",
      align: "center",
      width: 60,
      templet: "custom", // 拖动把手
      prop: "sort",
    },

    {
      label: "图标",
      align: "center",
      prop: "icon",
      templet: "image",
    },
    {
      label: "收银方式",
      align: "center",
      prop: "payName",
    },
    {
      label: "收银类型",
      align: "center",
      prop: "payType",
    },
    {
      label: "是否显示",
      align: "center",
      prop: "isDisplay",
      templet: "switch",
    },
    {
      label: "操作",
      align: "center",
      fixed: "right",
      width: 280,
      templet: "tool",
      operat: [],
    },
  ],
};

export default contentConfig;