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

import type { IModalConfig } from "@/components/CURD/types";
import { DeviceEnum } from "@/enums/DeviceEnum";
import { useAppStore } from "@/store";

const modalConfig: IModalConfig<UserForm> = {
  pageName: "sys:user",
  // component: "drawer",
  dialog: {
    title: "编辑单位",
    width: 800,
    draggable: true,
  },

  pk: "id",
  formAction: function (data: any) {
    if (data.selectgoods) {
      let arr = []
      data.selectgoods.forEach(element => {
        arr.push(element.id)
      });
      data.productIds = arr
    }
    // return UserAPI.update(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,
      watch() {
      }
    },

    {
      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"
      },
    },
    {
      type: 'time-picker',
      prop: "saleTime",
      label: "",
      attrs: {},
      hidden: true,
    },
  ],
};
/** 用户表单类型 */
interface UserForm {
  /** 用户头像 */
  avatar?: string;
  /** 部门ID */
  deptId?: number;
  /** 邮箱 */
  email?: string;
  /** 性别 */
  gender?: number;
  /** 用户ID */
  id?: number;
  /** 手机号 */
  mobile?: string;
  /** 昵称 */
  nickname?: string;
  /** 角色ID集合 */
  roleIds?: number[];
  /** 用户状态(1:正常;0:禁用) */
  status?: number;
  /** 用户名 */
  username?: string;
}

export default reactive(modalConfig);
