import fly from "./main";
import store from "@/store/index"


//获取验证码
export function userGetCode($params) {
  return fly.post('user/get-code', $params)
}

//用户注册+登录
export function userRegister($params) {
  return fly.post('user/register', $params)
}

//用户登录
export function userLogin($params) {
  return fly.post('user/login', $params)
}

//用户详情
export function userDetail() {
  let $token = wx.getStorageSync('token')
  let $params = {
    access_token: $token
  }
  return fly.post('user/user-detail', $params)
}

//获取时间戳（10）
export function  timestamp(){
  let outcome = Math.round(new Date().getTime()/1000).toString();
  return outcome
}

//校验验证码
export function userCheckCode($params) {
  let $token = wx.getStorageSync('token')
  $params['access_token'] = $token
  return fly.post('user/check-code', $params)
}


//修改手机号码
export function userChangePhone($params) {
  let $token = wx.getStorageSync('token')
  $params['access_token'] = $token
  return fly.post('user/change-phone', $params)
}

//修改性别
export function userChangeSex($params) {
  let $token = wx.getStorageSync('token')
  $params['access_token'] = $token
  return fly.post('user/change-sex', $params)
}

//修改生日
export function userChangeBirthday($params) {
  let $token = wx.getStorageSync('token')
  $params['access_token'] = $token
  return fly.post('user/change-birthday', $params)
}

//校验验证码
export function userCheckInvite($invite_code, $js_code) {
  let $params = {
    'invite': $invite_code,
    'js_code': $js_code,
    access_token: 11
  }
  return fly.post('user/check-invite', $params);
}

//刷新登录时间
export function userUpdateLoginTime() {
  let $params = {
    access_token: wx.getStorageSync('token')
  }
  return fly.post('user/update-login-time', $params);
}

// 地址列表
export function userAddressList() {
  let $params = {}
  $params['access_token'] = wx.getStorageSync('token')
  return fly.post('user/address-list', $params)
}

//编辑地址
export function userEditAddress($address_id) {
  let $params = {}
  $params['adress_id'] = $address_id
  $params['access_token'] = wx.getStorageSync('token')
  return fly.post('user/edit-addres', $params)
}

// 添加地址
export function userAddAddress($params) {
  $params['access_token'] = wx.getStorageSync('token')
  return fly.post('user/add-address', $params)
}

// 修改地址
export function userUpdateAddress($params) {
  $params['access_token'] = wx.getStorageSync('token')
  return fly.post('user/update-address', $params)
}


//检查有没有关注公众号
export function userCheckUnionid($js_code) {
  let $params = {
    js_code: $js_code,
    access_token:wx.getStorageSync('token')
  }
  return fly.post('user/check-unionid', $params)
}

//获取轮播图列表
export function getBannerList() {
  
  let $params = {
    access_token:wx.getStorageSync('token')
  }
  return fly.post('activity/activity-list', $params)
}

//获取联名轮播图
export function getJointBanner() {
  
  let $params = {
    access_token:wx.getStorageSync('token')
  }
  return fly.post('banner/index', $params)
}

//小程序登录一次就录入一次数据
export function setUserLogin() {
 
  let $params = {
    access_token:wx.getStorageSync('token')
  }
  return fly.post('user/user-login', $params)
}
