/**
 * Created by Anndy Yang on 18/09/18.
 */

export function setEventByModuleCode(itemData){
  let modeCode = itemData.appModuleInfo.code || '';
  let paramList = itemData.appModuleInfo.paramList ? itemData.appModuleInfo.paramList : ''
  if( modeCode === 'M001' || modeCode === 'M002' || modeCode === 'M003') {
      paramList = ''
  }else if( modeCode === 'M100' || modeCode === 'M300' ) {
     
    let urlPara = getUrlParmByCode(paramList);
    paramList[0] && (paramList[0].value += urlPara);

  }else if( modeCode === 'M400') {

      let path = paramList[0]['key'];
      let v = paramList[0]['value'];
      let query = setRouterParm(paramList);

      //console.log(Vue);
      // this.$router.push({
      //   path: v,
      //   query:query
      // })
  }
  if(typeof paramList === 'string' && !paramList){
      paramList = []
  }

  return paramList;
}

function getUrlParmByCode(paramList) {
    if ( paramList.length <= 1) {
        return ''
    }
    let dataStr = ''
    let list = [];
    for( let i = 1; i < paramList.length; i ++) {
        list.push(paramList[i].key + '=' + paramList[i].value)
    }
    dataStr = list.join('&')
    if (dataStr !== '') {
        return '?' + dataStr
    }
    return ''
}

export function deepCopy(obj) {
  var result = Array.isArray(obj) ? [] : {};
  for (var key in obj) {
    if (obj.hasOwnProperty(key)) {
      if (typeof obj[key] === 'object') {
        result[key] = deepCopy(obj[key]);   //递归复制
      } else {
        result[key] = obj[key];
      }
    }
  }
  return result;
}

export function pageJumpUrl(){
  let url = { 
    pageListUrl : 'https://test1-contents.yunqueyi.com/content_list',
    detailUrl : 'https://test1-contents.yunqueyi.com/content_detail'
  };

  return url;
}

export function sortParmData(originData, orderCol, index) {
  return originData.sort((a, b) => {
    return (a[orderCol] - b[orderCol] ) * -1
  })
}

//跳转个人评价页面
export function jumpEvaluatPage(){
  return evaluatPageUrl
}


// // dev地址
// // const baseUrl = 'http://10.177.10.149:8080/'
// const baseUrl = 'https://dev-sc.yunqueyi.com/'
// const apiUrl = 'https://dev-api.yunqueyi.com/'
// const evaluatPageUrl = 'https://dev-phome.yunqueyi.com/gpr/#/home'

// test1地址
const baseUrl = 'https://test1-sc.yunqueyi.com/'
const apiUrl = 'https://test1-api.yunqueyi.com/'
const evaluatPageUrl = 'https://test1-phome.yunqueyi.com/gpr/#/home'

// // uat地址
// const baseUrl = 'https://uat-sc.yunqueyi.com/'
// const apiUrl = 'https://uat-api.yunqueyi.com/'
// const evaluatPageUrl = 'https://uat-phome.yunqueyi.com/gpr/#/home'

// // pro地址
// const baseUrl = 'https://sc.yunqueyi.com/'
// const apiUrl = 'https://api.yunqueyi.com/'
// const evaluatPageUrl = 'https://phome.yunqueyi.com/gpr/#/home'


// 为每个URL添加应用校验密钥
export function getBaseUrl(url,str) {
  
  return baseUrl + url
 
}

export function getApiUrl(url) {
 
  return apiUrl + url
  
}
