import UserAPI from "@/api/product/index";
import RoleAPI from "@/api/system/role";
import type { UserPageQuery } from "@/api/system/user";
import type { IContentConfig } from "@/components/CURD/types";
import { id } from "element-plus/es/locale";

const contentConfig: IContentConfig<UserPageQuery> = {
  pageName: "sys:user",
  table: {
    border: true,
    highlightCurrentRow: true,
    rowKey: 'id',
    treeProps: {
      children: 'skuList' // 指定子节点存储的字段为 customChildren
    }
  },
  pagination: {
    background: true,
    layout: "prev,pager,next,jumper,total,sizes",
    pageSize: 20,
    pageSizes: [10, 20, 30, 50],
  },
  indexActionData: {},
  indexAction: async function (params) {
    let obj = { ...params, ...params.times }
    obj.createBeginTime = obj['0']
    obj.createEndTime = obj['1']
    const res = await UserAPI.getPage(obj);
    res.records.forEach((element: any) => {
      if (element.type == "single") {
        delete element.skuList
      }
    });
    return new Promise(function (resolve, reject) {
      return resolve({
        ...res
      })
    })
  },
  modifyAction: function (data) {
    let obj = {
      type: data.isGrounding ? 'sku' : 'product',
      id: data.id,
      isSale: data.value
    }
    return UserAPI.onOff(obj);
  },
  deleteAction: UserAPI.deleteByIds,
  importsAction(data) {
    // 模拟导入数据
    console.log("importsAction", data);
    return Promise.resolve();
  },
  exportsAction: async function (params) {
    // 模拟获取到的是全量数据
    const res = await UserAPI.getPage(params);
    console.log("exportsAction", res.list);
    return res.list;
  },
  pk: "id",
  toolbar: [
    "add",
    //  {
    //   icon: "edit",
    //   text: "库存预警",
    //   type: "info",
    //   name: "custom1",
    //   auth: "import",
    // },
  ],
  cols: [
    // { type: "selection", width: 50, align: "center" },
    { label: "封面图", align: "center", prop: "coverImg", templet: "image" },
    { label: "商品名称", align: "center", prop: "name", },
    { label: "售价", align: "center", prop: "lowPrice" },
    {
      label: "商品规格", align: "center", prop: "type", templet: "custom",
      slotName: "type",
    },
    { label: "库存", align: "center", prop: "stockNumber" },
    { label: "耗材信息", align: "center", prop: "consName" },
    {
      label: "上架",
      align: "center",
      prop: "status",
      templet: "switch",
      slotName: "status",
    },
    {
      label: "操作",
      align: "center",
      fixed: "right",
      width: 280,
      templet: "tool",
      operat: ["edit", "delete"],
    },
  ],
};

export default contentConfig;
