import { $get, $post } from '@/utils'

export const SHOP_ACTION = (params) => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/order/actions', params);
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const SHOP_DETAIL = (params) => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/goods/info', params);
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const SHOP_ADD_CART = (params) => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/add/cart', params);
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const SHOP_CART_LIST = (is_free = 0) => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/cart/list', { is_free });
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const SHOP_CART_CONFIRM = (params) => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/cart/confirm', params);
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const SHOP_CART_FCONFIRM = (params) => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/cart/fconfirm', params);
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const SHOP_CART_DEL = (id = '') => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/cart/del', { id });
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const SHOP_ORDER_SUBMIT = (params) => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/order/submit', params);
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const SHOP_ORDER_FSUBMIT = (params) => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/order/fsubmit', params);
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})


export const SHOP_PAY_INFO = (params = {}) => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/pay/info', params);
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const SHOP_SUBMIT_PAY = (params) => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/submit/pay', params);
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const SHOP_ORDER_STATUS = () => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/order/status');
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const SHOP_ORDER_GETPAY = (orderids = '') => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/order/getpay', { orderids });
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const SHOP_ORDER_DETAIL = (orderid = '') => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/order/detail', { orderid });
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const CONTENT_FLOAT = (params) => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/content/float', params);
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const SHOP_SEARCH_SIMILAR = (params) => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/search/similar', params);
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const SHOP_USER_COLLECT = (params) => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/user/collect', params);
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const SHOP_SELLER_INFO = (params) => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/seller/info', params);
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})


export const SHOP_COLLECT_List = (params) => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/collect/list', params);
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})


export const SHOP_PACKAGES_SUBMIT = (params) => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/packages/submit', params);
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const SHOP_ADDRESS_LIST = () => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/address/list');
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const SHOP_ADDRESS_ADD = (params) => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/address/add', params);
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const SHOP_PACKAGES_CREATED = (params) => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/packages/create', params);
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const SHOP_ADDRESS_DEL = (id = '') => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/address/del', { id });
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const SHOP_PACKAGES_PAY = (params) => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/packages/pay', params);
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const SHOP_PACKAGES_DETAIL = (id = '') => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/packages/detail', { id });
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const SHOP_PACKAGES_CANCEL = (id = '') => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/packages/cancel', { id });
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const SHOP_PACKAGES_FINISH = (id = '') => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/packages/finish', { id });
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const VIDEO_LISTS = ({ limit = 10, active_id = 0, isLoading = false }) => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/discover/video/lists', { limit, active_id }, { isLoading });
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const VIDEO_VIEWS = (id = '') => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/discover/video/views', { id }, { isLoading: true });
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const SHOP_ORDER_EXPRESS = (orderid = '') => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/order/express', { orderid }, { isLoading: true });
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const SHOP_STOCKS_INFO = (id = '') => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/stocks/info', { id });
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const SHOP_GET_CANCOUPON = (money = '') => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/get/cancoupon', { money });
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const SHOP_EXPRESS_TEMPLATE = () => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/express/template');
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})


export const SHOP_PAY_STATUS = (params = {}) => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/pay/status', { ...params });
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const SHOP_ORDER_CANCEL = (params = {}) => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/order/cancel', { ...params });
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const SHOP_EDIT_CART = (params = {}) => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/edit/cart', { ...params });
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})


export const SHOP_SHOPCOUNPON_LIST = (params = {}) => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/shopcoupon/list', { ...params });
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const SHOP_GET_SHOPCOUPON = (money = 0) => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/get/shopcoupon', { money });
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const SHOP_INDEX_ORDER = (params) => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/index/order', params, { isLoading: true });
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const SHOP_GOODS_CATEGORY = (params) => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/goods/category', params, { isLoading: true });
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})


export const SHOP_ADD_COMMENTS = (params) => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/add/comments', params, { isLoading: true });
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})


export const SHOP_SHOW_COMMENTS = (orderid = '') => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/show/comments', { orderid });
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})


export const SHOP_BUYBACK_LISTS = () => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/buyback/lists');
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})


export const SHOP_SUBMIT_BUYBACK = (params) => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/submit/buyback', params);
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const SHOP_BUYBACK_ORDER = (status = 0) => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/buyback/order', { status });
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})

export const SHOP_BUYBACK_EXPRESS = (params) => new Promise(async (resolve, reject) => {
  try {
    const res = await $post('/shop/backbuy/express', params);
    const { ret } = res.data
    if (ret == 1) {
      resolve(res.data)
    }
    reject(res.data)
  } catch (error) { }
})
