/**
 *  模块名称:督查计划
 *  包含:
 *
 *
 *  @author:lsj
 *  version:0.1.0
 */

import request from '../utils/gw_ajax_request.js';

const baseUrlPrefix = '/pdcApi';
// let baseUrlPrefix = 'http://10.1.102.136:8101';

// 根据督查组id获取督查人员列表
export function getDcryList(inspGroupId, pageSize, pageNum, isAll, persName) {
  return request({
    url: '/dc/pers/base/getListByInspGroupId',
    method: 'get',
    params: {
      inspGroupId: inspGroupId,
      pageSize: pageSize,
      pageNum: pageNum,
      isAll: isAll,
      persName: persName,
    },
  });
}
// 根据督查组id  人员id   删除组内 人员
export function deleteMember(inspGroupId, persId) {
  return request({
    url: '/dc/pers/inspGroup/deleteMemberBy',
    method: 'POST',
    params: {
      inspGroupId: inspGroupId,
      persId: persId,
    },
  });
}
// 根据督查组id  人员id   对象类型   设置组长
export function setHeadMan(inspGroupId, persid, pertype, orgId) {
  return request({
    url: '/bis/insp/setHeadMan',
    method: 'get',
    params: {
      id: inspGroupId,
      persid: persid,
      pertype: pertype,
      orgId: orgId,
    },
  });
}
// 根据督查组id获取督查对象列表
export function getDcdxList(
  inspGroupId,
  objType,
  pageSize,
  pageIndex,
  isAll,
  searchNameOfRsName,
  searchNameOfAdName,
  searchNameOfwtdstNm,
  engScal,
  rsAdmDep,
  wtdstType,
  wtdstState,
) {
  const paramsObj = {
    inspGroupId: inspGroupId,
    objType: objType, // 小水库
    pageSize: pageSize,
    pageNum: pageIndex,
    isAll: isAll,
  };

  if (objType == '1') {
    paramsObj['rsName'] = searchNameOfRsName;
    paramsObj['engScal'] = engScal;
    paramsObj['rsAdmDep'] = rsAdmDep;
  } else if (objType == '2') {
    paramsObj['adName'] = searchNameOfAdName;
  } else {
    paramsObj['wtdstNm'] = searchNameOfwtdstNm;
    paramsObj['wtdstType'] = wtdstType;
    paramsObj['wtdstState'] = wtdstState;
  }
  return request({
    url: '/dc/insp/obj/getObjListByGroupIdAndType',
    method: 'get',
    params: paramsObj,
  });
}

export function getDcdxList1(
  inspGroupId,
  objType,
  pageSize,
  pageIndex,
  isAll,
  searchNameOfRsName,
  searchNameOfAdName,
  searchNameOfwtdstNm,
  engScal,
  rsAdmDep,
  wtdstType,
  wtdstState,
) {
  const paramsObj = {
    inspGroupId: inspGroupId,
    objType: objType, // 小水库
    pageSize: pageSize,
    pageNum: pageIndex,
    isAll: isAll,
    plnaId: inspGroupId,
  };

  if (objType == '1') {
    paramsObj['rsName'] = searchNameOfRsName;
    paramsObj['engScal'] = engScal;
    paramsObj['rsAdmDep'] = rsAdmDep;
  } else if (objType == '2') {
    paramsObj['adName'] = searchNameOfAdName;
  } else {
    paramsObj['wtdstNm'] = searchNameOfwtdstNm;
    paramsObj['wtdstType'] = wtdstType;
    paramsObj['wtdstState'] = wtdstState;
  }
  return request({
    url: '/dc/insp/obj/getObjListByGroupIdAndType',
    method: 'get',
    params: paramsObj,
  });
}

// 根据督查组id  对象id   删除组内 对象
export function deleteDcdx(objId, objType, inspGroupId, plnaId) {
  return request({
    url: '/dc/insp/obj/deleteInspObj',
    method: 'POST',
    params: {
      objId: objId,
      objType: objType,
      inspGroupId: inspGroupId,
      plnaId: plnaId,
    },
  });
}
export function deleteDcdxByObjid(objId, objType, deleteMethod) {
  return request({
    url: '/supervision/plan/cleanObjDataByObjId',
    method: 'GET',
    params: {
      objId: objId,
      objType: objType,
      deleteMethod,
    },
  });
}

