import request from './fetcher/request'

export default {
  getCategoryList (data) {
    data = Object.assign({
      pageNum: 1,
      pageSize: 999
    }, data)
    return request.get('goods/category/getCategoryList', data)
  },
  getCategoryGoods (data) {
    return request.get('goods/getGoodsListByCategory', data)
  },
  getGoodsDetail (goodsId) {
    return request.get('goods/getGoodsDetail', { goodsId })
  },
  /*
  ** @params goodsId String
  ** @params viewerId String
  */
  collectGoods (goodsId) {
    let data = {
      goodsId,
      viewerId: getApp().globalData.userinfo.viewerId
    }
    return request.post('goods/collectGoods', data)
  },

  getCollectedGoods (data = {}) {
    data = Object.assign({
      pageNum: 1,
      pageSize: 999,
      viewerId: getApp().globalData.userinfo.viewerId
    }, data)
    return request.get('goods/getCollectedGoods', data)
  },

  searchGoodsOrCompany (data) {
    const defaultData = {
      pageNum: 1,
      pageSize: 999,
      keyword: '',
      type: ''
    }
    return request.get('goods/queryGoodsOrCompany', Object.assign(defaultData, data))
  },

  getGuideByGoods (goodsId) {
    return request.get('goods/getGuideByGoods', { goodsId })
  },

  getGoodsCollectStatus (goodsId) {
    let data = {
      goodsId,
      viewerId: getApp().globalData.userinfo.viewerId
    }
    return request.get('goods/isCollected', data)
  },

  cancleCollect (goodsId) {
    let data = {
      goodsId,
      viewerId: getApp().globalData.userinfo.viewerId
    }
    return request.get('goods/cancelGoodsCollect', data)
  },

  getShopGoodsDetail (goodsId) {
    return request.post('https://shop.4dkankan.com/platform-framework/api/goods/detail', {id: Number(goodsId)}, { header: {'Content-Type': 'application/x-www-form-urlencoded'}})
  }
}