import { hasSpace, isAddr, isChinese, isEmoticon, isMobile, isnumber, isSpecialSymbol } from "@/utils/validate";

export const addressRules = {
  receipt_quantity: [
    {
      required: true,
      trigger: "blur",
      validator: (rule, value, callback) => {
        if (value === "") {
          callback(new Error("不能为空!"));
        } else {
          if (!isnumber(value)) {
            callback(new Error("仅支持整数!"));
          } else {
            callback();
          }
        }
      },
    },
  ],

  contactor: [
    {
      required: true,
      trigger: "blur",
      validator: (rule, value, callback) => {
        if (value === "") {
          callback(new Error("联系人不能为空！"));
        } else {
          if (value.length < 2 || value.length > 10) {
            callback(new Error("联系人规则为2~10位汉字！"));
          } else {
            if (!isChinese(value)) {
              callback(new Error("联系人规则为2~10位汉字！"));
            } else if (isEmoticon(value)) {
              callback(new Error("联系人规则为2~10位汉字！"));
            } else {
              callback();
            }
          }
        }
      }
    },
  ],

  mobile: [
    {
      required: true,
      validator: (rule, value, callback) => {
        if (value === "") {
          callback(new Error("手机号不能为空！"));
        } else {
          if (!isMobile(value)) {
            callback(new Error("手机号格式不正确！"));
          } else {
            callback();
          }
        }
      },
      trigger: "blur",
    },
  ],

  // addr_code: [
  //   {
  //     type: "array",
  //     required: false,
  //     message: "收货省市区不能为空",
  //     trigger: "change",
  //   },
  // ],
  
  addr: [
    {
      required: true,
      trigger: "blur",
      validator: (rule, value, callback) => {
        if (value === "") {
          callback(new Error("详细地址不能为空！"));
        } else {
          if (hasSpace(value)) {
            callback(new Error("系统不允许输入转义字符，请检查后重新输入！"));
          } else if (isSpecialSymbol(value)) {
            callback(new Error("不能使用英文特殊字符！"));
          } else if (isAddr(value)) {
            callback();
          } else {
            callback(new Error("详细地址填写不规范！"));
          }
        }
      }
    },
  ],
};


export const createRules = {
  customerCode:{
    required:true,
    message:'业务公司不能为空',
    trigger:'blur'
  },
  companyName:{
    required:true,
    message:'客户名称不能为空',
    trigger:'blur'
  },
  num:{
    required:true,
    message:'销售数量不能为空',
    trigger:'blur'
  },
  is_determine_price:{
    required:true,
    message:'销售价不能为空',
    trigger:'blur'
  },
  price:{
    required:true,
    message:'采购价不能为空',
    trigger:'blur'
  },
  service_proportion:{
    required:true,
    message:'服务费比例不能为空',
    trigger:'blur'
  },
  expect_service:{
    required:true,
    message:'期望服务费不能为空',
    trigger:'blur'
  },
  brand_id:{
    required:true,
    message:'请选择品牌',
    trigger:'blur'
  },
  preservation_day:{
    required:true,
    message:'有效期不能为空',
    trigger:'blur'
  },
  delivery_day:{
    required:true,
    message:'物流时间不能为空',
    trigger:'blur'
  },
  make_day:{
    required:true,
    message:'生产工期不能为空',
    trigger:'blur'
  },
  tax:{
    required:true,
    message:'税点不能为空',
    trigger:'blur'
  },
  unit_id:{
    required:true,
    message:'请选择单位',
    trigger:'blur'
  },
  cat_id:{
    required:true,
    message:'请选择分类',
    trigger:'blur'
  },
  spec_list:{
    required:true,
    message:'请选择规格',
    trigger:'blur'
  },
  good_name:{
    required:true,
    message:'商品名称不能为空',
    trigger:'blur'
  },
  delivery_place:{
    required:true,
    message:'发货地不能为空',
    trigger:'blur'
  },
  origin_place:{
    required:true,
    message:'产地不能为空',
    trigger:'blur'
  },
  weight:{
    required:true,
    message:'总重量不能为空',
    trigger:'blur'
  },
  supply_area:{
    required:true,
    message:'请选择供货区域',
    trigger:'blur'
  },
  pay_way:{
    required:true,
    message:'请选择付款方式',
    trigger:'blur'
  },
  config:{
    required:true,
    message:'配置要求不能为空',
    trigger:'blur'
  },
  other_config:{
    required:true,
    message:'其他配置要求不能为空',
    trigger:'blur'
  },
  remark:{
    required:true,
    message:'采购备注不能为空',
    trigger:'blur'
  },
  cost_desc:{
    required:true,
    message:'工艺说明不能为空',
    trigger:'blur'
  },
  good_img:{
    required:true,
    message:'请上传商品图片',
    trigger:'blur'
  },
  supplierNo:{
    required:true,
    message:'供应商不能为空',
    trigger:'blur'
  }
}
