import { http } from "@/common/service/service.js";
import configService from "@/common/service/config.service.js";
import buildURL from "@/common/luch-request/helpers/buildURL.js";
const apiService = {
  /**
   * 登录
   */
  login(params) {
    return http.post("/sys/login", params);
  },
  /**
   * 获取权限菜单
   */
  getPermission(params) {
    return http.get("/sys/permissionNew/getUserPermissionByToken", params);
  },
  //获取任务管理列表-瓦斯巡检
  teamList(params) {
    const url = buildURL("/safety/disTeamInfo/list", params);
    return http.get(url);
  },
  //获取任务管理巡检地点列表-瓦斯巡检
  taskDetailsList(params) {
    const url = buildURL("/safety/gasDayReport/taskDetailsList", params);
    return http.get(url);
  },

  //获取App在线版本更新下载链接
  getAppLast(params) {
    const url = buildURL("/safety/app/last", params);
    return http.get(url);
  },

  /**
   * 单点登录
   */
  // validateCasLogin(params) {
  //  var index = 0;
  //  var url = "/sys/cas/client/validateLogin";
  //  for(var w in params){
  //   if(index == 0)
  //   url = url+"?"+w+"="+params[w];
  //   else
  //   url = url+"&"+w+"="+params[w];
  //   index++;
  //  }
  //   return http.get(url);
  // },

  validateCasLogin(to, params) {
    var url = to + "/sys/cas/client/validateLogin" + params;
    // var index = 0;
    // var url = "/sys/cas/client/validateLogin";
    // for(var w in params){
    //  if(index == 0)
    //  url = url+"?"+w+"="+params[w];
    //  else
    //  url = url+"&"+w+"="+params[w];
    //  index++;
    // }
    console.log("validateCasLogin url============" + url);
    return http.get(url, {});
  },
  /**
   * 手机号码登录
   */
  phoneNoLogin(params) {
    return http.post("/sys/phoneLogin", params);
  },
  /**
   * 退出
   */
  logout(params) {
    return http.post("/sys/logout", params);
  },
  // 按系统查询设备分类信息
  getDeviceType(params) {
    return http.get(
      "/safety/ventanalyDeviceInfo/DeviceKind/queryBySystem",
      params
    );
  },

  // 查询各类设备的列表表头信息
  getShowColum(params) {
    return http.get("/safety/ventanalyShowColum/show_colum", params);
  },
  // 获取工作面煤层下拉选项
  getDictItems(params) {
    const url = buildURL("/sys/api/getDictItems", params);
    return http.get(url);
  },
  // 按系统查询设备监测信息
  getDeviceMonitor(params) {
    return http.post("/monitor/device", params);
  },
  //查询场景类型数据
  getSysList(params) {
    const url = buildURL("/safety/ventanalyManageSystem/list", params);
    return http.get(url);
  },
  //查询分页列表信息 通过分类查询 各类设备在app上是否展示的字段
  getShowColumList(params) {
    // const urlParams = new URLSearchParams(params);
    // const url = "/safety/ventanalyShowColum/list?" + urlParams.toString();
    const url = buildURL("/safety/ventanalyShowColum/list", params);
    return http.get(url);
  },
  //设备控制
  controlDevice(params) {
    return http.put(
      "/ventanaly-device/safety/ventanalyMonitorData/devicecontrol",
      params
    );
  },
  //根据设备id 查询该设备关联的视频流url
  getCameraById(params) {
    // const urlParams = new URLSearchParams(params);
    // const url = "/safety/ventanalyCamera/list?" + urlParams.toString();
    const url = buildURL("/safety/ventanalyCamera/list", params);
    return http.get(url);
  },
  //如果上面这个接口返回code码  则使用这个接口获取url
  getCameraByCode(params) {
    const url = buildURL("/monitor/camera/queryByCameraCode", params);
    return http.get(url);
  },

  //瓦斯日报列表数据
  getGas(params) {
    const url = buildURL("/safety/gasDayReport/list", params);
    return http.get(url);
  },
  //瓦斯日报-下拉选项
  getSelect(params) {
    const url = buildURL("/safety/gasDayReport/getGasAddressList", params);
    return http.get(url);
  },
  //瓦斯日报-新增保存
  getAdd(params) {
    return http.post("/safety/gasDayReport/add", params);
  },
  //瓦斯日报-编辑保存
  getEdit(params) {
    return http.post("/safety/gasDayReport/edit", params);
  },
  //瓦斯日报-删除
  delGas(params) {
    const url = buildURL("/safety/gasDayReport/delete", params);
    return http.delete(url);
  },
  //获取设备历史数据
  getDeviceHistory(params) {
    const url = buildURL("/safety/ventanalyMonitorData/listdays", params);
    return http.get(url);
  },
  getDeviceHistory2(params) {
    return http.post("/monitor/history/getHistoryData", params);
  },
  //获取操作历史
  getOpreateHistory(params) {
    const url = buildURL(
      "/ventanaly-device/safety/ventanalyDevicesetLog/list",
      params
    );
    return http.get(url);
  },
  //获取文件数据
  getFileInfo(params) {
    return http.post("/ventanaly-sharefile/fileServer/list", params);
  },
  //获取预警信息
  getWarnInfo(params) {
    return http.get("/safety/ventanalyAlarmLog/total", params);
  },
  //获取通风预警监测详情tab信息
  sysTypeWarn(params) {
    return http.post(
      "/ventanaly-device/safety/ventanalyAlarmLog/sysTypeWarn",
      params
    );
  },
  //获取通风预警监测详情信息
  sysWarn(params) {
    return http.post(
      "/ventanaly-device/safety/ventanalyAlarmLog/sysWarn",
      params
    );
  },
  //获取通风预警监测详情信息
  getDeviceVent(params) {
    return http.post("/ventanaly-device/monitor/device", params);
  },

  //获取设备预警实时监测数据
  warningList(params) {
    const url = buildURL("/safety/ventanalyAlarmLog/now_alarmlist", params);
    return http.get(url);
  },

  //获取设备预警历史监测数据
  historyList(params) {
    const url = buildURL("/safety/ventanalyAlarmLog/list", params);
    return http.get(url);
  },

  getFilePreview(params) {
    return http.post("/ventanaly-sharefile/fileServer/preview", params);
  },
  // 下载文件
  downloadFile(params) {
    return http.post("/ventanaly-sharefile/fileServer/download", params);
  },
  // 删除文件
  delateFile(params) {
    const url = buildURL("/ventanaly-sharefile/fileServer/delete", params);
    return http.delete(url);
  },
  //提交文件
  commitFile(params) {
    const url = buildURL("/safety/actBusiness/commit", params);
    return http.post(url);
  },
  // 撤回文件
  cancelFile(params) {
    const url = buildURL("/safety/actBusiness/cancelNew", params);
    return http.post(url);
  },
  // 审批流程
  getListFile(params) {
    const url = buildURL("/activiti/activiti_process/listData", params);
    return http.get(url);
  },
  //审批进度
  gethistoricFlowNew(params) {
    const url = buildURL("/safety/actTask/historicFlowNew", params);
    return http.get(url);
  },
  //通过id（巡检卡id）查询
  getCardList(params) {
    const url = buildURL("/safety/gasInsCard/queryByIdApp", params);
    return http.get(url);
  },
  //nfc卡ID校验
  enterCardId(params) {
    const url = buildURL("/safety/gasInsCard/enterCardId", params);
    return http.get(url);
  },
  // 获取瓦斯巡检任务统计情况
  queryNowGasInfoByUser(params) {
    const url = buildURL("/safety/gasInsCard/queryNowGasInfoByUser", params);
    return http.post(url);
  },
  //审批进度
  gethistoricFlowNew(params) {
    const url = buildURL("/safety/actTask/historicFlowNew", params);
    return http.get(url);
  },
  /**
   * 获取文件访问路径
   * @param avatar
   * @param subStr
   * @returns {*}
   */
  getFileAccessHttpUrl(avatar, subStr) {
    if (!subStr) subStr = "http";
    if (avatar && avatar.startsWith(subStr)) {
      return avatar;
    } else {
      return configService.staticDomainURL + "/" + avatar;
    }
  },
  // 获取瓦斯巡检详情图片
  gasServerImg(params) {
    const url = buildURL("/gasServerImg", params);
    return http.post(url);
  },
};

export default apiService;
