import service from '@/utils/request'
export const createGameTask = (data) => {
    return service({
      url: '/gameTask/create',
      method: 'post',
      data
    })
  }


  export const getGameTaskList = (data) => {
    return service({
      url: '/gameTask/getGameTaskList',
      method: 'post',
      data
    })
  }

  export const getGameTaskById = (data) => {
    return service({
      url: '/gameTask/getGameTaskById',
      method: 'post',
      data
    })
  }

  export const statusOperation = (data) => {
    return service({
      url: '/gameTask/statusOperation',
      method: 'post',
      data
    })
  }

  export const updateGameTask = (data) => {
    return service({
      url: '/gameTask/update',
      method: 'post',
      data
    })
  }

  export const deleteGameTask = (data) => {
    return service({
      url: '/gameTask/delete',
      method: 'post',
      data
    })
  }

  export const getGameTaskTargetList = (data) => {
    return service({
      url: '/gameTask/getGameTaskTargetList',
      method: 'post',
      data
    })
  }

  export const getGameTaskTargetById = (data) => {
    return service({
      url: '/gameTask/getGameTaskTargetById',
      method: 'post',
      data
    })
  }

  export const updateGameTaskTarget = (data) => {
    return service({
      url: '/gameTask/updateTarget',
      method: 'post',
      data
    })
  }

  export const everyDayStatistics = (data) => {
    return service({
      url: '/gameTask/everyDayStatistics',
      method: 'post',
      data
    })
  }

  export const monthStatistics = (data) => {
    return service({
      url: '/gameTask/monthStatistics',
      method: 'post',
      data
    })
  }
  
  export const gameStatistics = (data) => {
    return service({
      url: '/gameTask/gameStatistics',
      method: 'post',
      data
    })
  }

  export const gameList = (data) => {
    return service({
      url: '/gameTask/gameList',
      method: 'post',
      data
    })
  }

  export const getGameTxTaskList = (data) => {
    return service({
      url: '/gameTask/getGameTxTaskList',
      method: 'post',
      data
    })
  }

  export const taskResetFee = (data) => {
    return service({
      url: '/gameTask/taskResetFee',
      method: 'post',
      data
    })
  }

  export const getFeeAccountList = (data) => {
    return service({
      url: '/gameTask/getFeeAccountList',
      method: 'post',
      data
    })
  }

  const handleFileError = (res, fileName) => {
    if (typeof (res.data) !== 'undefined') {
      if (res.data.type === 'application/json') {
        const reader = new FileReader()
        reader.onload = function() {
          const message = JSON.parse(reader.result).msg
          ElMessage({
            showClose: true,
            message: message,
            type: 'error'
          })
        }
        reader.readAsText(new Blob([res.data]))
      }
    } else {
      var downloadUrl = window.URL.createObjectURL(new Blob([res]))
      var a = document.createElement('a')
      a.style.display = 'none'
      a.href = downloadUrl
      a.download = fileName
      var event = new MouseEvent('click')
      a.dispatchEvent(event)
    }
  }
  
  // @Tags excel
  // @Summary 导出Excel
  // @Security ApiKeyAuth
  // @accept application/json
  // @Produce  application/octet-stream
  // @Param data body model.ExcelInfo true "导出Excel文件信息"
  // @Success 200
  // @Router /gameTask/taskTargetExport [post]
  export const taskTargetExport = (tableData, fileName) => {
    service({
      url: '/gameTask/taskTargetExport',
      method: 'post',
      data: {
        fileName: fileName,
        infoList: tableData
      },
      responseType: 'blob'
    }).then((res) => {
      handleFileError(res, fileName)
    })
  }