/**
 * 到访门禁接口
 */
import request from '@/utils/request'
import qs from 'qs'

// 门禁组别下拉
export function getDoorGroupList() {
  return request({
    url: 'acsDoorGroup/list',
    method: 'get'
  })
}

// 门禁查询
export function getDoorListPage(params) {
  return request({
    url: 'door/listPage',
    method: 'get',
    params
  })
}

// 添加门禁
export function addDoor(params) {
  return request({
    url: 'door/add',
    method: 'post',
    params
  })
}
// 修改门禁
export function updateDoor(params) {
  return request({
    url: 'door/update',
    method: 'post',
    params
  })
}
// 绑定设备
export function bindDevice(params) {
  return request({
    url: 'door/bindDevice',
    method: 'post',
    params,
    paramsSerializer: params => {
      return qs.stringify(params, { indices: false })
    }
  })
}
// 删除门禁
export function delDoor(ids) {
  return request({
    url: 'door/delete',
    method: 'post',
    params: {
      ids: ids
    },
    paramsSerializer: params => {
      return qs.stringify(params, { indices: false })
    }
  })
}

// 远程开门
export function openDoor(ids) {
  return request({
    url: 'acsPermission/remoteControllAcs',
    method: 'post',
    params: {
      doorCodes: ids
    },
    paramsSerializer: params => {
      return qs.stringify(params, { indices: false })
    }
  })
}

// 常开/常闭/刷卡开门
export function openDoorAlways(params, status) {
  return request({
    url: 'door/updateOpenStatus',
    method: 'post',
    params: {
      doorIds: params.doorId,
      beginDateTime: params.beginDateTime,
      endDateTime: params.endDateTime,
      openStatus: status
    },
    paramsSerializer: params => {
      return qs.stringify(params, { indices: false })
    }
  })
}



// 门禁分组
export function doorGroupAdd(groupName, description, groupIdList) {
  return request({
    url: 'acsDoorGroupRelationship/add',
    method: 'post',
    timeout: 60000,
    params: {
      groupName: groupName,
      description: description
    },
    data: groupIdList
    // paramsSerializer: params => {
    //   return qs.stringify(params, { indices: false })
    // }
  })
}
export function doorGroupListPage(params) {
  return request({
    url: 'acsDoorGroup/listPage',
    method: 'get',
    params
  })
}
export function doorGroupUpdate(id, groupName, description, groupIdList) {
  return request({
    url: 'acsDoorGroupRelationship/update',
    method: 'post',
    timeout: 60000,
    params: {
      groupName: groupName,
      description: description,
      id: id
    },
    data: groupIdList
  })
}
export function doorGroupDel(ids) {
  return request({
    url: 'acsDoorGroup/batchDelete',
    method: 'post',
    timeout: 60000,
    params: {
      acsDoorGroupIds: ids
    },
    paramsSerializer: params => {
      return qs.stringify(params, { indices: false })
    }
  })
}

// 详情
export function groupList(params) {
  return request({
    url: '/door/listGroupPage',
    method: 'get',
    params
  })
}

export function getDoorList(params) {
  return request({
    url: 'door/groupDoorList',
    method: 'get',
    params
  })
}
export function getDoorCode() {
  return request({
    url: 'door/getDoorMaxCode',
    method: 'get'
  })
}

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