
// var baseurl = 'https://www.xygh.org.cn'
// var baseurl = 'https://h.anssy.com/hdrecCs'
// var baseurl = 'http://192.168.0.66:8081/hdrec'
var baseurl = 'https://www.zhihuihankoubei.com:9090/hdrec'
// document.getElementById('app').style.height = window.innerHeight + 'px'
// window.addEventListener("resize", function() {
//     document.getElementById('app').style.height = window.innerHeight + 'px'
// });
var event = new Event('resize')
window.dispatchEvent(event)
if (window.axios) {
  // axios.defaults.baseURL = 'http://192.168.0.66:8081/hdrec/api/';
  axios.defaults.baseURL = 'https://www.zhihuihankoubei.com:9090/hdrec/api/';
  // axios.defaults.baseURL = 'https://h.anssy.com/hdrecCs/api/';
  axios.defaults.headers['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8';
  // axios.defaults.headers['X-Nideshop-Token'] = localStorage.getItem('X-Nideshop-Token')||""
}

function GetRequest(urlStr) {
  if (typeof urlStr == "undefined") {
    var url = decodeURI(location.search); //获取url中"?"符后的字符串
  } else {
    var url = "?" + urlStr.split("?")[1];
  }
  var theRequest = new Object();
  if (url.indexOf("?") != -1) {
    var str = url.substr(1);
   var strs = str.split("&");
    for (var i = 0; i < strs.length; i++) {
      theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
    }
  }
  return theRequest
}
function aler(){
    alert('网页开发中，敬请期待。')
}
//判断访问终端
var browser = function () {
  var u = navigator.userAgent,
    app = navigator.appVersion;
  return {
    trident: u.indexOf('Trident') > -1, //IE内核
    presto: u.indexOf('Presto') > -1, //opera内核
    webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
    gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
    mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
    ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
    android: u.indexOf('Android') > -1 || u.indexOf('Adr') > -1, //android终端
    iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
    iPad: u.indexOf('iPad') > -1, //是否iPad
    webApp: u.indexOf('Safari') == -1, //是否web应该程序，没有头部与底部
    weixin: u.indexOf('MicroMessenger') > -1, //是否微信 （2015-01-22新增）
    qq: u.match(/\sQQ/i) == " qq" //是否QQ
  };
}()

if (typeof Object.assign != 'function') {
  Object.assign = function (target) {
    'use strict';
    if (target == null) {
      throw new TypeError('Cannot convert undefined or null to object');
    }

    target = Object(target);
    for (var index = 1; index < arguments.length; index++) {
      var source = arguments[index];
      if (source != null) {
        for (var key in source) {
          if (Object.prototype.hasOwnProperty.call(source, key)) {
            target[key] = source[key];
          }
        }
      }
    }
    return target;
  };
}
var PUBLIC_KEY = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCjJmws8ahwdYOZ52Ow0wHkBvbYaiz0+9FEguRkKQj8iwoYNeyWj/gRO9lsO31KkYWsv+zll5apqNKgPJP8OlQUR' +
    'hAf6wdsMRB9hfjXsXKCs5+5nJISs5A+h5KDX2kC65OkOuyD+6QeeF2hZZYKqmvCCpvrZkrVNdHtL9ijNAPEWQIDAQAB'
//校验身份证号码
function testid(id) {
  // 1 "验证通过!", 0 //校验不通过
  var format = /^(([1][1-5])|([2][1-3])|([3][1-7])|([4][1-6])|([5][0-4])|([6][1-5])|([7][1])|([8][1-2]))\d{4}(([1][9]\d{2})|([2]\d{3}))(([0][1-9])|([1][0-2]))(([0][1-9])|([1-2][0-9])|([3][0-1]))\d{3}[0-9xX]$/;
  //号码规则校验
  if (!format.test(id)) {
    return 0
  }


  //区位码校验
  //出生年月日校验   前正则限制起始年份为1900;
  var year = id.substr(6, 4), //身份证年
    month = id.substr(10, 2), //身份证月
    date = id.substr(12, 2), //身份证日
    time = Date.parse(month + '-' + date + '-' + year), //身份证日期时间戳date
    now_time = Date.parse(new Date()), //当前时间戳
    dates = (new Date(year, month, 0)).getDate(); //身份证当月天数
  if (time > now_time || date > dates) {
    return 0
  }
  //校验码判断
  var c = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); //系数
  var b = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'); //校验码对照表
  var id_array = id.split("");
  var sum = 0;
  for (var k = 0; k < 17; k++) {
    sum += parseInt(id_array[k]) * parseInt(c[k]);
  }
  if (id_array[17].toUpperCase() != b[sum % 11].toUpperCase()) {
    return 0
  }
  return 1
}
//校验手机号
function phone(number) {
    // 1 通过, 0 不通过
    let patrn = /^1[3456789]\d{9}$/;
    // let zj = /^(0\d{2,3}\-)?([2-9]\d{6,7})+(\-\d{1,6})?$/
    if (!patrn.test(number)) {
        return 0
    } else {
        return 1
    }
};
// 格式化时间
const cover = time => {
  const date = new Date(time)
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()
  return (
    [year, month, day].map(formatNumber).join('-') +
    ' ' + [hour, minute, second].map(formatNumber).join(':')
  )
}
const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

