import $http from '@/common/request.js'
import config from '@/config'
import store from '@/store/index.js'
/* 使用统计 */
function storeUser() {
  const userInfo = store.state.user.userInfo
  return {
    userId: userInfo.userId,
    phone: userInfo.phone,
    userName: userInfo.name
  }
}

function getProjectId() {
  const projectId = store.state.user.userInfo.projectId
  return projectId
}

function commonParams() {
  return `openid=${storeUser().userId}&pubname=${
    config.brsgServer.pubname
  }&projectId=${getProjectId()}&userName=${storeUser().userName}&userPhone=${
    storeUser().phone
  }&userId=${storeUser().userId}`
}

// 企业碳账户-总积分查询
function queryIntegralByAccount(accountId) {
  return $http({
    serverSp: config.brsgServer.duoduoUrl,
    url: `/server/userIntegral/queryIntegralByAccount?accountId=${accountId}`,
    method: 'get',
    isNotShowErrorToast: true,
    errorSave: true
  })
}

// 企业碳账户-积分查询
function operationsQuery(params) {
  return $http({
    serverSp: config.brsgServer.duoduoUrl,
    url: `/server/userIntegral/operationsQuery`,
    method: 'post',
    isNotShowErrorToast: true,
    errorSave: true,
    data: JSON.stringify(params)
  })
}
// 邀请函埋点
function buriedEventLogHttp(params) {
  return $http({
    serverSp: config.brsgServer.duoduoUrl,
    url: `/server/buriedEvent/buriedEventLog/add?${commonParams()}`,
    method: 'post',
    isNotShowErrorToast: true,
    errorSave: true,
    data: JSON.stringify({
      ...params,
      projectId: getProjectId()
    })
  })
}

// 获取邀请函埋点信息
function queeyBuriedEventLogHttp(params) {
  let criteria = {
    ...params,
    projectId: getProjectId(),
    userId: storeUser().userId
  }
  return $http({
    serverSp: config.brsgServer.duoduoUrl,
    url: `/server/buriedEvent/buriedEventLog/query`,
    method: 'post',
    isNotShowErrorToast: true,
    errorSave: true,
    data: JSON.stringify({criteria: criteria})
  })
}

// 访客
function queryInvitationStatisticsHttp(params) {
  return $http({
    serverSp: config.brsgServer.duoduoUrl,
    url: `/duoduo-service/duoduoenv-service/userPortrait/invitation/queryInvitationStatistics?${commonParams()}`,
    method: 'post',
    isNotShowErrorToast: true,
    errorSave: true,
    data: JSON.stringify({ ...params, userId: storeUser().userId, projectId: getProjectId() })
  })
}

// 开关记录调节
function lightFeedbackQuery(params) {
  params.criteria = {
    ...params.criteria,
    projectId: getProjectId(),
    userId: storeUser().userId
  }
  return $http({
    serverSp: config.brsgServer.duoduoUrl,
    url: `/duoduo-service/duoduoenv-service/custom/feedback/light/query`,
    method: 'post',
    isNotShowErrorToast: true,
    errorSave: true,
    data: JSON.stringify(params)
  })
}
// 空调记录调节
function tempFeedbackQuery(params) {
  params.criteria = {
    ...params.criteria,
    projectId: getProjectId(),
    // userId:'564a8ab745de45c2aa6060f0c28e7372'
    userId: storeUser().userId
  }
  return $http({
    serverSp: config.brsgServer.duoduoUrl,
    url: `/server/custom/feedbackQuery`,
    method: 'post',
    isNotShowErrorToast: true,
    errorSave: true,
    data: JSON.stringify(params)
  })
}
// 获取季节类型
function getSeasonBySeasonDate(params) {
  return $http({
    serverSp: config.brsgServer.duoduoUrl,
    url: `/server/custom/getSeasonBySeasonDate?projectId=${getProjectId()}&dateTime=${
      params.dateTime
    }`,
    method: 'get',
    isNotShowErrorToast: true,
    errorSave: true
  })
}
// 空调统计数据  chart详情
function queryPortraitTempUserDetail(params) {
  params.criteria = {
    ...params.criteria,
    projectId: getProjectId(),
    // userId:'7a925778ee184f58a8f4ef73f5196887'
    userId: storeUser().userId
  }
  return $http({
    serverSp: config.brsgServer.duoduoUrl,
    url: `/duoduo-service/duoduoenv-service/userPortrait/portraitTemp/queryPortraitTempUserDetail`,
    method: 'post',
    isNotShowErrorToast: true,
    errorSave: true,
    data: JSON.stringify(params)
  })
}
// 空调统计数据  汇总
function queryPortraitTempUserTotal() {
  return $http({
    serverSp: config.brsgServer.duoduoUrl,
    url: `/duoduo-service/duoduoenv-service/userPortrait/portraitTemp/queryPortraitTempUserTotal?userId=${
      storeUser().userId
    }`,
    method: 'get',
    isNotShowErrorToast: true,
    errorSave: true
  })
}

// 开关灯 累计使用次数  chart详情
function queryPortraitLightUser() {
  var params = {
    criteria: {
      userId: storeUser().userId
    }
  }
  return $http({
    serverSp: config.brsgServer.duoduoUrl,
    url: `/duoduo-service/duoduoenv-service/userPortrait/portraitLight/queryPortraitLightUser`,
    method: 'post',
    isNotShowErrorToast: true,
    errorSave: true,
    data: JSON.stringify(params)
  })
}

