import { isURL } from "@/utils/validate";
const validateUrl = (_, value, callback) => {
  if (value === "") {
    callback();
  } else {
    if (!isURL(value)) {
      callback(new Error("链接格式不正确！"));
    } else {
      callback();
    }
  }
};

const rules = {
  name: [{ required: true, message: "请输入活动名称", trigger: "change" }],
  act_img: [
    {
      type: "array",
      required: true,
      message: "至少上传一张活动图片",
      trigger: "change",
    },
  ],
  act_url: [{ required: false, trigger: "blur", validator: validateUrl }],
};

const formItem = {
  id: "",
  name: "",
  act_img: [],
  act_url: "",
};
const columns = [
  {
    prop: "index",
    label: "顺序",
    type: "index",
    width: "100px",
  },
  {
    prop: "name",
    label: "名称",
    minWidth: "200px",
  },
  {
    prop: "act_img",
    label: "图片",
    _slot_: "act_img",
    minWidth: "300px",
  },
  {
    prop: "act_url",
    label: "超链",
    _slot_: "act_url",
    minWidth: "70px",
  },

  {
    prop: "",
    label: "操作",
    _add_: true,
    fixed: "right",
    _noset_: true,
    width: "100px",
    _slot_: "operation",
  },
];

export { formItem, columns, rules };
