import baseUtils from './baseUtils'
import request from './request'
//根据字典类型查询字典的URL
export const QUERY_DICTIONARY_BY_TYPE_URL = 'api/v1/platformDict/queryDictionaryByType'
//查询所有用户简略信息URL
export const ALL_AUTH_USER_SKETCH_URL = 'api/v1/authUser/queryAllAuthUserSketch'
//行政区域
export const DISTRICT_CODE_URL = 'api/v1/districtCode/queryByParams'
//当前长整时间
export const CURRENT_LONG_TIME = 'api/v1/platform/currenLongTime'
//OSS地址
export const OSS_URL = 'https://skywalking-web.oss-cn-chengdu.aliyuncs.com/'

//婚姻状况类型
export const marriageOptions = [
  {
    'text':'未婚',
    'value':1
  },
  {
    'text':'已婚',
    'value':2
  },
]
//常住类型
export const residenceTypeOptions = [
  {
    'text':'户籍',
    'value':'01'
  },
  {
    'text':'非户籍',
    'value':'02'
  },
]
//性别选项
export const genderOptions = [
  {
    'text':'男',
    'value':1
  },
  {
    'text':'女',
    'value':2
  },
]
//是否查询所有
export const needAllStatusOptions = [
  {
    'text':'是',
    'value':'true'
  },
  {
    'text':'否',
    'value':'false'
  },
]
//物品是否热门
export const itemHotStatusOptions = [
  {
    'text':'热门',
    'value':'HOT'
  },
  {
    'text':'非热门',
    'value':'UN_HOT'
  },
]
//APP的板块名称
export const itemStatusOptions = [
  {
    'text':'上架',
    'value':'ITEM_STATUS_ON'
  },
  {
    'text':'下架',
    'value':'ITEM_STATUS_OFF'
  },
]
//APP的板块名称
export const panelOptions = [
  {
    'text':'主页',
    'value':'MAIN'
  },
  {
    'text':'页面内',
    'value':'PAGE'
  },
]
//审核状态
export const auditStatusOption = [
  {
    'text':'通过',
    'value':'APPROVED'
  },
  {
    'text':'驳回',
    'value':'REJECT'
  },
  {
    'text':'待处理',
    'value':'WAIT_HANDLE'
  }
]
//分页查询对比条件
export const contrastFactorOption = [
  {
    'text':'等于',
    'value':'EQUALS',
  },
  {
    'text':'大于',
    'value':'GREATER_THAN',
  },
  {
    'text':'大于等于',
    'value':'GREATER_THAN_OR_EQUAL_TO',
  },
  {
    'text':'小于等于',
    'value':'LESS_THAN_OR_EQUAL_TO',
  },
  {
    'text':'小于',
    'value':'LESS_THAN',
  }
]
export const dataBeginAndEndTimeFormat = 'YYYY-MM' //时间格式
//发送post请求
export const postBodyRequest = async (url,params) => {
  let res = await request.postBodyRequest(url,
      params
  )
  if(res){
    return res
  }else{
    return {}
  }
}
//发送get请求
export const getRequest = async (url,params) => {
  let res = await request.get(url,
      params
  )
  if(res){
    return res
  }else{
    return {}
  }
}
//根据字典类型查询字典
export const queryDictionaryByType  = async (dictType) => {
  let res = await request.get(QUERY_DICTIONARY_BY_TYPE_URL,
      {
        "dictType":dictType
      }
  )
  if(res){
    let data = res.data.data;
    let optionList = new Array();
    if(data) {
      data.map(item => {
        let option = {
          'text': item.dictValue,
          'value': item.platformDictId
        }
        optionList.push(option);
      })
    }
    return optionList;
  }else{
    return new Array();
  }
}
export const methodHandler = {
  //处理图片URL
  handleImageUrl(url){
    if(baseUtils.isNull(url)){
      return '';
    }
    let handledUrl = OSS_URL+url
    return handledUrl
  },
  async yearOption(){
    let optionArray = new Array();
    for(let index = 1900;index<=2100;index++) {
      let option = {
        'text': index,
        'value': index
      }
      optionArray.push(option);
    }
    return optionArray
  },
  async mapSearchOptions(){
    let result = await postBodyRequest(DISTRICT_CODE_URL,{
      itemStatus:'ITEM_STATUS_ON'
    });
    let data = result.data.data;
    let resultArray = new Array();
    if(data && data.length>0){
      data.map(item => {
        let option = {
          'text':item.districtName,
          'value':item.districtCode
        }
        resultArray.push(option);
      })
    }
    //console.log('resultArray: '+JSON.stringify(resultArray))
    return resultArray;
  },
  async currenLongTime(){
    let result = await getRequest(CURRENT_LONG_TIME,{});
    let data = result.data;
    if(data){
      return data
    }else{
      return ''
    }
  },
  async authUserIdOption(){
    let result = await getRequest(ALL_AUTH_USER_SKETCH_URL,{});
    let data = result.data.data;
    let resultArray = new Array();
    if(data && data.length>0){
      data.map(item => {
        let option = {
          'text':item.userName,
          'value':item.authUserId
        }
        resultArray.push(option);
      })
    }
    //console.log('resultArray: '+JSON.stringify(resultArray))
    return resultArray;
  },
}
export default {
  auditStatusOption:auditStatusOption,
  contrastFactorOption:contrastFactorOption,
  dataBeginAndEndTimeFormat:dataBeginAndEndTimeFormat,
  authUserIdOption:methodHandler.authUserIdOption,
  yearOption:methodHandler.yearOption,
  mapSearchOptions:methodHandler.mapSearchOptions,
  currenLongTime:methodHandler.currenLongTime,
  panelOptions:panelOptions,
  itemStatusOptions:itemStatusOptions,
  itemHotStatusOptions:itemHotStatusOptions,
  needAllStatusOptions:needAllStatusOptions,
  genderOptions:genderOptions,
  residenceTypeOptions:residenceTypeOptions,
  marriageOptions:marriageOptions,
  handleImageUrl:methodHandler.handleImageUrl,
};

