constant.js 7.91 KB
// 新值,旧值,整数部分位数,小数部分位数,最小值,最大值,规则
function limitPrice(newValue, oldValue, intergerDigit, pointDigit, minValue, maxValue, regRule) {
  /* eslint-disable */
  var reg = {
    priceReg: /^\d[\d\.]*$/,
    numReg: /^[1-9]\d*$/,
    zNumReg: /^\d*$/
  }
  /* eslint-enable */
  regRule = regRule || 'priceReg'
  if (newValue && ((minValue && newValue < minValue) || (maxValue && newValue > maxValue))) {
    return oldValue || ''
  }
  if (newValue && reg[regRule].test(newValue + '')) {
    if (/\./.test(newValue)) {
      newValue = newValue + ''
      var interger = newValue.split('.')[0]
      var point = newValue.split('.')[1]
      var intergerNum = interger.length > intergerDigit ? oldValue.split('.')[0] : interger
      var pointNum = point.length > pointDigit ? point.slice(0, pointDigit) : point
      newValue = pointDigit ? intergerNum + '.' + pointNum : newValue.split('.')[0]
    } else {
      newValue = newValue.length > intergerDigit ? oldValue.slice(0, intergerDigit) : newValue
      if (regRule == 'zNumReg') {
        newValue = newValue.split('')[0] == '0' ? '0' : newValue
      }
    }
    return newValue
  } else {
    return newValue ? oldValue : ''
  }
}
function downloadIamge(imgsrc, name = new Date().getTime()) {
  //下载图片地址和图片名
  var image = new Image()
  // 解决跨域 Canvas 污染问题
  image.setAttribute('crossOrigin', 'anonymous')
  image.onload = function() {
    var canvas = document.createElement('canvas')
    canvas.width = image.width
    canvas.height = image.height
    var context = canvas.getContext('2d')
    context.drawImage(image, 0, 0, image.width, image.height)
    var url = canvas.toDataURL('image/png') //得到图片的base64编码数据
    var a = document.createElement('a') // 生成一个a元素
    var event = new MouseEvent('click') // 创建一个单击事件
    a.download = name || 'photo' // 设置图片名称
    a.href = url // 将生成的URL设置为a.href属性
    a.dispatchEvent(event) // 触发a的单击事件
  }
  image.src = imgsrc
}
function getExplorer() {
  var ua = navigator.userAgent.toLocaleLowerCase()
  var browserType = null
  if (ua.match(/msie/) != null || ua.match(/trident/) != null) {
    browserType = 'IE'
  } else if (ua.match(/firefox/) != null) {
    browserType = '火狐'
  } else if (ua.match(/ubrowser/) != null) {
    browserType = 'UC'
  } else if (ua.match(/opera/) != null) {
    browserType = '欧朋'
  } else if (ua.match(/bidubrowser/) != null) {
    browserType = '百度'
  } else if (ua.match(/metasr/) != null) {
    browserType = '搜狗'
  } else if (ua.match(/tencenttraveler/) != null || ua.match(/qqbrowse/) != null) {
    browserType = 'QQ'
  } else if (ua.match(/maxthon/) != null) {
    browserType = '遨游'
  } else {
    browserType = '谷歌'
  }
  return browserType
}
function exportFn(url) {
  let browserType = getExplorer()
  if (browserType == 'QQ') {
    window.open(url)
    return
  }
  let iframe = document.createElement('iframe')
  iframe.style.display = 'none'
  iframe.src = url.replace(/(http|https):/, '')
  document.body.appendChild(iframe)
}
function aToExport(url) {
  var a = document.createElement('a')
  a.setAttribute('id', 'exportToExport')
  a.setAttribute('href', url)
  a.setAttribute('target', '_blank')
  document.body.appendChild(a)
  a.click()
}
const orderManageStatusList = [
  { confId: '1', confName: '待付款' },
  { confId: '2', confName: '已支付' },
  { confId: '3', confName: '已失效' },
  // { confId: '21', confName: '待收货(待核销)' },
  { confId: '21', confName: '待核销' },
  { confId: '22', confName: '已核销' },
  // { confId: '22', confName: '已收货(已核销)' },
  { confId: '6', confName: '待发货' },
  // { confId: '7', confName: '待核销' },
  // { confId: '8', confName: '已核销' },
  { confId: '9', confName: '售后中' },
  { confId: '10', confName: '售后完成' },
  { confId: '11', confName: '待审批' },
  { confId: '13', confName: '待发货' },
  { confId: '14', confName: '已收货' }
]
const afterSaleStatusList = [
  { confId: '1', confName: '待审核' },
  { confId: '2', confName: '审核成功' },
  { confId: '3', confName: '审核失败' },
  { confId: '4', confName: '待确认' },
  { confId: '5', confName: '退款中' },
  { confId: '6', confName: '已退款' },
  { confId: '7', confName: '退款失败' }
]
const orderSourceList = [
  { confId: '1', confName: '商城订单' },
  { confId: '2', confName: '直播订单' },
  { confId: '3', confName: '秒杀订单' },
  { confId: '4', confName: '众筹订单' }
]
const deliveryTypeList = [
  { confId: '1', confName: '到店核销' },
  { confId: '2', confName: '快递到家' }
]
//会员中心得状态list
const statusList = [
  // {
  //   confId: '',
  //   confName: '全部'
  // },
  {
    confId: 1,
    confName: '生效中'
  },
  {
    confId: 2,
    confName: '已失效'
  }
]
//会员订单类型字典
const orderTypesList = [
  {
    confId: 1,
    confName: '套餐'
  },
  {
    confId: 2,
    confName: '权益卡'
  }
]
const orderStatus = [
  {
    confId: 1,
    confName: '未开始'
  },
  {
    confId: 2,
    confName: '进行中'
  },
  {
    confId: 3,
    confName: '已结束'
  }
]
const orderStatusList = [
  // 2: '待收货',
  // 3: '已完成',
  // 4: '售后中',
  // 5: '退款失败',
  // 6: '已经退款',
  {
    confId: 2,
    confName: '待收货'
  },
  {
    confId: 3,
    confName: '已完成'
  },
  {
    confId: 4,
    confName: '售后中'
  },
  {
    confId: 5,
    confName: '退款失败'
  },
  {
    confId: 6,
    confName: '已退款'
  }
]
const serviceStatusList = [
  {
    confId: 1,
    confName: '未生效'
  },
  {
    confId: 2,
    confName: '生效中'
  },
  {
    confId: 3,
    confName: '已失效'
  }
]
const memberTypeList = [
  {
    confId: 1,
    confName: '正式会员'
  },
  {
    confId: 2,
    confName: '试用会员'
  }
]
const stateList = [
  {
    confId: 0,
    confName: '待上架'
  },
  {
    confId: 1,
    confName: '在售中'
  },
  {
    confId: 2,
    confName: '已下架'
  }
]
const businessType = [
  {
    optionId: 1,
    optionLabel: '1.2'
  },
  {
    optionId: 3,
    optionLabel: '2.0'
  }
]
const subscribe = [
  {
    optionId: 1,
    optionLabel: '道路救援'
  },
  {
    optionId: 2,
    optionLabel: '定保招揽'
  },
  {
    optionId: 5,
    optionLabel: '续保招揽'
  },
  {
    optionId: 6,
    optionLabel: '节假日关怀'
  },
  {
    optionId: 3,
    optionLabel: '次新车转化'
  },
  {
    optionId: 8,
    optionLabel: '超级营销'
  },
  {
    optionId: 9,
    optionLabel: '售后众筹'
  }
]
const giftPackage = [
  { id: 1, name: '换(焕新礼)' },
  { id: 2, name: '减(折扣礼)' },
  { id: 3, name: '送(券包礼)' },
  { id: 4, name: '约(膨胀礼)' }
]
const equityLevel = {
  PC0036: '续保惠享A套餐',
  PC0037: '续保优享B套餐',
  PC0038: '续保乐享C套餐',
  PC0039: '续保尊享D套餐'
}
function setMinHeight(calssName = '.edit-container') {
  let height = document.querySelector('.header-wrap').clientHeight + 110 + 'px'
  let minHeight = 'calc(100vh - ' + height + ')'
  document.querySelector(calssName).style.minHeight = minHeight
}
function isShowBtn(value) {
  let isShowStatus = false
  const menu = JSON.parse(sessionStorage['SCRM_BASE_MENULIST'])
  menuLevel(menu)
  function menuLevel(item) {
    item.forEach(itm => {
      if (itm.path == value) {
        isShowStatus = true
      }
      if (itm.children) {
        menuLevel(itm.children)
      }
    })
  }
  return isShowStatus
}
const RENEWAL = [1, 2, 3, 4, 5, 6, 7, 8]
const FESTIVAL = [9, 10]
export { RENEWAL, FESTIVAL, equityLevel, isShowBtn, subscribe, giftPackage, limitPrice, getExplorer, exportFn, aToExport, downloadIamge, businessType, orderStatus, orderManageStatusList, afterSaleStatusList, orderSourceList, deliveryTypeList, statusList, serviceStatusList, memberTypeList, stateList, orderTypesList, orderStatusList, setMinHeight }