import axios from 'axios';
import qs from 'qs';
// import fetch2 from '../config/fetch2'

axios.interceptors.request.use((config) => {
  if (config.method == "post" && config.url.indexOf("filemanager") == 1) {
    config.data = qs.stringify(config.data);
    config.headers['Content-Type'] = 'application/x-www-form-urlencoded';
  }
  return config;
}, (error) => {
  return Promise.reject(error);
});
//http://219.159.248.175:4002/safety/companyArchive/queryByCompanyForApp?companyId=123
const urlForOrgTree = 'http://219.159.248.175:4000'; //组织架构相关接口host
const baseUrl = 'http://219.159.248.175:4002';
// 云环境隐患排查地址
const baseUrl2 = 'http://219.159.248.175:4003';
// 后台人员电脑ip地址，隐患排查
// const baseUrl2 = 'http://10.0.0.11:8888';
const fileUrl = 'http://fcrm.coli688.com';
//设备接口地址
const deviceUrl = 'http://219.159.248.175:4004/qpi';
const planUrl = 'http://192.168.3.251:4002';
const deviceQpi = '/qpi/rest';
// 文件服务器地址
// const filemanagerHost = 'http://huiyuncas.chinaccs.cn:5903';
// const deviceUrl = 'http://10.0.0.31:8086/qpi';
const filemanagerHost = 'http://huiyuntest.wuyeface.com:5903';
//获取企业基本信息
export const getEnterpriseBaseInfo = (params) => axios({
  method: 'get',
  url: baseUrl + "/safety/companyArchive/queryByCompanyForApp",
  params: params
});
//获取台账种类-年度下拉菜单http://219.159.248.175:4002/safety/companyLedgerType/queryYearForApp
export const queryYearForApp = (params) => axios({
  method: 'get',
  url: baseUrl + "/safety/companyLedgerType/queryYearForApp",
  params: params
});
//获取台账种类
export const getLedgerTypes = (params) => axios({
  method: 'get',
  url: baseUrl + "/safety/companyLedgerType/queryLedgerTypesForApp",
  params: params
});

//获取园区ID  http://219.159.248.175:4000/park/byCompanyId?orgId=283
export const getCompanyId = (params) => axios({
  method: 'get',
  url: urlForOrgTree + "/park/byCompanyId",
  params: params
});
//获取园区ID  http://219.159.248.175:4000/park/byCompanyId?orgId=283
export const getParkId = (params) => axios({
  method: 'get',
  url: urlForOrgTree + "/park/byUserId",
  params: params
});

//台账清单
export const getLedgerFileByCompany = (params) => axios({
  method: 'get',
  url: baseUrl + "/safety/companyLedgerFile/queryLedgerFileByCompany",
  params: params
});
//企业列表
export const getCompany = (params) => axios({
  method: 'get',
  url: urlForOrgTree + "/park/getCompany",
  params: params
});

//企业列表（返回企业下问题数量）
export const getCompanyWithCount = (params) => axios({
  method: 'get',
  url: baseUrl2 + "/quality/question/getCountAndCompanyByOrgId",
  params: params
});

//企业危险级别列表
export const dangerSourceArchive = (params) => axios({
  method: 'get',
  url: baseUrl + "/safety/dangerSourceArchive/queryByCompanyApp",
  params: params
});

