import { getAction, deleteAction, putAction, postAction, httpAction, downFile } from '@/api/manage'
import Vue from 'vue'
import {UI_CACHE_DB_DICT_DATA } from "@/store/mutation-types"

//角色管理
const addRole = (params)=>postAction("/sys/role/add",params);
const editRole = (params)=>putAction("/sys/role/edit",params);
const checkRoleCode = (params)=>getAction("/sys/role/checkRoleCode",params);
const queryall = (params)=>getAction("/sys/role/queryall",params);

//用户管理
const addUser = (params)=>postAction("/sys/user/add",params);
const editUser = (params)=>putAction("/sys/user/edit",params);
const queryUserRole = (params)=>getAction("/sys/user/queryUserRole",params);
const getUserList = (params)=>getAction("/sys/user/list",params);
const frozenBatch = (params)=>putAction("/sys/user/frozenBatch",params);
//验证用户是否存在
const checkOnlyUser = (params)=>getAction("/sys/user/checkOnlyUser",params);
//改变密码
const changePassword = (params)=>putAction("/sys/user/changePassword",params);

//权限管理
const addPermission= (params)=>postAction("/sys/permission/add",params);
const editPermission= (params)=>putAction("/sys/permission/edit",params);
const getPermissionList = (params)=>getAction("/sys/permission/list",params);
const getSystemMenuList = (params)=>getAction("/sys/permission/getSystemMenuList",params);
const getSystemSubmenu = (params)=>getAction("/sys/permission/getSystemSubmenu",params);
const getSystemSubmenuBatch = (params) => getAction('/sys/permission/getSystemSubmenuBatch', params)
const queryTreeList = (params)=>getAction("/sys/permission/queryTreeList",params);
const queryTreeListForRole = (params)=>getAction("/sys/role/queryTreeList",params);
const queryListAsync = (params)=>getAction("/sys/permission/queryListAsync",params);
const queryRolePermission = (params)=>getAction("/sys/permission/queryRolePermission",params);
const saveRolePermission = (params)=>postAction("/sys/permission/saveRolePermission",params);
const queryPermissionsByUser = ()=>getAction("/sys/permission/getUserPermissionByToken");
const loadAllRoleIds = (params)=>getAction("/sys/permission/loadAllRoleIds",params);
const getPermissionRuleList = (params)=>getAction("/sys/permission/getPermRuleListByPermId",params);
const queryPermissionRule = (params)=>getAction("/sys/permission/queryPermissionRule",params);

// 委托信息——委托单位下拉列表
const getWeituoClientList = (params)=>getAction("/weituo/itdmWeituoInfo/distinctClientList",params);
// 委托信息——根据委托单位查询委托信息列表
const getWeituoInfoListByClient = (params)=>getAction("/weituo/itdmWeituoInfo/weituoNoList",params);
// 根据委托编号获取日期下拉列表
const getWeituoRq = (params)=>getAction("/gongdandetail/itdmGongdanDetail/gongdanWorkdateList",params);
// 根据日期获取工单号下拉列表
const getWeituoGdh = (params)=>getAction("/gongdandetail/itdmGongdanDetail/gongdanWoIdList",params);
// 根据日期和工单号获取唯一的实验类型
const getWeiYi = (params)=>getAction("/gongdandetail/itdmGongdanDetail/gongdanDateListByWoId",params);
// 根据日期和工单号，实验类型获取实际试验设备
const getWeiSb = (params)=>getAction("/gongdandetail/itdmGongdanDetail/gongdanShebeiListByWoId",params);
// 根据日期和工单号，实验类型，实际试验设备获取实际开始时间，实际结束时间
const getWeiSj = (params)=>getAction("/gongdandetail/itdmGongdanDetail/gongdanDateListByWoId1",params);
// 日历
const getDeviceCalendar = (params)=>getAction("/deviceCalendar/list",params);


// 部门管理
const queryDepartTreeList = (params)=>getAction("/sys/sysDepart/queryTreeList",params);
const queryDepartTreeSync = (params)=>getAction("/sys/sysDepart/queryDepartTreeSync",params);
const queryIdTree = (params)=>getAction("/sys/sysDepart/queryIdTree",params);
const queryParentName   = (params)=>getAction("/sys/sysDepart/queryParentName",params);
const searchByKeywords   = (params)=>getAction("/sys/sysDepart/searchBy",params);
const deleteByDepartId   = (params)=>deleteAction("/sys/sysDepart/delete",params);

//二级部门管理
const queryDepartPermission = (params)=>getAction("/sys/permission/queryDepartPermission",params);
const saveDepartPermission = (params)=>postAction("/sys/permission/saveDepartPermission",params);
const queryTreeListForDeptRole = (params)=>getAction("/sys/sysDepartPermission/queryTreeListForDeptRole",params);
const queryDeptRolePermission = (params)=>getAction("/sys/sysDepartPermission/queryDeptRolePermission",params);
const saveDeptRolePermission = (params)=>postAction("/sys/sysDepartPermission/saveDeptRolePermission",params);
const queryMyDepartTreeList = (params)=>getAction("/sys/sysDepart/queryMyDeptTreeList",params);