// 开关灯 累计使用次数  汇总
function queryTotalPortraitLight() {
  return $http({
    serverSp: config.brsgServer.duoduoUrl,
    url: `/duoduo-service/duoduoenv-service/userPortrait/portraitLight/queryTotalPortraitLight?userId=${
      storeUser().userId
    }`,
    method: 'get',
    isNotShowErrorToast: true,
    errorSave: true
  })
}

//  查询 今日新增  排名
function queryTotalIntegral(params) {
  return $http({
    serverSp: config.brsgServer.duoduoUrl,
    url: `/duoduo-service/duoduoenv-service/userIntegral/queryUserMessage?userId=${
      storeUser().userId
    }&projectId=${getProjectId()}&date=${params.date}&month=${params.month}`,
    method: 'get',
    isNotShowErrorToast: true,
    errorSave: true
  })
}
// 查询当前用户积分
function queryAllIntegral(params) {
  // var criteria = { ...params, projectId: getProjectId(), userId: storeUser().userId };
  params.criteria = {
    ...params.criteria,
    projectId: getProjectId(),
    userId: storeUser().userId
  }
  return $http({
    serverSp: config.brsgServer.duoduoUrl,
    url: `/duoduo-service/duoduoenv-service/userIntegral/query`,
    method: 'POST',
    isNotShowErrorToast: true,
    errorSave: true,
    data: JSON.stringify(params)
  })
}
// 查询所有用户积分排名
function queryIntegralRank(params) {
  // var criteria = { ...params, projectId: getProjectId(), userId: storeUser().userId };
  params.criteria = {
    ...params.criteria,
    projectId: getProjectId()
  }
  return $http({
    serverSp: config.brsgServer.duoduoUrl,
    url: `/duoduo-service/duoduoenv-service/userIntegral/query`,
    method: 'POST',
    isNotShowErrorToast: true,
    errorSave: true,
    data: JSON.stringify(params)
  })
}

// function queryUserIntegral(params) {
//     return $http({
//       serverSp: config.brsgServer.duoduoUrl,
//       url: `/duoduo-service/duoduoenv-service/userIntegral/query`,
//       method: 'POST',
//       isNotShowErrorToast: true,
//       errorSave: true,
//       data: JSON.stringify({...params})
//     })
//   }

// 会议室-首页：累计使用次数
function portraitMeetingHttp(params) {
  let criteria = {
    ...params,
    userId: storeUser().userId,
    projectId: getProjectId()
  }
  return $http({
    serverSp: config.brsgServer.duoduoUrl,
    url: `/server/userPortrait/portraitMeeting/query?${commonParams()}`,
    method: 'POST',
    isNotShowErrorToast: true,
    errorSave: true,
    data: JSON.stringify({ criteria: criteria })
  })
}

// 会议室-详情页：累计使用次数
function summaryHttp(params) {
  let criteria = { ...params, projectId: getProjectId() }
  return $http({
    serverSp: config.brsgServer.duoduoUrl,
    url: `/server/userPortrait/portraitMeeting/query/summary?${commonParams()}`,
    method: 'POST',
    isNotShowErrorToast: true,
    errorSave: true,
    data: JSON.stringify({ criteria: criteria })
  })
}
// 会议室-详情页：常用会议室
function queryComsHttp(params) {
  return $http({
    serverSp: config.brsgServer.duoduoUrl,
    url: `/server/userPortrait/portraitMeetingUser/queryComs?${commonParams()}`,
    method: 'POST',
    isNotShowErrorToast: true,
    errorSave: true,
    data: JSON.stringify({ ...params, projectId: getProjectId() })
  })
}
// 会议室-详情页：参与同事统计
function portraitMeetingUserHttp(params) {
  return $http({
    serverSp: config.brsgServer.duoduoUrl,
    url: `/server/userPortrait/portraitMeetingUser/query?${commonParams()}`,
    method: 'POST',
    isNotShowErrorToast: true,
    errorSave: true,
    data: JSON.stringify({ ...params, projectId: getProjectId() })
  })
}
// 模块显示
function queryPortraitModule() {
  return $http({
    serverSp: config.brsgServer.duoduoUrl,
    url: `/duoduo-service/duoduoenv-service/userPortrait/queryPortraitModuleList?${commonParams()}`,
    method: 'get',
    isNotShowErrorToast: true,
    errorSave: true
  })
}

export {
  queryIntegralByAccount,
  operationsQuery,
  queeyBuriedEventLogHttp,
  buriedEventLogHttp,
  queryInvitationStatisticsHttp,
  queryTotalIntegral,
  queryAllIntegral,
  portraitMeetingHttp,
  summaryHttp,
  queryComsHttp,
  portraitMeetingUserHttp,
  queryIntegralRank,
  queryTotalPortraitLight,
  queryPortraitLightUser,
  queryPortraitTempUserTotal,
  queryPortraitTempUserDetail,
  getSeasonBySeasonDate,
  tempFeedbackQuery,
  lightFeedbackQuery,
  queryPortraitModule
}
