import axios from 'axios'
import Vue from 'Vue'

// 非父子组件之间通信
export const bus = new Vue()
// http://192.168.0.245:8081/datamanage/
export const dataUrl = '/datamanage/'

// -------------------- 数据管理系统 - 修改token ------------------
// export let token = ''
// export let reToken = (tok) => {
//   token = tok
// }

// headers: {'Content-type': 'application/json;charset=utf8', 'token': token}

// -------------------- 自动判断请求方式
const requestMethodAuto = (params, data) => {
  for (let i in data) { return 'post' }
  for (let i in params) { return 'get' }
}

// -------------------- 数据管理系统 - 用户登录 ------------------ login
export let requestLogin = (params, data, callback) => {
  axios({
    url: dataUrl + 'login',
    method: requestMethodAuto(params, data),
    params: params,
    data: data
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
// -------------------- 数据管理系统 - 用户退出登录 ------------------ leave
export let requestLeave = (params, data, callback) => {
  axios({
    url: dataUrl + 'leave',
    method: requestMethodAuto(params, data),
    params: params,
    data: data
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
// -------------------- 数据管理系统 - 渠道数据 ------------------ getDataAll?start=0&end=0
export let requestGetDataAll = (params, data, callback) => {
  axios({
    url: dataUrl + 'getDataAll',
    method: requestMethodAuto(params, data),
    params: params,
    data: data
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
// -------------------- 数据管理系统 - 详细数据 ------------------ getDataByTempName?start=0&end=0
export let requestGetDataByTempName = (params, data, callback) => {
  axios({
    url: dataUrl + 'getDataByTempName',
    method: requestMethodAuto(params, data),
    params: params,
    data: data
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
// -------------------- 数据管理系统 - 详细数据 - 搜索词模糊匹配列表 ------------------ getSource
export let requestGetSource = (params, data, callback) => {
  axios({
    url: dataUrl + 'getSource',
    method: requestMethodAuto(params, data),
    params: params,
    data: data
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
// -------------------- 数据管理系统 - 检测模板 - 获取列表信息 ------------------ findAllTmp
export let requestFindAllTmp = (params, data, callback) => {
  axios({
    url: dataUrl + 'findAllTmp',
    method: requestMethodAuto(params, data),
    params: params,
    data: data
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
// -------------------- 数据管理系统 - 检测模板 - 新建模板 ------------------ saveTmp
export let requestSaveTmp = (params, data, callback) => {
  axios({
    url: dataUrl + 'saveTmp',
    method: requestMethodAuto(params, data),
    params: params,
    data: data
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
// -------------------- 数据管理系统 - 检测模板 - 更新模板 ------------------ updateTmp
export let requestUpdateTmp = (params, data, callback) => {
  axios({
    url: dataUrl + 'updateTmp',
    method: requestMethodAuto(params, data),
    params: params,
    data: data
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
// -------------------- 数据管理系统 - 检测模板 - 删除模板 ------------------ deleteTmp
export let requestDeleteTmp = (params, data, callback) => {
  axios({
    url: dataUrl + 'deleteTmp',
    method: requestMethodAuto(params, data),
    params: params,
    data: data
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
// -------------------- 数据管理系统 - 检测模板 - 开关/on ------------------ startTmp
export let requestStartTmp = (params, data, callback) => {
  axios({
    url: dataUrl + 'startTmp',
    method: requestMethodAuto(params, data),
    params: params,
    data: data
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
// -------------------- 数据管理系统 - 检测模板 - 开关/off ------------------ stopTmp
export let requestStopTmp = (params, data, callback) => {
  axios({
    url: dataUrl + 'stopTmp',
    method: requestMethodAuto(params, data),
    params: params,
    data: data
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
// -------------------- 数据管理系统 - 检测信息 - 获取所有信息列表 ------------------ findAllMsg
export let requestFindAllMsg = (params, data, callback) => {
  axios({
    url: dataUrl + 'findAllMsg',
    method: requestMethodAuto(params, data),
    params: params,
    data: data
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
// -------------------- 数据管理系统 - 检测信息 - 详情 - 处理 ------------------ handle
export let requestHandle = (params, data, callback) => {
  axios({
    url: dataUrl + 'handle',
    method: requestMethodAuto(params, data),
    params: params,
    data: data
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
// -------------------- 数据管理系统 - 检测信息 - 删除信息 ------------------ deleteMsg
export let requestDeleteMsg = (params, data, callback) => {
  axios({
    url: dataUrl + 'deleteMsg',
    method: requestMethodAuto(params, data),
    params: params,
    data: data
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
// -------------------- 数据管理系统 - 处理记录 - 获取记录列表 ------------------ findHandleMsg
export let requestFindHandleMsg = (params, data, callback) => {
  axios({
    url: dataUrl + 'findHandleMsg',
    method: requestMethodAuto(params, data),
    params: params,
    data: data
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
// -------------------- 数据管理系统 - 用户管里 - 获取用户列表 ------------------ getPerson
export let requestGetPerson = (params, data, callback) => {
  axios({
    url: dataUrl + 'getPerson',
    method: requestMethodAuto(params, data),
    params: params,
    data: data
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
// -------------------- 数据管理系统 - 用户管里 - 修改用户信息 ------------------ updatePerson
export let requestUpdatePerson = (params, data, callback) => {
  axios({
    url: dataUrl + 'updatePerson',
    method: requestMethodAuto(params, data),
    params: params,
    data: data
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
// -------------------- 数据管理系统 - 用户管里 - 新建用户 ------------------ savePerson
export let requestSavePerson = (params, data, callback) => {
  axios({
    url: dataUrl + 'savePerson',
    method: requestMethodAuto(params, data),
    params: params,
    data: data
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
// -------------------- 数据管理系统 - 用户管里 - 删除用户 ------------------ deletePerson
export let requestDeletePerson = (params, data, callback) => {
  axios({
    url: dataUrl + 'deletePerson',
    method: requestMethodAuto(params, data),
    params: params,
    data: data
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
// -------------------- 数据管理系统 - 数据库信息 - 获取列表信息 ------------------ getServer
export let requestGetServer = (params, data, callback) => {
  axios({
    url: dataUrl + 'getServer',
    method: requestMethodAuto(params, data),
    params: params,
    data: data
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
// -------------------- 数据管理系统 - 数据库信息 - 删除数据库 ------------------ deleteServer
export let requestDeleteServer = (params, data, callback) => {
  axios({
    url: dataUrl + 'deleteServer',
    method: requestMethodAuto(params, data),
    params: params,
    data: data
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
// -------------------- 数据管理系统 - 数据库信息 - 新建数据库 ------------------ insertServer
export let requestInsertServer = (params, data, callback) => {
  axios({
    url: dataUrl + 'insertServer',
    method: requestMethodAuto(params, data),
    params: params,
    data: data
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
// -------------------- 数据管理系统 - 数据库信息 - 更新数据库 ------------------ updateServer
export let requestUpdateServer = (params, data, callback) => {
  axios({
    url: dataUrl + 'updateServer',
    method: requestMethodAuto(params, data),
    params: params,
    data: data
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
// -------------------- 数据管理系统 - 渠道表信息 - 获取列表 ------------------ getChannel
export let requestGetChannel = (params, data, callback) => {
  axios({
    url: dataUrl + 'getChannel',
    method: requestMethodAuto(params, data),
    params: params,
    data: data
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
// -------------------- 数据管理系统 - 渠道表信息 - 新建列表 ------------------ insertChannel
export let requestInsertChannel = (params, data, callback) => {
  axios({
    url: dataUrl + 'insertChannel',
    method: requestMethodAuto(params, data),
    params: params,
    data: data
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
// -------------------- 数据管理系统 - 渠道表信息 - 修改列表 ------------------ updateChannel
export let requestUpdateChannel = (params, data, callback) => {
  axios({
    url: dataUrl + 'updateChannel',
    method: requestMethodAuto(params, data),
    params: params,
    data: data
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
// -------------------- 数据管理系统 - 渠道表信息 - 删除列表 ------------------ deleteChannel
export let requestDeleteChannel = (params, data, callback) => {
  axios({
    url: dataUrl + 'deleteChannel',
    method: requestMethodAuto(params, data),
    params: params,
    data: data
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
// -------------------- 数据管理系统 - 字段表信息 - 获取列表 ------------------ getFields
export let requestGetFields = (params, data, callback) => {
  axios({
    url: dataUrl + 'getFields',
    method: requestMethodAuto(params, data),
    params: params,
    data: data
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
// -------------------- 数据管理系统 - 字段表信息 - 新建列表 ------------------ insertFields
export let requestInsertFields = (params, data, callback) => {
  axios({
    url: dataUrl + 'insertFields',
    method: requestMethodAuto(params, data),
    params: params,
    data: data
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
// -------------------- 数据管理系统 - 字段表信息 - 更新列表 ------------------ updateFields
export let requestUpdateFields = (params, data, callback) => {
  axios({
    url: dataUrl + 'updateFields',
    method: requestMethodAuto(params, data),
    params: params,
    data: data
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
// -------------------- 数据管理系统 - 字段表信息 - 更新列表 ------------------ deleteFields
export let requestDeleteFields = (params, data, callback) => {
  axios({
    url: dataUrl + 'deleteFields',
    method: requestMethodAuto(params, data),
    params: params,
    data: data
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
// -------------------- 数据管理系统 - 渠道列表 ------------------ getShowChannel
export let requestGetShowChannel = (callback) => {
  axios({
    url: dataUrl + 'getShowChannel',
    method: 'post'
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
// -------------------- 数据管理系统 - 修改渠道 ------------------ changePt
export let requestChangePt = (params, data, callback) => {
  axios({
    url: dataUrl + 'changePt',
    method: requestMethodAuto(params, data),
    params: params,
    data: data
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
// -------------------- 数据管理系统 - 数据库信息 - 获取参数说明列表 ------------------ getParam
export let requestGetParam = (callback) => {
  axios({
    url: dataUrl + 'getParam',
    method: 'post'
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
// -------------------- 数据管理系统 - 字段表信息 - 获取渠道信息列表 ------------------ getDisChannel
export let requestGetDisChannel = (callback) => {
  axios({
    url: dataUrl + 'getDisChannel',
    method: 'post'
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
// -------------------- 数据管理系统 - 检测模板 - 获取字段信息 ------------------ getAllFields
export let requestGetAllFields = (params, data, callback) => {
  axios({
    url: dataUrl + 'getAllFields',
    method: requestMethodAuto(params, data),
    params: params,
    data: data
  }).then((response) => {
    callback(response)
  }).catch((response) => {
    callback(response)
  })
}