// 新建督查计划
export function createNewDcPlan(params) {
  return request({
    url: '/dc/insp/scheme',
    method: 'post',
    data: params,
  });
}
// 根据计划ID查询公文文件
export function findFileByBiz(Id) {
  return request({
    url: '/file/findFileByBiz',
    method: 'POST',
    params: {
      bizId: Id,
    },
  });
}
// 查询非当前督查组成员列表
export function getArenGrpMen(
  guid,
  inspGroupId,
  pageSize = 20,
  pageIndex = 1,
  searchText,
  searchProvTreeListCode,
  orgName,
) {
  const paramsObj = {
    guid: guid,
    inspGroupId: inspGroupId,
    pageSize: pageSize,
    pageIndex: pageIndex,
  };
  if (searchText && searchText != '') {
    paramsObj['name'] = searchText;
  }
  if (orgName && orgName != '') {
    paramsObj['orgName'] = orgName;
  }
  // if(searchProvTreeListCode&&searchProvTreeListCode!=''){
  //   paramsObj['searchProvTreeListCode'] = searchProvTreeListCode;
  // }
  return request({
    url: '/dc/pers/base/getListByGuidNotInspGroupId',
    method: 'get',
    params: paramsObj,
  });
}
// 获取省级机构列表
export function getProvincialOrgList() {
  return request({
    url: '/dc/org/base/getProvincialOrgList',
    method: 'get',
    params: {},
  });
}

export function addDczOthersMens(addArr, inspGroupId, mohurd, psn) {
  return request({
    url: '/dc/pers/base/addManByInspGroupIdAndManId',
    method: 'POST',
    headers: { Authorization: '1' },
    params: {
      manIds: addArr,
      inspGroupId: inspGroupId,
      mohurd: mohurd,
      psn: psn,
    },
  });
}

// 根据督查组id获取督查区域列表 本级
export function getDcqyList(dczId, pageSize, pageIndex, adName) {
  return request({
    url: '/dc/insp/selarea/list',
    method: 'POST',
    data: {
      id: dczId,
      pageSize: pageSize,
      pageNum: pageIndex,
      adName: adName,
    },
  });
}
// 根据督查组id获取督查区域列表 全级
export function getDcqyListAll(dczId, pageSize, pageIndex, adName) {
  return request({
    url: '/dc/insp/selarea/tree/list',
    method: 'POST',
    data: {
      id: dczId,
      pageSize: pageSize,
      pageNum: pageIndex,
      adName: adName,
    },
  });
}

// 根据areaId删除督查组下的区域
export function deleteDcqy(areaId, flag) {
  return request({
    url: `/dc/insp/selarea/delete/${areaId}/${flag}`,
    method: 'POST',
    data: {
      // "id":areaId
    },
  });
}
// 根据督查组id获取可选区域
export function getOptionalArea(dczId, adCode, name) {
  return request({
    url: '/dc/insp/selarea/getAreaByGroup',
    method: 'get',
    params: {
      id: dczId,
      adCode: adCode,
      name: name,
    },
  });
}
// 根据督查组id获取可选区域
export function addDcqyOthers(arr) {
  return request({
    url: '/dc/pers/base/addManByInspGroupIdAndManId',
    method: 'POST',
    params: {
      manIds: addArr,
      inspGroupId: inspGroupId,
    },
  });
}

//
// 根据用户信息与督查计划类型获取该用户可示可管理的单一机构的所有批次
export function getPlanNodeByPersid(persid, ptype) {
  return request({
    url: '/supervision/plan/getNodeByPersid',
    method: 'GET',
    params: {
      persid: persid,
      ptype: ptype,
    },
  });
}
// 保留原有方法名根据调用参数个数重载方法
export function getTermByPersid() {
  if (arguments.length === 3) {
    console.log('调用getTermByPersidAndType');
    return getTermByPersidAndType(arguments[0], arguments[1], arguments[2]);
  } else if (arguments.length === 4) {
    console.log('调用getTermByPersidAndTime');
    return getTermByPersidAndTime(
      arguments[0],
      arguments[1],
      arguments[2],
      arguments[3],
    );
  }
}
// 获取督查组相关的对象、人员、区域信息
export function getTermByPersidAndTime(persid, inspYear, inspMnth, orgId) {
  return request({
    url: '/supervision/plan/getAllInfoByPersidAndOrgId',
    method: 'GET',
    params: {
      persid: persid,
      inspYear: inspYear,
      inspMnth: inspMnth,
      orgId: localStorage.getItem('orgId'),
    },
  });
}

