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 options10 = [
  { id: "0", name: "现结" },
  { id: "1", name: "月清" },
  { id: "2", name: "双月清" },
];
//发货方式
const options11 = [
  { id: "0", name: "公司自提" },
  { id: "1", name: "供应商包邮" },
];
const listCol = [
  {
    prop: "cgdNo",
    label: "采购单编号",
    width: "160px",
  },
  {
    prop: "apply_name",
    label: "申请人",
    width: "65px",
  },
  {
    prop: "good_code",
    label: "商品编码",
    width: "150px",
  },
  {
    prop: "good_name",
    label: "商品名称",
  },
  {
    prop: "class_cat",
    label: "商品分类",
  },

  {
    prop: "good_weight",
    label: "商品总重量(g)",
    width: "110px",
  },
  {
    prop: "diff_weight",
    label: "工差总重量(g)",
    width: "110px",
  },

  {
    prop: "status",
    label: "状态",
    _slot_: "status",
    width: "120px",
  },
  {
    prop: "addtime",
    label: "创建时间",
    width: "140px",
    sortable: true,
  },
  {
    prop: "",
    label: "操作",
    fixed: "right",
    _noset_: true,
    width: "52px",
    _slot_: "operation",
  },
];

const validate_num = (rule, value, callback) => {
  const { required } = rule;
  if (required) {
  if (value === "") {
    callback(new Error("不能为空！"));
  } else {
    callback();
  }}else{
    callback();
  }
};
const validate_num_0 = (rule, value, callback) => {
  const { required } = rule;
  if (required) {
    if (value === "") {
      callback(new Error("不能为空！"));
    } else if (
      value === "0" ||
      value === "0." ||
      value === "0.0" ||
      value === "0.00" ||
      value === "0.000"
    ) {
      callback(new Error("不能为零！"));
    } else {
      callback();
    }
  } else {
    callback();
  }
};
const validate_desc = (rule, value, callback) => {
  const { required } = rule;
  let str = value ?? "";
  if (required && str === "") {
    callback(new Error("不能为空！"));
  } else if (isSpecialSymbol(str)) {
    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",
    },
  ],
  expire_day: [
    {
      required: true,
      validator: validate_num_0,
      trigger: "blur",
    },
  ],

  supplierNo: [
    {
      type: "array",
      required: true,
      message: "请选择供应商",
      trigger: "change",
    },
  ],
  delivery_day: [
    {
      required: true,
      validator: validate_num,
      trigger: "blur",
    },
  ],

  pname: [
    {
      required: true,
      validator: validate_good_name,
      trigger: "blur",
    },
  ],
  work_day: [
    {
      required: true,
      validator: validate_num,
      trigger: "blur",
    },
  ],
  model: [
    {
      required: true,
      message: "型号不能为空",
      trigger: "blur",
    },
  ],

  color: [
    {
      required: true,
      message: "颜色不能为空",
      trigger: "blur",
    },
  ],
  material: [
    {
      required: true,
      message: "材质不能为空",
      trigger: "blur",
    },
  ],

  brandid: [
    {
      type: "array",
      required: true,
      message: "商品品牌",
      trigger: "change",
    },
  ],
  unit_id: [
    {
      type: "array",
      required: true,
      message: "请输入商品单位",
      trigger: "blur",
    },
  ],
  weight: [
    {
      required: true,
      validator: validate_num_0,
      trigger: "blur",
    },
  ],
  tax: [
    {
      required: true,
      message: "请选择税率",
      trigger: "change",
    },
  ],
  supply_area: [
    {
      required: true,
      message: "请选择供货区域",
      trigger: "change",
    },
  ],
  origin_place: [
    {
      type: "array",
      required: true,
      message: "请选择产地",
      trigger: "change",
    },
  ],

  delivery_place: [
    {
      type: "array",
      required: true,
      message: "请选择发货地",
      trigger: "change",
    },
  ],
  //固定成本
  cert_fee: [
    {
      required: true,
      validator: validate_num,
      trigger: "blur",
    },
  ],
  pakge_fee: [
    {
      required: true,
      validator: validate_num,
      trigger: "blur",
    },
  ],
  cost_fee: [
    {
      required: true,
      validator: validate_num,
      trigger: "blur",
    },
  ],

  mark_fee: [
    {
      required: true,
      validator: validate_num,
      trigger: "blur",
    },
  ],
  demo_fee: [
    {
      required: true,
      validator: validate_num,
      trigger: "blur",
    },
  ],

  open_fee: [
    {
      required: true,
      validator: validate_num,
      trigger: "blur",
    },
  ],
  delivery_fee: [
    {
      required: true,
      validator: validate_num,
      trigger: "blur",
    },
  ],
  nake_fee: [
    {
      required: true,
      validator: validate_num,
      trigger: "blur",
    },
  ],
  noble_weight: [
    {
      required: true,
      validator: validate_num_0,
      trigger: "blur",
    },
  ],
  metal_id: [
    {
      required: true,
      message: "请选择贵金属种类",
      trigger: "change",
    },
  ],
  is_gold_price: [
    {
      required: true,
      message: "请选择是否启用实时金价",
      trigger: "change",
    },
  ],
  is_diff: [
    {
      required: true,
      message: "请选择有无工差",
      trigger: "change",
    },
  ],
  config: [
    {
      required: true,
      type: "array",
      message: "请选择配置要求",
      trigger: "change",
    },
  ],
  other_config: [
    {
      required: true,
      message: "其他要求不能为空",
      trigger: "blur",
    },
  ],
  pay_way: [
    {
      required: true,
      message: "请选择付款方式",
      trigger: "change",
    },
  ],
  send_way: [
    {
      required: true,
      message: "请选择发货方式",
      trigger: "change",
    },
  ],

  cost_desc: [
    {
      required: false,
      validator: validate_desc,
      trigger: "blur",
    },
  ],
  remark: [
    {
      required: true,
      validator: validate_desc,
      trigger: "blur",
    },
  ],
  good_img: [
    {
      required: true,
      message: "商品图片不能为空",
      trigger: "change",
    },
  ],
};
export {
  options1,
  options2,
  options3,
  options4,
  options5,
  options6,
  options7,
  options8,
  options9,
  options10,
  options11,
  listCol,
  rules,
};