//风险点档案
export const getArchiveById = (params) => axios({
  method: 'get',
  url: baseUrl + "/safety/dangerSourceArchive/getArchiveById",
  params: params
});
//获取主题列表
export const getQueryThemes = (params) => axios({
  method: 'get',
  url: baseUrl2 + "/quality/theme/queryThemes",
  params: params
});
// 根据用户ID和所属组织ID查询主题
export const getThemes2 = (params) => axios({
  method: 'get',
  url: baseUrl2 + '/quality/theme/queryThemesByUserParam',
  params: params
});
//获取版本列表
export const getQueryVersions = (params) => axios({
  method: 'get',
  url: baseUrl2 + "/quality/version/queryVersions",
  params: params
});
//获取预警列表
export const getQueryWarns = (params) => axios({
  method: 'get',
  url: baseUrl2 + "/quality/warn/queryWarns",
  params: params
});
//检查标准列表
export const getQueryStandardList = (params) => axios({
  method: 'get',
  url: baseUrl2 + "/quality/standard/queryStandardList2",
  params: params
});
// 根据组织id获取子节点树
export const getOrgSubNode = (params) => axios({
  method: 'get',
  url: urlForOrgTree + '/org/getOrgTreeByOrgId',
  params: params
});
// 根据组织id获取在岗人(组织架构获取)
export const findUserByOrgId = (params) => axios({
  method: 'get',
  url: urlForOrgTree + '/user/findUserByOrgId',
  params: params
});
// 根据组织id获取用户(用户表直接获取)
export const findUserByCompanyId = (params) => axios({
  method: 'get',
  url: urlForOrgTree + '/user/findUserByCompanyId',
  params: params
});
// 根据组织id获取企业问题人员（包含企业和政府）
export const queryPeopleOfComAndParkById = (params) =>axios({
  method: 'get',
  url: urlForOrgTree + '/user/queryPeopleOfComAndParkById',
  params: params
})
// 提交问题
export const addQuestion = (params) => axios({
  method: 'post',
  url: baseUrl2 + '/quality/question/addQuestion',
  data: params,
  headers: {
    'Content-type': 'application/json'
  }
});
// 查询问题列表
export const queryQuestionList = (params) => axios({
  method: 'get',
  url: baseUrl2 + '/quality/question/queryQuestionList',
  params: params
});


// 已完成问题列表(新接口)
export const commetedQuestionList = (params) => axios({
  method: 'get',
  url: baseUrl2 + '/quality/question/queryQuestionList',
  params: params
});
// 查询问题列表（类型）
export const questionListQueryByParam = (params) => axios({
  method: 'get',
  url: baseUrl2 + '/quality/question/queryByParam',
  params: params
});
// 查询问题列表 (类型)  ------政府查询
export const questionListQueryCompanyByParam = (params) => axios({
  method: 'get',
  url: baseUrl2 + '/quality/question/queryCompanyByParam',
  params: params
})
// 修改整改措施
export const updateRectifyMethod = (params) => axios({
  method: 'post',
  url: baseUrl2 + '/quality/question/updateRectifyMethod',
  data: params
});
// 隐患排查转发、整改等操作,
// 操作代码：0：追记；1：转发；2：整改完成；3：复查合格；4：重新整改；5：指派；6：接收；
export const operateQuestion = (params) => axios({
  method: 'post',
  url: baseUrl2+'/quality/question/operateQuestion',
  data: params
});
// 隐患排查，根据问题ID获取问题详情
export const getQuestionDetail = (params) => axios({
  method: 'get',
  url: baseUrl2+'/quality/question/getQuestionById',
  params: params
});
// 隐患排查，撤单
export const cancelQuestion = (params) => axios({
  method: 'post',
  url: baseUrl2 + '/quality/question/cancelQuestion',
  data: params
});
// 隐患排查，根据问题ID查询问题记录
export const getQuestionRecords = (params) => axios({
  method: 'get',
  url: baseUrl2+'/quality/question/queryRecords',
  params: params
});
// 查询巡检列表
export const queryInspectTask = (params) => axios({
  method: 'get',
  url: deviceUrl+'/rest/devicePatrolRuleTask/downloadDeviceTaskRest',
  params: params
});
//根据任务id查询设备列表
export const queryInspectDevice = (params) => axios({
  method: 'get',
  url: deviceUrl+'/rest/devicePatrolRuleTask/downloadTaskDeviceRest',
  params: params
});
//根据任务id查询任务详情
export const queryInspectDetailByTaskId = (params) => axios({
  method: 'get',
  url: deviceUrl+'/rest/devicePatrolRuleTask/downloadTaskByTaskIdRest',
  params: params
});

//获取设备标准
export const queryDeviceFormRest = (params) => axios({
  method: 'get',
  url: deviceUrl+'/rest/devicePatrolRuleTask/downloadDeviceFormRest',
  params: params
});
//获取已上传的设备标准
export const queryDeviceHistoryFormRest = (params) => axios({
  method: 'get',
  url: deviceUrl+'/rest/devicePatrolRuleTask/downloadRecordRest',
  params: params
});