//入库的样品条码下拉列表
const rukuSampleBarcodeList = (params) => getAction('/inventory/itdmInventoryBarcode/xialaList', params);
//样品过期审核
const sampleExpireSH = (params) => putAction('/inventory/itdmSampleExpire/shenhe', params);
// 委托完成判断
const checkWancheng = (params) => putAction('/weituo/itdmWeituoInfo/edit1', params);
// 设备故障判断
const checkGuzhang = (params) => putAction('/itdmDevice/itdmDevice/edit1', params);
// 获取设备下拉列表
const getDeviceList = (params) => getAction('/itdmDevice/itdmDevice/xialalist', params);
// 获取项目经理下拉列表
const getManagerList = (params) => getAction('/itdmPersonManage/itdmPersonManage/xialalist', params);
// 获取传感器下拉列表
const getCgqList = (params) => getAction('/chuanganqi/itdmChuanganqi/xialalist', params);
// 计划员查询计划列表
const getJhList = (params) => getAction('/sych/JHYList', params);
// 计划员给检测项目选项目经理等等的提交按钮
const saveProject = (params)=>postAction("/sych/JHYAddOrUpdate",params);
// 项目经理查询计划列表
const getXmjlList = (params) => getAction('/sych/XMJLList', params);
// 项目经理拆单后的提交按钮
const saveProjectJl = (params)=>postAction("/sych/XMJLAddOrUpdate",params);
// 项目经理拆单后的删除按钮
const delProjectJl = (params)=>deleteAction("/sych/delete",params);
// 大屏报警信息删除按钮
const delBaojing = (params)=>deleteAction("/itdm/voice/delete",params);
// 大屏设备维护密码验证
const confirmPa = (params)=>getAction("/itdmMima/itdmMima/panduan",params);
// 折线图初始化
const listGraph = (params)=>getAction("/second/screen/chushihua",params);
// 首页数据
const listBdc = (params)=>getAction("/itdmFirstPage/getFrstPageTaskNum",params);
// 首页列表
const listBdc2 = (params)=>getAction("/itdmFirstPage/itdmTask/list",params);
// 数据确认提交按钮
const saveSj = (params)=>postAction("/itdmgomgongdanshuju/ItdmGongdanshuju/editList",params);
// 数据确认列表
const listSj = (params)=>getAction("/itdmgomgongdanshuju/ItdmGongdanshuju/list",params);
// 上传附件
const upload = (params)=>postAction("/itdmgomgongdanshuju/ItdmGongdanshuju/upload",params);
// 获取当前附件
const getUpload = (params)=>getAction("/itdmgomgongdanshuju/ItdmGongdanshuju/getUpdate",params);
// 根据流程id查询业务内容
const getYeWU = (params)=>getAction("flowpath/itdmRunFlowPath/queryById",params);
// 新增运行流程时，第一步操作人的下拉列表
const getFirNextZrr = (params)=>getAction("/flowpath/itdmRunFlowPathStep/AddSelectNextStepUser",params);
// 下一步的时候选择操作人的下拉列表
const getNextZrr = (params)=>getAction("/flowpath/itdmRunFlowPathStep/selectNextStepUser",params);
// 判断下一步是否为最后一步（最后一步没有责任人）
const getNextTF = (params)=>getAction("/flowpath/itdmFlowPathStep/getSortByFlowPathId",params);
// 绩效导出
const getExportJx = (params)=>downFile("/jixiaoPersonPrice/jixiaoPersonPrice/exportXlsByTime",params);


//日志管理
const deleteLog = (params)=>deleteAction("/sys/log/delete",params);
const deleteLogList = (params)=>deleteAction("/sys/log/deleteBatch",params);

//数据字典
const addDict = (params)=>postAction("/sys/dict/add",params);
const editDict = (params)=>putAction("/sys/dict/edit",params);
const treeList = (params)=>getAction("/sys/dict/treeList",params);
const addDictItem = (params)=>postAction("/sys/dictItem/add",params);
const editDictItem = (params)=>putAction("/sys/dictItem/edit",params);

//字典标签专用（通过code获取字典数组）
export const ajaxGetDictItems = (code, params)=>getAction(`/sys/dict/getDictItems/${code}`,params);
//从缓存中获取字典配置
function getDictItemsFromCache(dictCode) {
  if (Vue.ls.get(UI_CACHE_DB_DICT_DATA) && Vue.ls.get(UI_CACHE_DB_DICT_DATA)[dictCode]) {
    let dictItems = Vue.ls.get(UI_CACHE_DB_DICT_DATA)[dictCode];
    return dictItems;
  }
}

//系统通告
const doReleaseData = (params)=>getAction("/sys/annountCement/doReleaseData",params);
const doReovkeData = (params)=>getAction("/sys/annountCement/doReovkeData",params);
//获取系统访问量
const getLoginfo = (params)=>getAction("/sys/loginfo",params);
const getVisitInfo = (params)=>getAction("/sys/visitInfo",params);

