scroll-swiper.js 2.32 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 tabInfo = e.currentTarget.dataset.tabInfo;
      let current = tabInfo.id;
      
      let tabs = this.data.tabs;
      console.log("navTabClick iconType:"+tabInfo.iconType);
      if(tabInfo.iconUrl){
        let iconType = tabInfo.iconType;
        if(iconType === 2) {
          tabs[current].iconUrl = "../../assets/images/arrow_up@2x.png";
          tabs[current].iconType = 1;
        }else {
          tabs[current].iconUrl = "../../assets/images/arrow_down@2x.png";
          tabs[current].iconType = 2;
        }
        this.data.tabs = tabs;
       
        
      }
      console.log("navTabClick iconType:"+tabs[current].iconType+"this.data:"+this.data.tabs[current].iconType);

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

      
      // this.data.activeIndex = current;
      // this.data.sliderOffset = this.data.sliderWidth * current;
      
      this.setData({
        activeIndex: current,
        sliderOffset: this.data.sliderWidth * current,
        tabs: tabs,
      });
      this.triggerEvent(
        'onTabClick',
        myEventDetail,
        myEventOption
      )
    

    },
    

  },
  
    
})