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

//优惠券领取列表
export function getCouponReceiveList($limit = 0) {
  let $params = {}
  $params['limit'] = $limit
  $params['status'] = 1
  $params['access_token'] = wx.getStorageSync('token')
  return fly.post('coupon/coupon-receive-list', $params)
}

//已优惠券列表
export function getCouponList($limit = 0) {
  let $params = {}
  $params['limit'] = $limit
  $params['access_token'] = wx.getStorageSync('token')
  return fly.post('coupon/coupon-list', $params)
}

//已过期优惠券列表
export function getOverdueCouponList($limit = 0) {
  let $params = {}
  $params['limit'] = $limit
  $params['access_token'] = wx.getStorageSync('token')
  return fly.post('coupon/coupon-expire-list', $params)
}

//待领取优惠券
export function couponReceive($item) {
  let $params = {}
  $params['coupon_category_id'] = $item.coupon_category_id
  $params['start_time'] = $item.validity_time.start_time
  $params['end_time'] = $item.validity_time.end_time
  $params['access_token'] = wx.getStorageSync('token')
  return fly.post('coupon/coupon-receive', $params)
}

//获取首次登录领取优惠券ID
export function couponReceiveFirstID() {
  let $params = {
    "access_token": wx.getStorageSync('token'),
  }
  return fly.post('coupon/member-coupon', $params)
}

//首次登录领取优惠券
export function couponReceiveFirst($item) {
  let $params = {
    "access_token": wx.getStorageSync('token'),
    "coupon_category_id": $item.ID,
    "start_time": $item.start_time,
    "end_time": $item.end_time,
  }
  return fly.post('coupon/coupon-receive', $params)
}

//支付时优惠券
export function payCoupon($item) {
  let $params = {
    "access_token": wx.getStorageSync('token'),
    "price": $item.priceParam,
    "goods_id": $item.goods_id,
  }
  return fly.get('coupon/choose-coupon', $params)
}

// 外发卡券信息(无参数)
export function outputCoupon() {
  let $params = {
    "access_token": wx.getStorageSync('token'),
  }
  return fly.post('coupon/out-list', $params)
}

// 外发卡券信息(有other参数)
export function outCardCoupon() {
  let $params = {
    "access_token": wx.getStorageSync('token'),
  }
  return fly.post('coupon/out-card', $params)
}