index.js 2.17 KB
Newer Older
程智春 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
// static/nativeComponents/SpeedyNav/index.js
const app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    datas:{
      type : Object
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    getTypeStyle: 'across',
    categoryList : [],
    targetShow: true,
    loading: false,
    getColumnWidth : '',
    getStyle : ''
  },

  ready(){
    this.setData({
      getTypeStyle: this.data.datas.componentData.typeStyle
    })

    let arr = ['50%', "33.3%", "25%", "20%", "16.6%"]

    this.setData({
      getColumnWidth: arr[this.data.datas.componentData.columnNum - 2]
    })

    if (this.data.datas.componentData.style == 'circle'){
      this.setData({
        getStyle : '20%'
      })
    } else if (this.data.datas.componentData.style == 'rect'){
      this.setData({
        getStyle: '0'
      })
    } else if (this.data.datas.componentData.style == 'whole-circle'){
      this.setData({
        getStyle: '50%'
      })
    }

    app.indexApi.get_product_category({
      whetherShowSoldOutGoods: null
    }).then(res => {
      if (res.data.code == 200 && res.data.data.category[0] && res.data.data.category[0].children){
        this.setData({
          loading : true
        })
        res.data.data.category[0].children.forEach(item => {

          if (item.categoryBigImg) {
程智春 committed
60
            item.categoryBigImg = app.DFSImg(item.categoryBigImg,400,400)
程智春 committed
61
          }
程智春 committed
62 63
          if (item.categoryImgUrl) {
            item.categoryImgUrl = app.DFSImg(item.categoryImgUrl,400,400)
程智春 committed
64 65
          }

侯体倬 committed
66

程智春 committed
67 68 69 70 71 72 73 74
        })

        console.log(res.data.data.category[0].children, 'res.data.data.category[0].children')

        this.setData({
          categoryList: res.data.data.category[0].children
        })
        if (this.data.categoryList.length == 0) {
程智春 committed
75
          this.setData({
程智春 committed
76
            targetShow: false
程智春 committed
77
          })
程智春 committed
78
        }
程智春 committed
79 80 81 82 83 84 85 86 87 88 89
      }
    })


  },
  /**
   * 组件的方法列表
   */
  methods: {
    onclick(e){
      let item = e.currentTarget.dataset.item
侯体倬 committed
90
      app.trackCpn(e, this.data.datas.componentName, item)
程智春 committed
91 92 93 94 95 96 97
      app.$themeToLink({
        type: 1,
        link: `/goods/commodityMenu?categoryName=${item.categoryName}&categoryId=${item.id}`
      })
    }
  }
})