zero-service-new.js 2.98 KB
/**
 * zero-service-new.js
 *@author dennis
 *@createtime 2018/11/9
 *@description 零元购新网络请求
 */

import BaseService from '../../../libs/services/baseService'
import { MINI_QR_TYPE, MINI_APP_TYPE} from '../../../libs/config';
import Promise from '../../../vendors/es6-promise';
import config from '../../../config.js'

const MODULE = '/activity/zerobuy';


function productTime(product) {
  if (product.status === 1) {
    product.end_time = 0;
  }

  return product;
}

export default class ZeroSellServices extends BaseService {

  constructor(props) {
    super(props)
    this.url =  config.domains.activityHost + MODULE
  }

   getList(data, complete) {
    data.channel = 1
    let self = this;
     return new Promise(function (resolve, reject) {

       self.GET(
         {
           ...data,
         },
         {
           path: '/list',
           complete
         }
       ).then(result => {
           const products = result;
           const newProducts = products.map(productTime)
          resolve({
            code: 200,
             data: newProducts
           })
       })
         .catch(error => {
           console.log(error)
           reject(error)
         })

     })
  }

  getDetail(data,complete) {

    let self = this;

    return new Promise(function (resolve, reject) {
      self.GET(
        {
          ...data
        },
        {
          path: '/content',
          complete
        }
      ).then(result => {
        let newProduct = productTime(result)
        resolve(
          {
            code: 200,
            data: newProduct
          }
        )
      })
        .catch(error => {
          console.log(error)
          reject(error)
        })
    })
  }

  getRecommend(data, complete) {
    data.channel = 1
    let self = this;
    return new Promise(function (resolve, reject) {
      self.GET(
        {
          ...data
        },
        {
          path: '/list/recommend',
          complete
        }
      )
        .then(result => {
          const products = result;
          const newProducts = products.map(productTime)
          resolve({
            code: 200,
            data: newProducts
          })
        })
        .catch(error => {
          console.log(error)
          reject(error)
        })
    })
  }

  getRecentAvatars(data, complete) {
    return this.GET(
      {
        ...data
      },
      {
        path: '/code/recent',
        complete
      }
    )
  }

  getMyList(data, complete) {
    data.channel = 1
    return this.GET(
      {
        ...data
      },
      {
        path: '/list/mine',
        complete
      }
    )
  }

  getQrCode(page_param) {
    return config.domains.yohoApi + '/wechat/miniapp/img-check.jpg?param=' + JSON.stringify(page_param) + `&miniQrType=${MINI_QR_TYPE}&miniapp_type=${MINI_APP_TYPE}`;
  }

  fetchCode(data, complete) {
    data.miniAppType = MINI_APP_TYPE
    return this.POST(
      {
        ...data
      },
      {
        path: '/code/gain',
        complete
      }
    )
  }


}