// 巡检任务特殊关闭
export const applyClose = (params) => axios({
  method: 'post',
  // url: deviceQpi+'/devicePatrolRuleTask/applyClose',
  url: deviceUrl+'/rest/devicePatrolRuleTask/applyClose',
  data: params,
});
// export const saveSystemType = (data) => fetch2('/devicePatrolRuleTask/applyClose', '/qpi/rest', data, 'JSON', 'POST');
//上传记录
export const uploadDeviceCheckRecordRest = (params) => axios({
  method: 'post',
  // url: deviceQpi+'/devicePatrolRuleTask/uplouploadRecordFileInfoTIadDeviceCheckRecordRest',
  url: deviceUrl+'/rest/devicePatrolRuleTask/uploadDeviceCheckRecordRest',
  data: params,
});
//上传记录文件
export const uploadRecordFileInfoRest = (params) => axios({
  method: 'post',
  url: deviceUrl+'/rest/devicePatrolRuleTask/uploadRecordFileInfoRest',
  data: params,
});

//上传任务
export const uploadRoadRecordRest = (params) => axios({
  method: 'post',
  // url: deviceQpi+'/devicePatrolRuleTask/uploadRoadRecordRest',
  url: deviceUrl+'/rest/devicePatrolRuleTask/uploadRoadRecordRest',
  data: params
});



//获取系统列表
export const querySysAndLevel = (params) => axios({
  method: 'get',
  url: deviceUrl+'/rest/devicePatrolRuleTask/downloadSysAndLevelRest',
  params: params
});
//获取机房列表
export const queryDevicePatrolAddressRest = (params) => axios({
  method: 'get',
  url: deviceUrl+'/rest/devicePatrolRuleTask/downloadDevicePatrolAddressRest',
  params: params
});
//获取设备列表
export const queryDeviceRest = (params) => axios({
  method: 'get',
  url: deviceUrl+'/rest/devicePatrolRuleTask/downloadDeviceRest',
  params: params
});
//获取设备详情
export const queryDeviceByIdRest = (params) => axios({
  method: 'get',
  url: deviceUrl+'/rest/devicePatrolRuleTask/downloadDeviceByIdRest',
  params: params
});
//获取记录的附件信息
export const queryRecordFileInfoRest = (params) => axios({
  method: 'get',
  url: deviceUrl+'/rest/devicePatrolRuleTask/getRecordFileInfoRest',
  params: params
});

// 上传文件到文件服务器
export const uploadFile = (header, data) => axios({
  method: 'post',
  url: filemanagerHost + '/filemanager/FileUploadAndDownloadServlet',
  headers: header,
  data: data
});
// 获取图片路径
export const getFilePath = (header) => axios({
  method: 'post',
  url: filemanagerHost + '/filemanager/FileUploadAndDownloadServlet',
  headers: header,
});
//获取事故年份
export const queryAccidentYearsForApp = (params) => axios({
  method: 'get',
  url: baseUrl + '/safty/accident/queryAccidentYearsForApp',
  params: params
});
//获取事故类型
export const queryDictDetailListByDictCode = (params) => axios({
  method: 'get',
  url: urlForOrgTree + '/dict/getDictDetailListByDictCode',
  params: params
});

//获取事故列表
export const querySafetyAccidentForApp = (params) => axios({
  method: 'get',
  url: baseUrl + '/safty/accident/querySafetyAccidentForApp',
  params: params
});
//获取事故追踪
export const querySafetyAccidentById = (params) => axios({
  method: 'get',
  url: baseUrl + '/safty/accidentResearch/querySafetyAccidentById',
  params: params
});

//获取预案演练
export const queryPlansByParams = (params) => axios({
  method: 'get',
  url: baseUrl + '/saer/planContent/getPlansByParams',
  params: params
});
//获取预案演练详情
export const queryDetailsByPlanId = (params) => axios({
  method: 'get',
  url: baseUrl + '/saer/planContent/getDetailsByPlanId',
  params: params
});

