brandDetail.js 1.77 KB
Newer Older
wanghuihui's avatar
wanghuihui committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
var util = require('../../utils/util.js');
var api = require('../../config/api.js');


var app = getApp();

Page({
  data: {
    id: 0,
    brand: {},
    goodsList: [],
    page: 1,
    size: 100,
    nodes: []
  },
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
    var that = this;
    that.setData({
      id: parseInt(options.id)
    });
    this.getBrand();
  },
  getBrand: function () {
    let that = this;
    util.request(api.BrandDetail, {
      id: that.data.id
    }).then(function (res) {
      if (res.errno === 0) {
        that.setData({
          brand: res.data.brand
        });
        that.configNode(res.data.brand.desc);
        that.getGoodsList();
      }
    });
  },
  configNode(desc) {
    let _tempDesc = desc.split('|'),
     _tempNodes = [];
    for(let i=0; i<_tempDesc.length;i++) {
      let _tempObj = {
        name: 'div',
        attrs: {
          class: 'div_class',
          style: 'color: #666666; font-size: 30rpx; margin-left:31rpx;'
        },
        children: [{
          type: 'text',
          text: ""
        }]
      };
      _tempObj.children[0].text = _tempDesc[i];
      _tempNodes.push(_tempObj);
    }
    this.setData({
      nodes: _tempNodes
    })
  },
  getGoodsList() {
    var that = this;

    util.request(api.GoodsList, {
      brandId: that.data.id,
      page: that.data.page,
      size: that.data.size
    })
      .then(function (res) {
        if (res.errno === 0) {
          that.setData({
            goodsList: res.data.goodsList
          });
        }
      });
  },
  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {
    // 页面显示

  },
  onHide: function () {
    // 页面隐藏

  },
  onUnload: function () {
    // 页面关闭

  }
})