import axios from '@/libs/api.request';

export const login = ({username, password}) => {
  const data = {
    username,
    password
  };
  return axios.request({
    url: 'auth/login',
    method: 'post',
    data
  });
};

export const getUserInfo = () => {
  return axios.request({
    url: 'auth/me',
    method: 'get'
  });
};

export const logout = () => {
  return axios.request({
    url: 'auth/logout',
    method: 'get'
  });
};

export const changePassword = ({oldPassword, newPassword}) => {
  const data = {
    oldPassword,
    newPassword
  };
  return axios.request({
    url: 'auth/password/change',
    method: 'put',
    data
  });
};

export const getUserCmBy = ({
  page = 1,
  listRow = 10,
  phone,
  created_at
} = {}) => axios.request({
  url: 'user/businessUser',
  params: {
    page,
    listRow,
    phone,
    created_at
  }
})

export const bindUserBy = ({
  user_id,
  bd_id,
  type
} = {}) => axios.request({
  url: 'user/bind',
  method: 'post',
  data: {
    user_id,
    bd_id,
    type
  }
})

export const unBindUserById = id => axios.request({ url: 'user/unbind', method: 'post', data: { user_id: id} })

export const getExpresserPosiBy = () => axios.request({ url: '/location/deliveryman' })

export const getExpressHandleLog = data => axios.request({ url: '/user/express/handle/log', params: data })

export const postExpressBlack = data => axios.request({ url: '/user/express/blacklist', method: 'put', data })

export const getExpressDailyForwordBy = ({
  page = 1,
  listRow = 10,
  phone,
  name,
  date
} = {}) => axios.request({ url: '/activity/daily', params: {
  page,
  listRow,
  phone,
  name,
  date
} })

export const postStopActive = id => axios.request({ url: 'activity/termination/daily/welfare', method: 'put', data: { user_id: id } })

export const getDailyUserInfoBy = ({
  page = 1,
  listRow = 10,
  date,
  user_id
} = {}) => axios.request({ url: '/activity/daily/detail', params: {
  page,
  listRow,
  date,
  user_id
} })

export const getDailyActiveBy = ({
  page = 1,
  listRow = 10,
  name,
  phone
} = {}) => axios.request({ url: '/activity/double/seventh', params: {
  page,
  listRow,
  name,
  phone
} })

export const getDailyActiveInfoBy = (id) => axios.request({ url: '/activity/double/seventh/detail', params: { user_id: id } })

export const getUserDataBy = ({
  page = 1,
  listRow = 10,
  phone,
  type,
  created_at
} = {}) => axios.request({ 
  url: '/statistic/operation/userData',
  params: {
    page,
    listRow,
    phone,
    type,
    created_at: JSON.stringify(created_at)
  }
})

export const getOutputBy = ({
  name,
  phone,
  tel,
  created_at
} = {}) => axios.request({
  url: 'bd/orderCount',
  params: {
    name,
    phone,
    tel,
    created_at: JSON.stringify(created_at)
  }
})

export const getBDCheckBy = ({
  name,
  phone,
  page = 1,
  listRow = 10,
  sn,
  created_at
} = {}) => axios.request({
  url: '/bd/signing',
  params: {
    name,
    phone,
    page,
    listRow,
    sn,
    created_at: JSON.stringify(created_at)
  }
})

export const getFeedbackType = () => axios.request({ url: '/unimportant/fbType' })

export const postExpressChange = ({
  user_id,
  order_id
} = {}) => axios.request({
  url: '/order/through',
  method: 'post',
  data: { user_id, order_id } 
})

export const getOrderLocationBy = id => axios.request({ url: '/location/order/location', params: { order_id: id} })

export const postForwardBy = ({
  user_id,
  month
} = {}) => axios.request({
  url: '/activity/run/grant',
  method: 'post',
  data: {
    user_id,
    month
  }
})

export const getExpresserAnalysBy = ({
  name,
  listRow = 10,
  page = 1,
  phone,
  created_at,
  driver_type,
  order_type
} = {}) => axios.request({
  url: '/bd/dataAnalysis',
  params: {
    page,
    listRow,
    name,
    created_at: JSON.stringify(created_at),
    driver_type,
    order_type,
    phone
  }
})

export const getOrderWatingListBy = () => axios.request({ url: '/order/assignableOrder' })