//获取培训列表
export const queryTrainingPlanInfo = (params) => axios({
  method: 'get',
  url: baseUrl + '/safety/educationTrainingPlan/queryTrainingPlanInfo',
  params: params
});
//获取培训记录
export const queryTrainingRecordInfo = (params) => axios({
  method: 'get',
  url: baseUrl + '/safety/educationTrainingRecord/queryTrainingRecordInfo',
  params: params
});
// 根据企业id查询机构人员
export const queryOrganPersonByCompanyId = (params) => axios({
  method: 'get',
  url: baseUrl + '/safty/organPerson/queryOrganPersonByCompanyId',
  params: params
});
// 根据企业id查询器材
export const queryEquipmentByCompanyId = (params) => axios({
  method: 'get',
  url: baseUrl + '/safty/equipment/queryEquipmentByCompanyId',
  params: params
});
//根据企业id查询医疗救护
export const queryMedicalAttentionByCompanyId = (params) => axios({
  method: 'get',
  url: baseUrl + '/safty/medicalAttention/queryMedicalAttentionByCompanyId',
  params: params
});
//根据医疗救护id查询医疗救护装备
export const queryMedicalEquipmentByMedicalAttentionId = (params) => axios({
  method: 'get',
  url: baseUrl + '/safty/medicalAttention/queryMedicalEquipmentByMedicalAttentionId',
  params: params
});
// 根据医疗救护id查询医疗救护人员
export const queryMedicalPersonByMedicalAttentionId = (params) => axios({
  method: 'get',
  url: baseUrl + '/safty/medicalAttention/queryMedicalPersonByMedicalAttentionId',
  params: params
});

//获取培训详情
export const queryTrainingDetail = (params) => axios({
  method: 'get',
  url: baseUrl + '/safety/educationTrainingPlan/queryTrainingDetail',
  params: params
});

//新增培训记录
export const addRecord = (params) => axios({
  method: 'post',
  url: baseUrl + '/safety/educationTrainingRecord/addRecord',
  params: params
})

//修改培训记录
export const updateRecord = (params) => axios({
  method: 'post',
  url: baseUrl + '/safety/educationTrainingRecord/updateRecord',
  params: params
})
//新增安全会议记录
export const safetyMeetingAddRecord = (params) => axios({
  method: 'post',
  url: baseUrl + '/safety/meeting/insertOrUpdate',
  params: params
})

//新增安全会议记录
export const querySafetyMeetingRecord = (params) => axios({
  method: 'get',
  url: baseUrl + '/safety/meeting/queryByParam',
  params: params
})


//获取所有安全执法检查标准
export const queryStandardByParkForApp = (params) => axios({
  method: 'get',
  url: baseUrl2 + '/enforce/check/queryStandardByParkForApp',
  params: params
})

//获取所有检查项
export const queryDescByStandardForApp = (params) => axios({
  method: 'get',
  url: baseUrl2 + '/enforce/check/queryDescByStandardForApp',
  params: params
})

//暂存or提交安全行政检查_app
export const commitSaftyCheck = (params) => axios({
  method: 'post',
  url: baseUrl2 + '/enforce/check/commitSaftyCheck',
  data: params
})

//获取检查类表
export const queryCheckListByTypeForApp = (params) => axios({
  method: 'get',
  url: baseUrl2 + '/enforce/check/queryCheckListByTypeForApp',
  params: params
})
//获取一周所有执法检查
export const queryWeekOfSafe = (params) => axios({
  method: 'get',
  url: baseUrl2 + '/enforce/check/queryWeekOfSafe',
  params: params
})

//获取执法检查详情
export const queryInfoByCheckIdForApp = (params) => axios({
   method: 'get',
   url: baseUrl2 + '/enforce/check/queryInfoByCheckIdForApp',
   params: params
})

