scroll-swiper.js
2.32 KB
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
92
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
)
},
},
})