import { axios } from '@/utils/request'

const api = {
  createWorkTemplate: '/task/work-template/insertOne',
  uploadWorkFlow: '/task/process-file/upload',
  saveApprover: '/task/work-approve/saveTemplateApprove',
  getTemplateList: '/task/work-template/',
  deployProcess: '/task/work-template/deployProcess',
  createWorkGroup: '/task/work-type/insert',
  getAllTemplatesWithGroup: '/task/work-template/getAllTemplates',
  getGroupList: '/task/work-type/selectList',
  getWorkPermissionByTemplateId: '/task/work-permission/getWorkPermissionByTemplateId',
  saveWorkPermission: '/task/work-permission/saveWorkPermission',
  getWorkTempldateField: '/task/work-template-field/getWorkTempldateField',
  getTemplateId: '/task/work-template/insertOne',
  saveAll: '/task/work-template/saveTemplate',
  updateWorkTemplateStatus: '/task/work-template/updateOne',
  deleteGroupById: '/task/work-type/deleteById',
  updateGroupById: '/task/work-type/updateById',
  getTempletById: '/task/work-template/queryTemplateByTemplateId',
  copyTemplate: '/task/work-template/templateCopy',
  moveTemplate: '/task/work-template/templateMove',
  roleTree: '/task/tb-role/getRoleAll',
  userTree: '/task/tb-user/getDeptTree',
  getDictionaryBySearch: '/task/equipment/getDictionaryBySearch',
  pushTaskById: '/task/work-template/publish'
}

export default api

export function createWorkTemplate(parameter) {
  return axios({
    url: api.createWorkTemplate,
    method: 'post',
    data: parameter
  })

}export function pushTaskById(parameter) {
  return axios({
    url: api.pushTaskById,
    method: 'post',
    data: parameter
  })
}

export function uploadWorkFlow(parameter) {
  return axios({
    url: api.uploadWorkFlow,
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data: parameter
  })
}

export function saveApprover(parameter) {
  return axios({
    url: api.saveApprover,
    method: 'get',
    params: parameter
  })
}

export function getTemplateList(parameter) {
  return axios({
    url: api.getTemplateList,
    method: 'get',
    params: parameter
  })
}

export function deployProcess(parameter) {
  return axios({
    url: api.deployProcess,
    method: 'get',
    params: parameter
  })
}

export function createWorkGroup(parameter) {
  return axios({
    url: api.createWorkGroup,
    method: 'post',
    data: parameter

  })
}

export function getAllTemplatesWithGroup(parameter) {
  return axios({
    url: api.getAllTemplatesWithGroup,
    method: 'get',
    data: parameter
  })
}

export function getGroupList(parameter) {
  return axios({
    url: api.getGroupList,
    method: 'post',
    data: parameter
  })
}

export function getWorkPermissionByTemplateId(parameter) {
  return axios({
    url: api.getWorkPermissionByTemplateId,
    method: 'get',
    params: parameter
  })
}

export function saveWorkPermission(parameter) {
  return axios({
    url: api.saveWorkPermission,
    method: 'post',
    data: parameter,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

export function getWorkTempldateField(parameter) {
  return axios({
    url: api.getWorkTempldateField,
    method: 'get',
    params: parameter
  })
}

export function getTemplateId(parameter) {
  return axios({
    url: api.getTemplateId,
    method: 'post',
    data: parameter
  })
}

export function saveAll(parameter) {
  return axios({
    url: api.saveAll,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    method: 'post',
    data: parameter
  })
}

export function updateWorkTemplateStatus(data) {
  return axios({
    url: api.updateWorkTemplateStatus,
    method: 'put',
    data: data
  })
}

export function getTempletById(params) {
  return axios({
    url: api.getTempletById,
    method: 'get',
    params: params
  })
}

export function deleteGroupById(id) {
  return axios({
    url: api.deleteGroupById + '?id=' + id,
    method: 'delete'
  })
}

export function updateGroupById(data) {
  return axios({
    url: api.updateGroupById,
    method: 'post',
    data: data
  })
}

export function copyOrMoveTemplate(data, type) {
  const url = type === 0 ? api.copyTemplate : api.moveTemplate
  return axios({
    url,
    method: 'post',
    data: data
  })
}
// 查询设备控件分类列表
export function getDictionaryBySearch(data) {
  return axios({
    url: api.getDictionaryBySearch,
    method: 'get',
    params: data
  })
}

export function roleTree(params) {
  const url = api.roleTree
  return axios({
    url,
    method: 'get',
    params: params
  })
}
export function userTree(params) {
  const url = api.userTree
  return axios({
    url,
    method: 'get',
    params: params
  })
}
