import {
  isLicense,
  isMobile,
  isqz,
  isSpecialSymbol,
  hasSpace,
  isAddr,
  validEmail
} from '/@/utils/validator'

import { isqzf, isqz, iszf, isz, isMobile } from "/@/utils/validate";

export const statusOptions = [
  { value: "0", label: "禁用", type: 'warning' },
  { value: "1", label: "启用", type: 'success' },
];

export const isUpgradeOptions = [
  { value: '1', label: '已升级', type:'success' },
  { value: '0', label: '未升级', type: 'info' }
]


export const orcStatusOptions = [
  { value: '0', label: '未上传', type:'info' },
  { value: '1', label: '识别成功', type:'success' },
  { value: '2', label: '识别失败', type:'warning' },
]


export const coopStateoptions = [
  { value: '0', label: '白名单' },
  { value: '1', label: '黑名单' }
]


export const sourceOptions = [
  { value: '0', label: '客户提供' },
  { value: '1', label: '供应商' },
  { value: '2', label: '公司开发' }
]

export const applicationTypeOptions = [
  { value: '0', label: '正式供应商' },
  { value: '1', label: '临时供应商' },
]

export const categoryOptions = [
  { value: '0', label: '单品类供应商' },
  { value: '1', label: '多品类供应商' },
]

export const deliveryWayOptions = [
  { value: '0', label: '供应商发货' },
  { value: '1', label: '公司自提' },
]


export const supplierTypeOptions = [
  { value: '0', label: '生产厂家' },
  { value: '1', label: '代理商' },
  { value: '2', label: '经销商' },
  { value: '3', label: '分销商' },
  { value: '4', label: '电商平台' }
]


export const supplierLevelOptions = [
  { value: '2', label: '生产厂家' },
  { value: '0', label: '一级代理商' },
  { value: '1', label: '二级代理商' }
]


export const payTypeOptions = [
  { value: '0', label: '现结' },
  { value: '1', label: '月清' },
  { value: '2', label: '双月清' }
]

export const taxpayerOptions = [
  { value: '0', label: '一般纳税人' },
  { value: '1', label: '农户' },
  { value: '2', label: '合作社' },
  { value: '3', label: '个人' },
  { value: '4', label: '小规模' }
]

const basic = {
  required: true,
  message: "联系电话格式不正确"
};

export const contactOptions = [
  {
    value: "0",
    label: "区-固-分",
    rule: {
      ...basic,
      validator(_, value) {
        return isqzf(value);
      }
    }
  },
  {
    value: "1",
    label: "区-固",
    rule: {
      ...basic,
      validator(_, value) {
        return isqz(value);
      }
    }
  },
  {
    value: "2",
    label: "固-分",
    rule: {
      ...basic,
      validator(_, value) {
        return iszf(value || "");
      }
    }
  },
  {
    value: "3",
    label: "固",
    rule: {
      ...basic,
      validator(_, value) {
        return isz(value || "");
      }
    }
  },
  {
    value: "4",
    label: "手机号",
    rule: {
      ...basic,
      validator(_, value) {
        return isMobile(value || "");
      }
    }
  }
];

const validateLicense = (rule, value, callback) => {
  if (value !== '' || !value) {
    if (!isLicense(value)) {
      callback(new Error('统一社会信用代码不正确！'))
    } else {
      callback()
    }
  } else {
    callback(new Error('请输入统一社会信用代码！'))
  }
}
const validatemobile = (rule, value, callback) => {
  if (value === '' || !value) {
    callback(new Error('手机号不能为空！'))
  } else {
    if (!isMobile(value)) {
      callback(new Error('手机号格式不正确！'))
    } else {
      callback()
    }
  }
}
const validatetelephone = (rule, value, callback) => {
  if (value === '' || !value) {
    callback()
  } else {
    if (isqz(value)) {
      callback()
    } else {
      callback(new Error('规则为区号[0+2~3位]-固定电话[7~8位]！'))
    }
  }
}
const validateAddr = (rule, value, callback) => {
  if (value === '' && 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('详细地址填写不规范！'))
    }
  }
}
const validateEmail = (rule, value, callback) => {
  if (value === '' && value) {
    callback(new Error('邮箱不能为空！'))
  } else {
    if (!validEmail(value)) {
      callback(new Error('邮箱格式不正确！'))
    } else {
      callback()
    }
  }
}

export const rules = {
  coop_state: [{ required: true, message: '请选择合作状态', trigger: 'change' }],
  source: [{ required: true, message: '请选择供应商来源', trigger: 'change' }],

  type: [{ required: true, message: '请选择申请类型', trigger: 'change' }],
  category: [{ required: true, message: '请选择所属类别', trigger: 'change' }],
  delivery_way: [{ required: true, message: '请选择物流方式', trigger: 'change' }],

  supplier_type: [
    { required: true, message: '请选择供应商类型', trigger: 'change' }
  ],
  level: [{ required: true, message: '请选择供应商级别', trigger: 'change' }],
  pay_type: [{ required: true, message: '请选择支付方式', trigger: 'change' }],
  personid: [
    {
      required: true,
      message: '请选择负责人',
      trigger: 'change'
    }
  ],
  contactor: [{ required: true, message: '姓名不能为空', trigger: 'blur' }],
  mobile: [{ required: true, validator: validatemobile, trigger: 'blur' }],
  email: [{ required: true, validator: validateEmail, trigger: 'blur' }],
  telephone: [{ required: false, validator: validatetelephone, trigger: 'blur' }],
  position: [{ required: true, message: '职位不能为空', trigger: 'blur' }],
  registercode: [{ required: true, validator: validateLicense, trigger: 'blur' }],
  name: [{ required: true, message: '供应商名称不能为空', trigger: 'blur' }],
  nature: [{ required: true, message: '公司类型不能为空', trigger: 'change' }],
  addr: [{ required: true, validator: validateAddr, trigger: 'blur' }],
  legaler: [{ required: true, message: '法人代表不能为空', trigger: 'blur' }],
  registertime: [
    { required: true, message: '成立时间不能为空', trigger: 'change' }
  ],
  scope: [{ required: true, message: '营业执照不能为空', trigger: 'blur' }],
  legaler_type: [{ required: true, message: '请选择纳税人资质', trigger: 'change' }]
}



export const upperRules = {
  inv_bank: [
    {
      required: true,
      message: '银行名称不能为空！',
      trigger: 'blur'
    }
  ],
  inv_bankNo: [
    {
      required: true,
      message: '银行卡号不能为空！',
      trigger: 'blur'
    }
  ],
  

  inv_addr: [{ required: true, message: '联系地址不能为空！', trigger: 'blur' }],
  invoice_title: [{ required: true, message: '公司抬头不能为空', trigger: 'blur' }],
  invoice_mobile: [{ required: true, message: '联系电话不能为空', trigger: 'blur' }]
}


export const initialData = {
  id: '',
  code: '',
  coop_state: '',
  source: '',
  type: '',
  category: '',
  delivery_way: '',
  supplier_type: '',
  level: '',
  pay_type: '',
  personid: '',
  license_img: '',
  prove_img: [],
  contactor: "",
  mobile: "",
  email: "",
  position: "",
  telephone: "",
  name: "",
  registercode: "",
  nature: "",
  legaler: "",
  registertime: "",
  addr: "",
  scope: "",
  person: '',
  invoice_code: '',
  legaler_type: '',
  lead_prove: ''
}