// 查询不在督查组督查范围内的督查对象(人饮、水毁)
export function getTermByPersidAndType(persid, ptype, id) {
  return request({
    url: '/supervision/plan/getAllInfoByPersid',
    method: 'GET',
    params: {
      persid: persid,
      ptype: ptype,
      id: id,
    },
  });
}

// 查询不在督查组督查范围内的督查对象(人饮、水毁) 水闸
export function getSupObjListNotInspGroupId(
  adCode,
  inspGroupId,
  fields,
  pageSize,
  pageNum,
  objType,
  nm,
  prjType,
) {
  return request({
    url: '/supervision/plan/getSupObjListNotInspGroupId',
    method: 'GET',
    params: {
      adCode: adCode,
      inspGroupId: inspGroupId,
      fields: fields,
      pageSize: pageSize,
      pageNum: pageNum,
      objType: objType,
      nm: nm,
      prjType: prjType,
      type: objType == '111' ? prjType : '',
    },
  });
}

// 查询不在督查组督查范围内的督查对象(人饮、水毁) 水闸  多了个通用督查的参数
export function getSupObjListNotInspGroupIdTwo(
  adCode,
  inspGroupId,
  fields,
  pageSize,
  pageNum,
  objType,
  nm,
  prjType,
  isAdCodeChecked,
) {
  return request({
    url: '/supervision/plan/getSupObjListNotInspGroupId',
    method: 'GET',
    params: {
      adCode: adCode,
      inspGroupId: inspGroupId,
      fields: fields,
      pageSize: pageSize,
      pageNum: pageNum,
      objType: objType,
      nm: nm,
      prjType: prjType,
      type: objType == '111' ? prjType : '',
      ownerOfc: isAdCodeChecked ? 'province' : 'other',
    },
  });
}

// /supervision/plan/getPersType
// getPersTypeByPersid
export function getPersPlanType(usrGuid) {
  return request({
    url: '/supervision/plan/getPersType',
    method: 'GET',
    params: {
      persid: usrGuid,
    },
  });
}

export function getPersPlanTypeNew(data) {
  return request({
    url: '/bis/insp/BisInspProblemRelation/getNotPlanList',
    method: 'POST',
    data,
  });
}

// 督查人员角色分配
export function setPersRole(usrGuid, perName, persType, groupId) {
  return request({
    url: '/supervision/plan/assignmentRole',
    method: 'POST',
    // data: {
    //   'guid': usrGuid,
    //   'persName': perName,
    //   'persType': persType,
    //   'id': groupId,
    // },
    params: {
      guid: usrGuid,
      persName: perName,
      persType: persType,
      id: groupId,
    },
  });
}
export function editDcz(params) {
  return request({
    url: '/dc/insp/scheme',
    method: 'post',
    data: params,
  });
}
export function deleteDcdq(dczId, adCode) {
  return request({
    url: '/dc/insp/selarea/deleteByGroupId',
    method: 'get',
    params: {
      id: dczId,
      adCode: adCode,
    },
  });
}

// /bis/insp/BisInspStatisAnal/getBatchStatisticalAnalysis
export function getBatchStatisticalAnalysis(batch) {
  return request({
    url: '/bis/insp/BisInspStatisAnal/getBatchStatisticalAnalysis',
    method: 'GET',
    params: {
      batch: batch,
    },
  });
}

// /bis/insp/BisInspStatisAnal/update
export function BisInspStatisAnalupdate(params) {
  return request({
    url: '/bis/insp/BisInspStatisAnal/update',
    method: 'post',
    data: params,
  });
}

// /bis/insp/BisInspStatisAnal/updateBisInspStatisAnal
export function updateBisInspStatisAnal(id) {
  return request({
    url: '/bis/insp/BisInspStatisAnal/updateBisInspStatisAnal',
    method: 'post',
    data: {
      id,
    },
  });
}

export function getDisplayPage() {
  return request({
    url: '/dc/insp/plan/getDisplayPage',
    method: 'GET',
    params: {},
  });
}
