import request from '@/utils/request';
import { baseURL } from '@/config';

export function getList(data) {
  let param = '?page=' + data.page + '&size=' + data.size;
  if (data.regionCode) {
    param += '&regionCode=' + data.regionCode;
  }
  if (data.name) {
    param += '&name=' + data.name;
  }
  if (data.leader) {
    param += '&leader=' + data.leader;
  }
  if (data.contact) {
    param += '&contact=' + data.contact;
  }
  if (data.groupId) {
    param += '&groupId=' + data.groupId;
  }
  return request({
    url: '/iot/project/select' + param,
    method: 'get',
    data,
  });
}

export function doEdit(data) {
  return request({
    url: '/iot/project/update',
    method: 'post',
    data,
  });
}

export function getProjectGroup(data) {
  return request({
    url: '/iot/project/selectAllProjectGroup',
    method: 'get',
    data,
  });
}

//查询报警方式列表
export function selectAlarmTypeList(data) {
  return request({
    url: '/iot/project/selectAlarmTypeList',
    method: 'get',
    data,
  });
}

//查询所有报警联系人以及项目所绑定的报警联系人
export function getAlarmUser(data) {
  return request({
    url: '/iot/project/getAlarmUser?projectId=' + data.projectId,
    method: 'get',
    data,
  });
}

//查询所有报警联系人以及项目所绑定的报警联系人
export function addAlarmUsers(data) {
  return request({
    url: '/iot/project/addAlarmUsers',
    method: 'post',
    data,
  });
}

export function doDelete(data) {
  return request({
    url: '/iot/project/remove?',
    method: 'post',
    data,
  });
}

export function doAdd(data) {
  return request({
    url: '/iot/project/insert',
    method: 'post',
    data,
  });
}

//导出
export function exportProject(data) {
  let param = '?page=' + data.page + '&size=' + data.size;
  if (data.regionCode) {
    param += '&regionCode=' + data.regionCode;
  }
  if (data.name) {
    param += '&name=' + data.name;
  }
  if (data.leader) {
    param += '&leader=' + data.leader;
  }
  if (data.contact) {
    param += '&contact=' + data.contact;
  }
  if (data.groupId) {
    param += '&groupId=' + data.groupId;
  }
  return baseURL + '/iot/project/export' + param;
}
