import CryptoJS from 'crypto-js'

export const TOKEN_NAME = 'token'
export const getToken = () => localStorage.getItem(TOKEN_NAME)
export const setToken = (token) => localStorage.setItem(TOKEN_NAME,token)
export const removeToken = () => localStorage.removeItem(TOKEN_NAME)
export const stripos = (fHaystack,fNeedle,fOffset=0) => {
    const haystack = (fHaystack + '').toLowerCase()
    const needle = (fNeedle + '').toLowerCase()
    let index = 0
    if ((index = haystack.indexOf(needle, fOffset)) !== -1) {
      return index
    }
    return false
}

export const status_name = (status,isdel=0) => {
  let _status = parseInt(status)
  let _isdel = parseInt(isdel)
  if(_isdel == 0) {
      return ['等待处理','已建询函','询函已检','已建报价','报价已批','待付款订单'][_status]
  } else if(_isdel == 1) {
      return '用户取消'
  } else {
      return '客服取消'
  }
}
export const md5 = str => CryptoJS.MD5(str).toString()
export const getAssetsImages = (url) => {
  return new URL(`../assets/images/${url}`, import.meta.url).href
};
export const assetsImage = (url) => {
  return new URL(`../assets/images/${url}`, import.meta.url).href
};