import { FormRules } from "element-plus";

export const ladderFormRules: FormRules = {
  key: {
    trigger: "change",
    required: true,
    message: "请选择商品类型"
  },
  value: {
    trigger: "change",
    required: true,
    message: "请选择单位"
  }
};

export const projectFormRules: FormRules = {
  good_name: {
    trigger: "change",
    required: true,
    validator(_, value) {
      if (value === "") return new Error("请输入商品名称");
      return true;
    }
  },
  good_cover_img: {
    trigger: "change",
    required: true,
    message: "请上传封面图",
    validator(_, value) {
      if (value === "") return new Error("请上传封面图");
      return true;
    }
  },
  type: {
    trigger: "change",
    required: true,
    message: "请选择商品类型"
  },
  unit_id: {
    trigger: "change",
    required: true,
    message: "请选择单位"
  },
  price: {
    trigger: "change",
    required: true,
    validator(_, value) {
      // console.log(typeof value + "--售价--" + value);

      if (value === "") return new Error("请输入售价");
      return true;
    }
  },
  moq: {
    trigger: "change",
    required: true,
    validator(_, value) {
      if (typeof value != "number") return new Error("请输入起订量");
      const num = Number(value + "");
      if (num < 1) return new Error("起订量不能低于1");
      return true;
    }
  },
  step: {
    trigger: "change",
    required: true,
    validator(_, value) {
      if (typeof value != "number") return new Error("请输入步长");
      const num = Number(value + "");
      if (num < 1) return new Error("步长不能低于1");
      return true;
    }
  },
  good_banner_img: {
    trigger: "change",
    type: "array",
    required: true,
    validator(_, value) {
      if (value.length === 0) return new Error("请上传轮播图");
      if (value.length < 3 || value.length > 10)
        return new Error("轮播图应为3~10张！");
      return true;
    }
  },
  good_img: {
    trigger: "change",
    type: "array",
    required: true,
    validator(_, value) {
      if (value.length === 0) return new Error("请上传详情图");
      if (value.length > 20) return new Error("详情图不得超过20张！");
      return true;
    }
  },
  good_param: {
    trigger: "change",
    type: "array",
    required: true,
    validator(_, value) {
      if (value === "") return new Error("请输入商品参数");
      return true;
    }
  },
  good_remark: {
    trigger: "change",
    required: true,
    validator(_, value) {
      if (!value) return new Error("请输入备注");
      return true;
    }
  }
};
