import UserAPI from "@/api/onlineShop/goodsGroupconfig";

import type { IModalConfig } from "@/components/CURD/types";

const modalConfig: IModalConfig<UserForm> = {
  pageName: "sys:user",
  dialog: {
    title: "新增分组",
    width: 800,
    draggable: true,
  },
  form: {
    labelWidth: 100,
  },
  formAction: function (data: any) {
    if (data.selectgoods) {
      let arr = []
      data.selectgoods.forEach(element => {
        arr.push(element.id)
      });
      data.productIds = arr
    }
    return UserAPI.addunit(data)
  },
  beforeSubmit(data: any) {
    if (data.saleTime) {
      let a = data.saleTime[0]
      let b = data.saleTime[1]
      data.saleStartTime = a
      data.saleEndTime = b
    }
  },
  formItems: [
    {
      label: "分组名称",
      prop: "name",
      rules: [{ required: true, message: "分组名称不能为空", trigger: "blur" }],
      type: "input",
      attrs: {
        placeholder: "请输入分组名称",
      },
    },
    {
      slotName: "addButton",
      prop: "selectgoods",
      attrs: {},
      type: "custom",
      label: "选择商品",
    },

    {
      label: "分组状态",
      prop: "status",
      type: "radio",
      options: [
        { label: "启用", value: 1 },
        { label: "禁用", value: 0 },
      ],
      initialValue: 1,
    }, {
      label: "售卖时间管控",
      prop: "useTime",
      type: "radio",
      options: [
        { label: "启用", value: 1 },
        { label: "禁用", value: 0 },
      ],
      initialValue: 0,
    },

    {
      label: "排列方式",
      prop: "sortMode",
      type: "radio",
      options: [
        { label: "默认", value: '0' },
        { label: "价格由高到低", value: '1' },
        { label: "价格由低到高", value: '2' },
        { label: "销量由高到低", value: '3' },
        { label: "销量由低到高", value: '4' },
      ],
      initialValue: 0,
    },
    {
      label: "分组排序",
      prop: "sort",
      type: "input-number",
      attrs: {
        controlsPosition: "right"
      },
      initialValue: 1,
    },
    {
      slotName: "addmanagementtime",
      prop: "",
      type: "custom",
      label: "",
    },
  ],
};
export interface UserForm {

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