//去除html 标签
function delHtmlTag(str){
    return str.replace(/<[^>]+>/g,"");
}
//判断昨天，今天
function fnTime(time) {
    let ptime = new Date(time).getTime()

    const twentyFourHours = 24 * 60 * 60 * 1000;
    const fortyEightHours = 24 * 60 * 60 * 1000 * 2;
    const date = new Date();
    const year = date.getFullYear();
    const month = date.getMonth() + 1;
    const day = date.getDate();
    const today = `${year}/${month}/${day}`;
    const todayTime = new Date(today).getTime();
    const yesterdayTime = new Date(todayTime - twentyFourHours).getTime();
    const lastYesterdayTime = new Date(todayTime - fortyEightHours).getTime();

    if (ptime >= todayTime) {
        return '今天 ' + time.split(' ')[1].slice(0, 5);
    } else if (ptime < todayTime && yesterdayTime <= ptime) {
        return '昨天 ' + time.split(' ')[1].slice(0, 5);
    }
    // else if( ptime < yesterdayTime && lastYesterdayTime <= ptime ){
    //     return '前天 '+time.split(' ')[1];
    // }
    else {
        return time.slice(0, 10).replace(/\//g, '-');
    }
}
//获取日期是周几
function getWeekDate(time) {
    var date = new Date(time);
    var day = date.getDay();
    var names = ["周日","周一","周二","周三","周四","周五","周六"];
    return names[day];
}
//获取后几日日期
function getDate(num) {
    var date = new Date();
    date.setDate(date.getDate() + num)
    let year = date.getFullYear()
    let month = date.getMonth() + 1
    let day = date.getDate();
    if (month >= 1 && month <= 9) {
        month = `0${month}`
    }
    if (day >= 1 && day <= 9) {
        day = `0${day}`
    }
    return `${year}/${month}/${day}`
}
//获取前几日日期
function getBeforeDate(date) {
    let n = date;
    let d = new Date();
    let year = d.getFullYear();
    let mon = d.getMonth() + 1;
    let day = d.getDate();
    if (day <= n) {
        if (mon > 1) {
            mon = mon - 1;
        } else {
            year = year - 1;
            mon = 12;
        }
    }
    d.setDate(d.getDate() - n);
    year = d.getFullYear();
    mon = d.getMonth() + 1;
    day = d.getDate();
    let s = year + "/" + (mon < 10 ? ('0' + mon) : mon) + "/" + (day < 10 ? ('0' + day) : day);
    return s;
}
