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

// 设备查询
export function getCardList(params) {
  return request({
    url: 'acsCard/listPage',
    method: 'get',
    params
  })
}

// 添加卡
export function addCard(params) {
  return request({
    url: 'acsCard/add',
    method: 'post',
    params
  })
}

// 修改设备
export function updateCard(params) {
  return request({
    url: 'acsCard/update',
    method: 'post',
    params
  })
}

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

// 删除设备
export function delCard(ids) {
  return request({
    url: 'acsCard/delete',
    method: 'post',
    params: {
      ids: ids
    },
    paramsSerializer: params => {
      return qs.stringify(params, { indices: false })
    }
  })
}

// 批量导出
export function batchExportCard(params) {
  return request({
    url: 'acsPermission/batchAcsImport',
    method: 'get',
    timeout: 120000,
    params,
    responseType: 'blob' // 这一步也很关键，一定要加上 responseType 值为 blob
  })
}

export function getStaffList(params) {
  return request({
    url: 'acsDeviceCard/listStaff',
    method: 'post',
    params,
    paramsSerializer: params => {
      return qs.stringify(params, { indices: false })
    }
  })
}

export function getCardRecords() {
  return request({
    url: 'acsPermission/getCardRecords',
    method: 'post',
    params: {
      doorCode: ''
    }
  })
}

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

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

