/**
 * Created by luyanan on 18/8/13.
 */
export const xtUrl = process.env.XT_API
export const kexiuUrl = process.env.KX_API

/**
 * default img
 */
export const defaultSet = {
  img: {
    user: '/static/comimg/default-expert.jpg',
    org: '/static/comimg/default-org.jpg'
  }
}

/**
 * 解析url参数
 * @example ?id=12345&a=b
 * @return Object {id:12345,a:b}
 */
export function urlParse(name) {
  return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || ['', ''])[1].replace(/\+/g, '%20')) || null
}

export function trimStr(str) {
  return str.replace(/(^\s*)|(\s*$)/g, '')
}

export function parseTime(date, flag) {
  if (flag) {
    return date.substring(0, 4) + '年' + date.substring(4, 6) + '月' + date.substring(6, 8) + '日 ' + date.substring(8, 10) + ':' + date.substring(10, 12) + ':' + date.substring(12, 14)
  } else {
    return date.substring(0, 4) + '/' + date.substring(4, 6) + '/' + date.substring(6, 8) + ' ' + date.substring(8, 10) + ':' + date.substring(10, 12) + ':' + date.substring(12, 14)
  }
}

export const TimeTr = function(dealtime) {
  var s = dealtime
  var y = s.substr(0, 4)
  var m = s.substr(4, 2)
  var d = s.substr(6, 2)
  var h = ''
  var minute = ''
  var formatTime
  if (s.length <= 6) {
    formatTime = y + '年' + m.replace(/\b(0+)/gi, '') + '月'
  } else if (s.length > 6 && s.length <= 8) {
    formatTime = y + '年' + m.replace(/\b(0+)/gi, '') + '月' + d.replace(/\b(0+)/gi, '') + '日 '
  } else {
    h = s.substr(8, 2)
    minute = s.substr(10, 2)
    formatTime = y + '年' + m.replace(/\b(0+)/gi, '') + '月' + d.replace(/\b(0+)/gi, '') + '日 ' + h + ':' + minute
  }
  return formatTime
}
/**
 * String与Array之间的转换
 */
export function strToArr(str) {
  var subs = []
  if (str) {
    if (str.indexOf(',')) {
      subs = str.split(',')
    } else {
      subs[0] = str
    }
    return subs
  } else {
    return subs
  }
}
export function arrToStr(arr) {
  var strs = ''
  if (arr) {
    strs = arr.join(',')
    return strs
  } else {
    return strs
  }
}
export const type = {
  '1': '平台新闻',
  '2': '采访专栏',
  '3': '政策法规',
  '4': '通知公告'
}
export const orgType = {
  '2': '上市企业',
  '3': '外资企业',
  '4': '合资企业',
  '5': '资企业',
  '6': '个体经营',
  '7': '政府机构',
  '8': '公益组织',
  '9': '协会学会',
  '10': '新闻媒体',
  '11': '教育机构',
  'undefined': ''
}
