import request from '@/api/request.js'


// 查询表单及分组
export function getGroupModels(param, isSub = false) {
  return request({
    url: `wflow/model/${isSub ? 'sub/':''}group/list`,
    data: param
  })
}

// 查询表单及分组
export function getGroupModelsByUser(param,header) {
  return request({
    url: 'wflow/model/list/byUser',
    data: param,
	header
  })
}

// 查询所有模型分组
export function getModelGroups(param, isSub = false) {
  return request({
    url: `wflow/model/${isSub ? 'sub/':''}group`,
    data: param
  })
}

// 表单分组排序
export function modelGroupsSort(param, isSub = false) {
  return request({
    url: `wflow/model/${isSub ? 'sub/':''}group/sort`,
    method: 'PUT',
    data: param
  })
}

// 表单排序
export function modelsSort(groupId, param, isSub = false) {
  return request({
    url: `wflow/model/${isSub ? 'sub/':''}sort/${groupId}`,
    method: 'PUT',
    data: param
  })
}

// 修改分组
export function updateModelGroupName(groupId, param, isSub = false) {
  return request({
    url: `wflow/model/${isSub ? 'sub/':''}group/${groupId}`,
    method: 'PUT',
    data: param
  })
}

// 新增模型分组
export function createModelGroup(param, isSub = false) {
  return request({
    url: `wflow/model/${isSub ? 'sub/':''}group`,
    method: 'POST',
    data: param
  })
}

// 删除分组
export function deleteModelGroup(groupId, isSub = false) {
  return request({
    url: `wflow/model/${isSub ? 'sub/':''}group/${groupId}`,
    data: 'DELETE'
  })
}

// 删除模型
export function deleteModel(modelId) {
  return request({
    url: `wflow/model/${modelId}`,
    data: 'DELETE'
  })
}

// 获取模型
export function getModelById(modelId) {
  return request({
    url: `wflow/model/detail/${modelId}`,
    data: 'GET'
  })
}

// 获取模型
export function getModelByDefId(defId) {
  return request({
    url: `wflow/model/detail/def/${defId}`,
    data: 'GET'
  })
}

// 修改分组
export function modelMoveToGroup(modelId, groupId, isSub = false) {
  return request({
    url: `wflow/model/${isSub ? 'sub/':''}${modelId}/move/${groupId}`,
    data: 'PUT'
  })
}

// 启用或停用流程
export function enOrDisModel(modelId, type, params = {}, isSub = false) {
  return request({
    url: `wflow/model/${isSub ? 'sub/':''}${modelId}/active/${type}`,
    method: 'PUT',
    data: params
  })
}

// 获取抄送我的流程
export function getCcMeList(params) {
  return request({
    url: `wflow/process/ccMe`,
    method: 'GET',
    data: params
  })
}

// 获取控制台统计数据
export function getProcessCountData() {
  return request({
    url: `wflow/process/instance/count`,
    method: 'GET'
  })
}

export function getModuleAndMenuList(data){
	// 获取工作台的权限
	return request({
	  url: "xmgl/baseModule/getModuleAndMenuList",
	  method: 'POST',
	  data
	})
}


export default {
  createModelGroup, updateModelGroupName, modelGroupsSort,
  modelsSort, getGroupModels, getModelGroups, modelMoveToGroup,
  deleteModelGroup, deleteModel, getModelById, getModelByDefId,
  enOrDisModel, getCcMeList, getProcessCountData, getGroupModelsByUser
}
