brandDetail.js 2.42 KB
import { ACTIVITY_HOST, YOHOOD_HOST, API_HOST } from '../../libs/config';
import { GET, POST } from '../../libs/request';
import { parseBrandListData } from '../../utils/productList';
import jumpToMiniapp from '../../router/jump-to-miniapp';

Page({
  data: {
    shopId: '',
    brandInfo: {},
    productList: {
      page: 0,
      page_total: 0,
      total: 0,
      list: [],
    },
  },
  onLoad: function(options) {
    //Do some initialize when page load.
    let brandId = options.brandId;
    let brandName = options.brandName;
    wx.setNavigationBarTitle({title: brandName || '品牌详情'});

    this.fetchDetail(brandId);    
  },
  onReady: function() {
    //Do some when page ready.
    
  },
  onShow: function() {
    //Do some when page show.
    
  },

  fetchDetail(brandId) {
    let that = this;
    let param = {
      id: brandId
    }
    GET(YOHOOD_HOST + '/brand/getBrandById', param)
      .then(data => {

        let brandInfo = data.data;
        wx.setNavigationBarTitle({title: brandInfo.name || '品牌详情'});
        
        let link = brandInfo.link; 
        let shopId = link.split('=').pop();
        that.fetchProductList(shopId);

        that.setData({
          brandInfo,
          shopId
        })
      })
      .catch(error => {

      });
  },

  fetchProductList(brandId) {
    let that = this;
    let productList = this.data.productList;
    let param = {
      id: brandId
    }
    GET(ACTIVITY_HOST + '/api/yohood/getShopProduct', param)
      .then(data => {
        if (data && data.code==200 && data.data) {
          let product_list = data.data.product_list;
          product_list = parseBrandListData(product_list);
          productList.list = product_list;
          productList.total = data.data.total;
          productList.page_total = data.data.page_total;
          productList.page = data.data.page;

          that.setData({
            productList
          })
        }
      })
      .catch(error => {

      });
  },

  enterShop(event) {
    let shopId = this.data.shopId;
    // page_name=brands&is_red_shop=1&shop_id=2192&shop_name=TEEBACCO&shop_template_type=1
    let data = {
      shop_id: shopId,
    };
    jumpToMiniapp({ app: 'yohobuy', page: 'shopDetail', data: data })
  },

  onHide: function() {
    //Do some when page hide.
    
  },
  onUnload: function() {
    //Do some when page unload.
    
  },
  onPullDownRefresh: function() {
    //Do some when page pull down.
    
  }
})