import { isChinese, isEmoticon, isMobile } from "/@/utils/validator";

export const statusOptions = [
  { value: "0", label: "待发货", type: 'warning' },
  { value: "1", label: "待发货完成", type: 'warning' },
  { value: "2", label: "发货已完成", type: 'success' },
  { value: "3", label: "订单已取消", type: 'danger' }
];
export const platformTypeOptions = [
  { value: '1', label: 'toB' },
  { value: '2', label: 'toC' }
];
export const xsOrderSourceOptions = [
  { value: "1", label: "直接下单" },
  { value: "2", label: "竞价转单" },
  { value: "3", label: "项目转单" },
  { value: "4", label: "平台导入" },
  { value: "5", label: "有赞平台" },
  { value: "6", label: "售后补换货" },
  { value: "7", label: "报备转单" },
  { value: "9", label: "采销录单" },
];
export const xsOrderTypeOptions = [
  { value: "1", label: "库存商品" },
  { value: "2", label: "非库存商品" },
  { value: "3", label: "反馈商品" },
  { value: "4", label: "报备商品" },
];
function validatecontactor(_, value, callback){
  if(value === '' || !value){
    callback(new Error('联系人不能为空！'))
  } else {
    if(value.length < 2 || value.length > 10){
      callback(new Error('联系人规则为2~10位汉字或字母!'))
    } else {
      const isOk = value.split('').every(s => isChinese(s) || /^[A-Za-z]+$/.test(s))
      if(!isOk){
        callback(new Error('联系人规则为2~10位汉字或字母!'))
      } else if(isEmoticon(value)){
        callback(new Error('联系人规则为2~10位汉字或字母!'))
      } else {
        callback()
      }
    }
  }
}
function validatemobile(_, value, callback){
  if(value === "" || !value) {
    callback(new Error("手机号不能为空！"));
  } else {
    if(!isMobile(value)){
      callback(new Error('手机号格式不正确！'))
    } else {
      callback()
    }
  }
}
export const rules = {
  receipt_quantity: [{ required: true, trigger: 'blur', message: '收货数量不能为空' }],
  contactor: [{ required: true, trigger: 'blur', validator: validatecontactor }],
  mobile: [{ required: true, trigger: 'blur', validator: validatemobile }],
  addr_code: [{ required: true,  message: '收货省市区不能为空', trigger: 'change'}],
  addr: [{ required: true,  message: '收货省市区不能为空', trigger: 'blur' }]
}
