tabCell.js 2.09 KB
Component({
    properties: {
    // 这里定义了 headerText 属性,属性值可以在组件使用时指定
    headerText: {
      type: String,
      value: '默认标题文案',
    },
    tabs: Array,
    
  },
  data: {
    // 组件内部数据
    defaultStates: {},
    width:"165",
    height:"220",
    slideOffset: 0,
    activeIndex: 0,
    sliderWidth: 96,
    
  },
  attached: function () {
      
      let that = this;
      console.log("onLoad"+that.data.tabs.length)
      try{
        let systemInfo = tt.getSystemInfoSync();
        let screenWidth = systemInfo.screenWidth;
        let width = (screenWidth - 45)/ 2;
        let height = 5 * width / 3;
        let sliderWidth = systemInfo.windowWidth / that.data.tabs.length;
        let sliderOffset = systemInfo.windowWidth  / that.data.tabs.length * that.data.activeIndex;
      
        this.setData({
          width,
          height,
        })
        console.log("width:"+width)
      }catch(e){
        console.log("error:"+e.message)
      }
    },
  methods: {
    // 自定义方法
    navTabClick: function(e){
      let that = this;
      let current = e.currentTarget.dataset.index;
      console.log("index:"+e.currentTarget.dataset.index);
      let tabs = that.data.tabs;
      if(tabs[current].iconUrl){
        let iconType = tabs[current].iconType
        if(iconType === 1) {
          tabs[current].iconUrl = "../../assets/images/arrow_up@2x.png";
          tabs[current].iconType = 2;
        }else {
          tabs[current].iconUrl = "../../assets/images/arrow_down@2x.png";
          tabs[current].iconType = 1;
        }
        
      }

      var myEventDetail = tabs[current] // detail对象,提供给事件监听函数
      var myEventOption = {} // 触发事件的选项

      this.triggerEvent(
        'onTabClick',
        myEventDetail,
        myEventOption
      )
      
    // if(!tab.data){
    //   this.fetchOrderList(currentType, 1);
    // }
      that.setData({
        activeIndex: current,
        sliderOffset: that.data.sliderWidth * current,
        tabs: tabs,
      });
    

    },
    

  },
  
    
})