/**
 * 人员管理接口
 */
import request from '@/utils/request'
import qs from 'qs'

// 查询员工照片
export function getPersonPhoto(personId) {
  return request({
    url: '/person/getPhoto',
    method: 'get',
    params: {
      personId: personId
    }
  })
}

// 查询员工列表
export function getPersonListAll(params) {
  return request({
    url: '/person/irisList',
    method: 'get',
    params
  })
}

// 查询员工列表
export function getPersonList(params) {
  return request({
    url: '/person/irisListPage',
    method: 'get',
    params
  })
}
export function getPerson(params) {
  return request({
    url: '/acsPersonGroupRelationship/groupPersonList',
    method: 'get',
    params
  })
}
// 查询访客列表
export function getVisitorList(params) {
  return request({
    url: '/person/visitorListPage',
    method: 'get',
    params
  })
}

// 性别
export function getSexType(params) {
  return request({
    url: '/dict/code/sysSex',
    method: 'get',
    params
  })
}
// 业务类型
export function getDutyType(params) {
  return request({
    url: '/dict/code/dutyType',
    method: 'get',
    params
  })
}
// 民族
export function getNationType(params) {
  return request({
    url: '/dict/code/nationType',
    method: 'get',
    params
  })
}
export function getVisitorCode() {
  return request({
    url: 'person/getVisitorCode',
    method: 'get'
  })
}
// 添加人员
export function addPerson(data) {
  return request({
    url: 'person/irisAdd',
    method: 'post',
    data
  })
}
// 人员详情
export function personInfo(id) {
  return request({
    url: '/person/detail/' + id,
    method: 'get'
  })
}
// 修改人员
export function updatePerson(data) {
  return request({
    url: 'person/irisUpdate',
    method: 'post',
    data
  })
}
// 删除人员
export function delPerson(ids) {
  return request({
    url: 'person/batchIrisDelete',
    method: 'post',
    timeout: 60000,
    params: {
      ids: ids
    },
    paramsSerializer: params => {
      return qs.stringify(params, { indices: false })
    }
  })
}
// 批量导出
export function batchExportPerson(params) {
  return request({
    url: 'person/batchExport',
    method: 'get',
    timeout: 120000,
    params,
    responseType: 'blob' // 这一步也很关键，一定要加上 responseType 值为 blob
  })
}
// 批量导出
export function batchImportPersonNew(fileobj) {
  const param = new FormData()
  param.append('file', fileobj)
  return request({
    url: 'person/batchPersonImport',
    method: 'post',
    headers: { 'Content-Type': 'multipart/form-data' },
    data: param
  })
}

// 批量导入
export function batchImportPerson(fileobj) {
  const param = new FormData()
  param.append('file', fileobj)
  return request({
    url: 'person/batchImport',
    method: 'post',
    headers: { 'Content-Type': 'multipart/form-data' },
    data: param
  })
}

// 批量导入删除
export function batchDeletePerson(fileobj) {
  const param = new FormData()
  param.append('file', fileobj)
  return request({
    url: 'person/batchDeletePerson',
    method: 'post',
    headers: { 'Content-Type': 'multipart/form-data' },
    data: param
  })
}

// 照片批量导入
export function batchImportPhoto(fileobj) {
  const param = new FormData()
  param.append('file', fileobj)
  return request({
    url: 'person/photoBatch',
    method: 'post',
    headers: { 'Content-Type': 'multipart/form-data' },
    data: param
  })
}

// 人员同步至面板机
export function sendPanelPersons(ids) {
  return request({
    url: 'person/sendPersons',
    method: 'post',
    timeout: 60000,
    params: {
      personIds: ids
    },
    paramsSerializer: params => {
      return qs.stringify(params, { indices: false })
    }
  })
}

export function saveIris(params) {
  const formData = new FormData()
  formData.append('image_zy0', params.image_zy0)
  formData.append('image_zy1', params.image_zy1)
  formData.append('image_yy0', params.image_yy0)
  formData.append('image_yy1', params.image_zy0)
  formData.append('personId', params.personId)
  formData.append('idCardNo', params.idCardNo)
  return request({
    url: 'irisData/add',
    method: 'post',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    data: formData
  })
}

// 人员数据下发
export function updatePersonData(personIds, deviceIds) {
  return request({
    url: 'person/updateData',
    method: 'post',
    params: {
      personIds: personIds,
      deviceIds: deviceIds
    },
    paramsSerializer: params => {
      return qs.stringify(params, { indices: false })
    }
  })
}

// 人员分组
export function personGroupAdd(groupName, description, groupIdList) {
  return request({
    url: 'acsPersonGroupRelationship/add',
    method: 'post',
    timeout: 60000,
    params: {
      groupName: groupName,
      description: description
    },
    data: groupIdList
    // paramsSerializer: params => {
    //   return qs.stringify(params, { indices: false })
    // }
  })
}
export function personGroupListPage(params) {
  return request({
    url: 'acsPersonGroup/listPage',
    method: 'get',
    params
  })
}
export function personGroupUpdate(id, groupName, description, groupIdList) {
  return request({
    url: 'acsPersonGroupRelationship/update',
    method: 'post',
    timeout: 60000,
    params: {
      groupName: groupName,
      description: description,
      id: id
    },
    data: groupIdList
  })
}
export function personGroupDel(ids) {
  return request({
    url: 'acsPersonGroup/batchDelete',
    method: 'post',
    timeout: 60000,
    params: {
      acsPersonGroupIds: ids
    },
    paramsSerializer: params => {
      return qs.stringify(params, { indices: false })
    }
  })
}

// 人员详情
export function groupList(params) {
  return request({
    url: 'acsPersonGroupRelationship/groupListPage',
    method: 'get',
    params
  })
}
// 人员组别下拉
export function getPersonGroupList() {
  return request({
    url: 'acsPersonGroup/list',
    method: 'get'
  })
}

export function syncPerson(params) {
  return request({
    url: '/person/synchronizePerson',
    method: 'post',
    timeout: 600000,
    params,
    paramsSerializer: params => {
      return qs.stringify(params, { indices: false })
    }
  })
}

export function delSyncPerson(params) {
  return request({
    url: '/person/synchronizeDelPerson',
    method: 'post',
    timeout: 600000,
    params,
    paramsSerializer: params => {
      return qs.stringify(params, { indices: false })
    }
  })
}