//获取政府部门
export const getPosition = (params) => axios({
  method: 'get',
  url: urlForOrgTree + '/org/getPosition',
  params: params
})
//根据政府部门查人
export const getUsers = (params) => axios({
  method: 'get',
  url: urlForOrgTree + '/position/getUsers',
  params: params
})
//根据组织id获取政府部门子节点
export const getGovOrgTreeByOrgId = (params) => axios({
  method: 'get',
  url: urlForOrgTree + '/org/getGovOrgTreeByOrgId',
  params: params
})
//根据企业id获取企业名字
export const queryCompanyByComId = (params) => axios({
  method: 'get',
  url: urlForOrgTree + '/com/queryCompanyByComId',
  params: params
})
//根据企业id获取我的隐患状态数量
export const getQuestionCountByOrgId = (params) => axios({
  method: 'get',
  url: baseUrl2 + '/quality/question/getQuestionCountByOrgId',
  params: params
})
//根据问题id获取信息
export const getQuestionById = (params) => axios({
  method: 'get',
  url: baseUrl2 + '/quality/question/getQuestionById',
  params: params
})
/************************************************/
/*新安全执法功能*/
//政府根据整改状态查询列表
export const queryLawfulInspectListByStatus = (params) => axios({
  method: 'get',
  url: baseUrl2 + '/qmLawfulIntercept/getListByStatus',
  params: params
})
//按照qmLawfulInterceptID获取详情
export const queryLawfulInspectById = (params) => axios({
  method: 'get',
  url: baseUrl2 + '/qmLawfulIntercept/getById',
  params: params
})
//获取执法回复的记录
export const queryLawfulInspectRecordList = (params) => axios({
  method: 'get',
  url: baseUrl2 + '/qmLawfulIntercept/getRecordList',
  params: params
})

/***********************************************/
// export const queryInspectTask = (params) => fetch('/sync_SyncDevicePatrolRule_downloadDeviceTaskTI.do',deviceUrl, params,'XML', 'GET');


// export const getQuesTaskList = (params) =>axios({
//   method: 'get',
//   url: baseUrl + '/mkf/rest/houseInfo/getBuildingQuesTaskListByBuilder',
//   params: eval('(' + (JSON.stringify(params) + "{_t: (new Date()).getTime() }").replace(/}{/, ',').replace(/{,/, '{') + ')')
// });
// export const getQuesRecordList = (params) =>axios({
//   method: 'get',
//   url: baseUrl + '/mkf/sync_SyncQuesTask_getQuesRecordListTI.do',
//   params: eval('(' + (JSON.stringify(params) + "{_t: (new Date()).getTime() }").replace(/}{/, ',').replace(/{,/, '{') + ')')
// });
// export const getQuestionTaskList = (params) =>axios({
//   method: 'get',
//   url: baseUrl + '/mkf/rest/houseInfo/getQuestionTaskList',
//   params: eval('(' + (JSON.stringify(params) + "{_t: (new Date()).getTime() }").replace(/}{/, ',').replace(/{,/, '{') + ')')
// });
// /**
//  * 楼栋房间列表接口
//  */
// export const getBuildingList = (params) =>axios({
//   method: 'get',
//   url: baseUrl + '/mkf/rest/houseInfo/getBuildingListByBuilder',
//   params: eval('(' + (JSON.stringify(params) + "{_t: (new Date()).getTime() }").replace(/}{/, ',').replace(/{,/, '{') + ')')
// });
// /**
//  *  获取附件信息接口
//  */
// export const getQuesFileInfoTI = (params) =>axios({
//   method: 'get',
//   url: baseUrl + '/mkf/sync_SyncQuesTask_getQuesFileInfoTI.do',
//   params: eval('(' + (JSON.stringify(params) + "{_t: (new Date()).getTime() }").replace(/}{/, ',').replace(/{,/, '{') + ')')
// });
// export const getFilePath = (header) =>axios({
//   method: 'get',
//   url: fileUrl + '/filemanager/FileUploadAndDownloadServlet',
//   headers: header
// });
// /**
//  *  上传附件接口
//  */
// export const uploadFile = (header, data) =>axios({
//   method: 'post',
//   url: fileUrl + '/filemanager/FileUploadAndDownloadServlet',
//   headers: header,
//   data: data
// });
// /**
//  *  上传问题附件信息接口
//  */
// export const uploadQuesFileInfo = (params) =>axios({
//   method: 'post',
//   url: baseUrl + '/mkf/sync_SyncQuesTask_uploadQuesFileInfoTI.do',
//   data: params
// });
// /**
//  *  上传记录接口
//  */
// export const uploadQuesRecordTI = (params) =>axios({
//     method: 'post',
//     url:baseUrl + '/mkf/sync_SyncQuesTask_uploadQuesRecordTI.do',
//     data: params
//   });
// /**
//  *  上传（更新）问题接口
//  */
// export const uploadQuesTaskTI = (params) =>axios({
//     method: 'post',
//     url:baseUrl + '/mkf/sync_SyncQuesTask_uploadQuesTaskTI.do',
//     data: params
//   });




