import request from '@/utils/request'

export function getGoodsList(urlParams, data) {
  return request({
    url: '/api/v1/mp/admin/goods/list',
    method: 'post',
    data,
    urlParams
  })
}

export function getGoodsDetail(goodsId) {
  return request({
    url: '/api/v1/mp/admin/goods/detail',
    method: 'post',
    data: {
      goodsId
    }
  })
}

export function addGoods(data) {
  return request({
    url: `/api/v1/mp/admin/goods/${data.goodsId ? 'update' : 'create'}`,
    method: 'post',
    data
  })
}

export function delGoods(goodsId) {
  return request({
    url: '/api/v1/mp/admin/goods/remove',
    method: 'post',
    data: { goodsId }
  })
}

export function setGoodsStatus(data) {
  return request({
    url: '/api/v1/mp/admin/goods/status',
    method: 'post',
    data
  })
}
export function setTableData(data) {
  return request({
    url: '/api/v1/mp/admin/goods/update/sortWeight',
    method: 'post',
    data,
  })
}

// 导出商品信息
export function salesiteGoodsExport( data) {
  return request({
    url: '/api/v1/mp/admin/goods/export',
    method: 'post',
    data: data,
  })
}

/**
 * Post 方式上传文件
 */
export function setCamiloShip(data, config = {},goodsId) {
  var formData  = new FormData()
  Object.keys(data).forEach(key => {
    formData.append(key, data[key])
  })
  return request({
    url: `/api/v1/mp/admin/goods/card/import/${goodsId}`,
    method: 'post',
    data: formData ,
    ...config,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}


// 下载卡密导入模板
export function cradDownload() {
  return request({
    url: '/api/v1/mp/admin/goods/card/template/download',
    method: 'post',
  })
}

// 查看卡密列表
export function cradCamiloList(urlParams, data) {
  return request({
    url: '/api/v1/mp/admin/goods/card/list',
    method: 'post',
    data,
    urlParams
  })
}

