import { isSpecialSymbol, hasSpace } from '@/utils/validate'

// 是否定制
const options1 = [
  { id: '0', name: '否' },
  { id: '1', name: '是' }
]
// 专属类型
const options2 = [
  { id: '0', name: '非泰康' },
  { id: '1', name: '泰康' }
]
// 销售权限
const options3 = [
  { id: '0', name: '无销售权限' },
  { id: '1', name: '有销售权限' }
]

// 是否库存品
const options4 = [
  { id: '0', name: '非库存品' },
  { id: '1', name: '库存品' }
]
// 是否启用实时金价
const options5 = [
  { id: '0', name: '否' },
  { id: '1', name: '是' }
]
// 供货区域
const options6 = [
  { id: '1', name: '全国' },
  { id: '2', name: '全国除偏远' }
]
// 是否启用阶梯
const options7 = [
  { id: '0', name: '否' },
  { id: '1', name: '是' }
]

// 有无工差
const options8 = [
  { id: '0', name: '无工差' },
  { id: '1', name: '有工差' }
]
// 配置要求
const options9 = ['证书', '包装盒', '绒布袋', '标签', '其他']
const listCol = [
  { type: 'selection', fixed: 'left', _noset_: true },
  {
    prop: 'spuCode',
    label: '编号',
    width: '160px'
  },
  {
    prop: 'good_thumb_img',
    label: '图片',
    _slot_: 'good_thumb_img',
    width: '45px'
  },
  {
    prop: 'good_name',
    label: '名称',
    'min-width': '160px'
  },
  {
    prop: 'cat_name',
    label: '分类'
  },
  {
    prop: 'brand_name',
    label: '品牌'
  },
  {
    prop: 'isonline',
    label: '是否上线',
    _slot_: 'isonline',
    width: '70px'
  },
  {
    prop: 'status',
    label: '状态',
    _slot_: 'status',
    width: '118px'
  },
  {
    prop: 'supplierNo',
    label: '供应商编号',
    width: '110px'
  },
  {
    prop: 'supplier_name',
    label: '供应商名称',
    width: '110px'
  },
  {
    prop: 'companyNo',
    label: '业务公司编号',
    width: '110px'
  },
  {
    prop: 'company',
    label: '业务公司名称',
    width: '110px'
  },
  {
    prop: 'company_name',
    label: '创建人部门',
    minWidth: '150px'
  },
  {
    prop: 'creater',
    label: '创建人',
    width: '70px'
  },

  {
    prop: 'addtime',
    label: '创建时间',
    width: '140px'
  },
  {
    prop: '',
    label: '操作',
    fixed: 'right',
    _noset_: true,
    width: '200px',
    _slot_: 'operation'
  }
]
const validate_num = (rule, value, callback) => {
  const { required } = rule
  if (required && value === '') {
    callback(new Error('不能为空！'))
  } else {
    callback()
  }
}
const validate_num_0 = (rule, value, callback) => {
  const { required } = rule
  if (required && value === '') {
    callback(new Error('不能为空！'))
  } else if (
    required &&
    (value === '0' ||
      value === '0.' ||
      value === '0.0' ||
      value === '0.00' ||
      value === '0.000')
  ) {
    callback(new Error('不能为零！'))
  } else {
    callback()
  }
}
const validate_good_img = (rule, value, callback) => {
  const { required } = rule
  if (required && value.length == 0) {
    callback(new Error('请上传商品主图！'))
  } else if (required && (value.length < 3 || value.length > 10)) {
    callback(new Error('商品主图应为3~10张！'))
  } else {
    callback()
  }
}
const validate_desc = (rule, value, callback) => {
  const { required } = rule
  if (required && value.length == 0) {
    callback(new Error('不能为空！'))
  } else if (isSpecialSymbol(value)) {
    callback(new Error('不能使用英文特殊字符！'))
  } else {
    callback()
  }
}
const validate_good_name = (rule, value, callback) => {
  const { required } = rule
  if (required && value.length == 0) {
    callback(new Error('不能为空！'))
  } else if (hasSpace(value)) {
    callback(new Error('不能出现回车/换行符！'))
  } else if (isSpecialSymbol(value)) {
    callback(new Error('不能使用英文特殊字符！'))
  } else {
    callback()
  }
}
const rules = {
  cat_id: [
    {
      type: 'array',
      required: true,
      message: '请选择商品分类',
      trigger: 'change'
    }
  ],
  brandid: [
    {
      type: 'array',
      required: true,
      message: '请选择商品品牌',
      trigger: 'change'
    }
  ],
  noble_weight: [
    {
      required: true,
      validator: validate_num_0,
      trigger: 'blur'
    }
  ],
  weight: [
    {
      required: true,
      validator: validate_num,
      trigger: 'blur'
    }
  ],
  good_type: [
    {
      required: true,
      message: '请选择是否定制',
      trigger: 'change'
    }
  ],
  is_stock: [
    {
      required: true,
      message: '请选择是否库存品',
      trigger: 'change'
    }
  ],
  company_id: [
    {
      required: true,
      message: '请选择业务公司',
      trigger: 'change'
    }
  ],
  supplierNo: [
    {
      type: 'array',
      required: true,
      message: '请选择供应商',
      trigger: 'change'
    }
  ],
  is_auth: [
    {
      required: true,
      message: '请选择是否有权限销售',
      trigger: 'change'
    }
  ],
  tax: [
    {
      required: true,
      message: '请选择税率',
      trigger: 'change'
    }
  ],
  good_name: [
    {
      required: true,
      validator: validate_good_name,
      trigger: 'blur'
    }
  ],
  unit: [
    {
      type: 'array',
      required: true,
      message: '请输入商品单位',
      trigger: 'blur'
    }
  ],
  is_exclusive: [
    {
      required: true,
      type: 'array',
      message: '请选择专属类型',
      trigger: 'change'
    }
  ],
  noble_metal: [
    {
      required: true,
      message: '请选择贵金属种类',
      trigger: 'change'
    }
  ],
  is_gold_price: [
    {
      required: true,
      message: '请选择是否启用实时金价',
      trigger: 'change'
    }
  ],
  moq: [
    {
      required: true,
      validator: validate_num,
      trigger: 'blur'
    }
  ],
  stock_moq: [
    {
      required: true,
      validator: validate_num_0,
      trigger: 'blur'
    }
  ],
  customized: [
    {
      required: true,
      validator: validate_num,
      trigger: 'blur'
    }
  ],
  after_sales: [
    {
      required: true,
      message: '售后说明不能为空',
      trigger: 'blur'
    },
    {
      required: true,
      validator: validate_desc,
      trigger: 'blur'
    }
  ],
  // isSpecialSymbol
  good_remark: [
    {
      required: true,
      message: '商品备注不能为空',
      trigger: 'blur'
    },
    {
      required: true,
      validator: validate_desc,
      trigger: 'blur'
    }
  ],
  // 包装/发货/图片
  packing_list: [
    {
      required: true,
      message: '请输入包装清单',
      trigger: 'blur'
    }
  ],
  packing_way: [
    {
      required: true,
      message: '请输入包装方式',
      trigger: 'blur'
    }
  ],

  packing_spec: [
    {
      required: true,
      message: '请输入装箱规格',
      trigger: 'blur'
    }
  ],
  packing_weight: [
    {
      required: true,
      message: '请输入装箱重量',
      trigger: 'blur'
    }
  ],
  packing_szie: [
    {
      required: true,
      message: '请输入装箱尺寸',
      trigger: 'blur'
    }
  ],
  supply_area: [
    {
      required: true,
      message: '请选择供货区域',
      trigger: 'change'
    }
  ],
  delivery_place: [
    {
      type: 'array',
      required: true,
      message: '请选择发货地',
      trigger: 'change'
    }
  ],
  origin_place: [
    {
      type: 'array',
      required: true,
      message: '请选择产地',
      trigger: 'change'
    }
  ],
  delivery_day: [
    {
      required: true,
      message: '请输入物流时间',
      trigger: 'blur'
    }
  ],
  lead_time: [
    {
      required: true,
      message: '请输入供货周期',
      trigger: 'blur'
    }
  ],
  sample_day: [
    {
      required: true,
      message: '请输入调样周期',
      trigger: 'blur'
    }
  ],
  packing_size: [
    {
      required: true,
      message: '请输入装箱尺寸',
      trigger: 'blur'
    }
  ],
  good_size: [
    {
      required: true,
      message: '请输入商品尺寸',
      trigger: 'blur'
    }
  ],
  good_thumb_img: [
    {
      required: true,
      message: '请上传商品缩略图',
      trigger: 'change'
    }
  ],
  good_img: [
    {
      type: 'array',
      required: true,
      validator: validate_good_img,
      trigger: 'change'
    }
  ],
  good_info_img: [
    {
      type: 'array',
      required: true,
      message: '至少上传一张商品详情介绍图',
      trigger: 'change'
    }
  ],
  demo_fee: [
    {
      required: true,
      validator: validate_num,
      trigger: 'blur'
    }
  ],
  is_diff: [
    {
      required: true,
      message: '请选择有无工差',
      trigger: 'change'
    }
  ],
  config: [
    {
      required: true,
      type: 'array',
      message: '请选择配置要求',
      trigger: 'change'
    }
  ],
  other_config: [
    {
      required: true,
      message: '其他要求不能为空',
      trigger: 'blur'
    }
  ],
  open_fee: [
    {
      required: true,
      validator: validate_num,
      trigger: 'blur'
    }
  ],
  sample_fee: [
    {
      required: true,
      validator: validate_num,
      trigger: 'blur'
    }
  ],
  market_price: [
    {
      required: true,
      validator: validate_num,
      trigger: 'blur'
    }
  ],

  cgd_gold_price: [
    {
      required: true,
      validator: validate_num,
      trigger: 'blur'
    }
  ],
  craft_desc: [
    {
      required: false,
      validator: validate_desc,
      trigger: 'blur'
    }
  ]

  // is_step: {
  //   required: true,
  //   message: "请选择是否启用阶梯",
  //   trigger: "change",
  // },
}
// 表格 - 列参数
const columns = [
  { type: 'expand', _slot_: 'expand' },

  {
    prop: 'nickname',
    label: '姓名'
  },
  {
    prop: 'mobile',
    label: '手机号'
  },
  {
    prop: 'email',
    label: '邮箱'
  },
  // {
  //   prop: "supplier_list",
  //   label: "所在供应商",
  //   _slot_: "supplier_list",
  // },
  {
    prop: 'status',
    label: '状态',
    _slot_: 'status'
  },

  {
    prop: 'creater',
    label: '创建人'
  },
  {
    prop: 'addtime',
    label: '创建时间',
    width: '145'
  },
  {
    prop: '',
    label: '操作',
    fixed: 'right',
    width: '170',
    _noset_: true,
    _slot_: 'operation'
  }
]
export {
  options1,
  options2,
  options3,
  options4,
  options5,
  options6,
  options7,
  options8,
  options9,
  listCol,
  rules,
  columns
}
