/**
 * 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 contentType = {
  '1': '平台新闻',
  '2': '采访专栏',
  '3': '政策法规',
  '4': '通知公告',
  '5': '科技动态'
}
export const columnType = [
  {
    val: '1',
    tit: '平台新闻'
  },
  {
    val: '2',
    tit: '采访专栏'
  },
  {
    val: '5',
    tit: '科技动态'
  },
  {
    val: '3',
    tit: '政策法规'
  },
  {
    val: '4',
    tit: '通知公告'
  }
]

export const DateFormat = function(fmt, val) {
  var that = new Date()
  if (val) {
    that = val
  }
  var o = {
    'M+': that.getMonth() + 1, // 月份
    'd+': that.getDate(), // 日
    'h+': that.getHours(), // 小时
    'm+': that.getMinutes(), // 分
    's+': that.getSeconds(), // 秒
    'q+': Math.floor((that.getMonth() + 3) / 3), // 季度
    'S': that.getMilliseconds() // 毫秒
  }
  if (/(y+)/.test(fmt)) {
    fmt = fmt.replace(RegExp.$1, (that.getFullYear() + '').substr(4 - RegExp.$1.length))
  }
  for (var k in o) {
    if (new RegExp('(' + k + ')').test(fmt)) {
      fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
    }
  }
  return fmt
}