// 根据部门主键查询用户信息
const queryUserByDepId = (params)=>getAction("/sys/user/queryUserByDepId",params);

// 重复校验
const duplicateCheck = (params)=>getAction("/sys/duplicate/check",params);
// 加载分类字典
const loadCategoryData = (params)=>getAction("/sys/category/loadAllData",params);
const checkRuleByCode = (params) => getAction('/sys/checkRule/checkByCode', params)
//加载我的通告信息
const getUserNoticeInfo= (params)=>getAction("/sys/sysAnnouncementSend/getMyAnnouncementSend",params);
const getTransitURL = url => `/sys/common/transitRESTful?url=${encodeURIComponent(url)}`


const downWeituo_info= (params)=>downFile("weituo/itdmWeituoInfo/word",params);




const updateBarcode = (params)=>postAction("/inventory/itdmInventoryBarcode/edit",params);
const createBarcode = (params)=>postAction("/inventory/itdmInventoryBarcode/add",params);
const deleteBarcode   = (params)=>deleteAction("/inventory/itdmInventoryBarcode/delete",params);





const queryFlowPathSelectList = (params) => getAction('/flowpath/itdmFlowPath/querySelectList', params)


// 保存 流程信息
const runFlowPathSaveData = (params)=>postAction("/flowpath/itdmRunFlowPathStep/save",params);


// 通过当前流程
const runFlowPathPass = (params)=>postAction("/flowpath/itdmRunFlowPathStep/pass",params);

const runFlowPathPass1 = (params)=>postAction("/flowpath/itdmRunFlowPathStep/pass1",params);


// 驳回上一节点
const runFlowPathRejectDQ = (params)=>postAction("/flowpath/itdmRunFlowPathStep/rejectDQ",params);

// 当前运行之前的节点
const runFlowPathyrunList = (params)=>getAction("/flowpath/itdmRunFlowPathStep/yrunList",params);

// 驳回指定节点
const runFlowPathrejectzd = (params)=>postAction("/flowpath/itdmRunFlowPathStep/rejectzd",params);

// 人员绩效提成保存
const jixiaoPersonPrice = (params)=>postAction("/jixiaoPersonPrice/jixiaoPersonPrice/addAllJX",params);


// 中转HTTP请求
export const transitRESTful = {
  get: (url, parameter) => getAction(getTransitURL(url), parameter),
  post: (url, parameter) => postAction(getTransitURL(url), parameter),
  put: (url, parameter) => putAction(getTransitURL(url), parameter),
  http: (url, parameter) => httpAction(getTransitURL(url), parameter),
  delete: (url, parameter) => deleteAction(getTransitURL(url), parameter),
}

export {
  addRole,
  editRole,
  checkRoleCode,
  addUser,
  editUser,
  queryUserRole,
  getUserList,
  queryall,
  frozenBatch,
  checkOnlyUser,
  changePassword,
  getPermissionList,
  addPermission,
  editPermission,
  queryTreeList,
  queryListAsync,
  queryRolePermission,
  saveRolePermission,
  queryPermissionsByUser,
  loadAllRoleIds,
  getPermissionRuleList,
  queryPermissionRule,
  queryDepartTreeList,
  queryDepartTreeSync,
  queryIdTree,
  queryParentName,
  searchByKeywords,
  deleteByDepartId,
  deleteLog,
  deleteLogList,
  addDict,
  editDict,
  treeList,
  addDictItem,
  editDictItem,
  doReleaseData,
  doReovkeData,
  getLoginfo,
  getVisitInfo,
  queryUserByDepId,
  duplicateCheck,
  queryTreeListForRole,
  getSystemMenuList,
  getSystemSubmenu,
  getSystemSubmenuBatch,
  loadCategoryData,
  checkRuleByCode,
  queryDepartPermission,
  saveDepartPermission,
  queryTreeListForDeptRole,
  queryDeptRolePermission,
  saveDeptRolePermission,
  queryMyDepartTreeList,
  getUserNoticeInfo,
  getDictItemsFromCache,
  checkGuzhang,
  getDeviceList,
  getManagerList,
  getCgqList,
  getJhList,
  saveProject,
  getXmjlList,
  saveProjectJl,
  delProjectJl,
  getWeituoClientList,
  getWeituoInfoListByClient,
  delBaojing,
  confirmPa,
  listGraph,
  listBdc,
  listBdc2,
  saveSj,
  getWeituoRq,
  getWeituoGdh,
  listSj,
  getWeiYi,
  getWeiSb,
  getWeiSj,
  upload,
  getUpload,
  downWeituo_info,
  checkWancheng,
  updateBarcode,
  createBarcode,
  deleteBarcode,
  sampleExpireSH,
  rukuSampleBarcodeList,
  getDeviceCalendar,
  queryFlowPathSelectList,
  runFlowPathSaveData,
  runFlowPathPass,
  runFlowPathPass1,
  runFlowPathRejectDQ,
  runFlowPathyrunList,
  runFlowPathrejectzd,
  getYeWU,
  jixiaoPersonPrice,
  getFirNextZrr,
  getNextZrr,
  getNextTF,
  getExportJx
}



