function encodeSearchParams (obj) {
  const params = []
  Object.keys(obj).forEach((key) => {
    let value = obj[key]
    if (typeof value === 'undefined') {
      value = ''
    }
    params.push([key, encodeURIComponent(value)].join('='))
  })
  return params.join('&')
}

export default function exportExcel (url, options = {}) {
  const pageName = url.split('/').slice(-2, -1).join() + url.split('/').slice(-1).join().split('.')[0] + '_table'
  const param = { ...{ phonixExportPageCode: pageName, phonixIsExport: 'Y' }, ...options }
  window.location.href = `${url}?${encodeSearchParams(param)}`
}
