tabCell.js
2.09 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
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,
});
},
},
})