import request from '../util/request'
import $n from '../util/nothing'
import Enums from '../util/Enums'
import Qs from 'qs'

/**
 * ajax请求
 * @param {*}
 */
export function _request ({
  url,
  params = {},
  method = 'post',
  token = false,
  timeout = false,
  contentType = Enums.ContentType.JSON_UTF8,
  headers = {}
} = {}) {
  headers['Content-Type'] = contentType;
  return request.request(url, $n._caseValue(contentType, Enums.ContentType.FORM_UTF8, Qs.stringify(params), params), {
    method: method,
    _token: token,
	_timeout: timeout,
    headers
  })
}

/**
 * 分页查询
 * @param {*}
 */
export function _queryPage ({
  url,
  params = {},
  page = {},
  method = 'post',
  token = false,
  contentType = Enums.ContentType.JSON_UTF8
} = {}) {
  return _request({
    url,
    params,
    method,
    token,
    contentType,
    headers: {
      'pageNum': page.pageNum,
      'pageSize': page.pageSize
    }
  })
}
/**
 * 流式分页查询
 * @param {*}
 */
export function _queryFlowPage ({
  url,
  params = {},
  page = {},
  method = 'post',
  token = false,
  contentType = Enums.ContentType.JSON_UTF8
} = {}) {
  return _request({
    url,
    params,
    method,
    token,
    contentType,
    headers: {
      'beginTime': page.beginTime,
      'direction': page.direction,
      'orderBy': page.orderBy,
      'pageSize': page.pageSize
    }
  })
}
