product.js
4.57 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import {imgUrlMixin} from '~/mixins/index'
const videoBaseUrl = 'https://img02.glsx.com.cn/weapp/resource/miniprogram/ai-card/'
import {IMG_VERSION} from '~/utils/constantData'
Component({
behaviors: [imgUrlMixin],
properties: {
headerHeight: Number,
senceData:Object,
actNum: Number,
navIdx: Number,
isShare:{
type: Boolean,
value: false
}
},
data: {
videoBaseUrl,
img_version:IMG_VERSION(),
navList:['数字无忧权益卡'],
activeNavIdx: 0, //特色产品
tab:['适用场景','营销链路','项目亮点','转化漏斗','合作流程','合作案例'],
curTabIdx:0, //适用产品
actNum: 0, //场景
showAuth: false,
throttle: false
},
lifetimes:{
ready: function (){
wx.$eventbus.on('evt_page_scroll',(e)=>{
wx.$util.getViewInfo('.header',async (res)=> {
let heightTop = this.data.isShare ? 0 : (res?.height || 0)
let prodArr = await this.getHeight('.prod-wrap')
heightTop += prodArr[0].height
let imgArr = await this.getHeight('.img-item')
let imgHeightArr = []
imgArr.reduce((pre,cur,index)=>{
imgHeightArr.push(pre+cur.height)
return pre+cur.height
},heightTop)
let idx = imgHeightArr.findIndex(item => item > e.scrollTop)
if(idx>-1 && !this.data.throttle){
this.setData({
curTabIdx: idx
})
}
})
})
},
},
observers: {
actNum: function () {
let num = this.data.actNum;
let navList = []
let tab = ['适用场景','营销链路','项目亮点','转化漏斗','合作流程']
switch (num) {
case 0:
navList = ["数字无忧权益卡"];
tab.push("合作案例");
break;
case 1:
navList = ["汽车太阳膜"];
tab.push("合作案例");
break;
case 2:
navList = ["漆面保护膜", "改色膜"];
break;
case 3:
navList = [
"数字化美容",
"座椅通风",
"AR导航",
"氛围灯",
"360全景导航",
];
tab.push("合作案例");
break;
}
this.setData({
navList,
curTabIdx: 0,
activeNavIdx:this.data.isShare ? this.data.navIdx : 0,
tab
})
},
},
methods: {
changeTab(e){
let {idx} = e.currentTarget.dataset
this.setData({
curTabIdx: idx
})
this.data.throttle = true
wx.$util.getViewInfo('.header',async (res)=> {
let heightTop = this.data.isShare ? 0 : (res?.height || 0)
let prodArr = await this.getHeight('.prod-wrap')
heightTop += prodArr[0].height
let imgArr = await this.getHeight('.img-item')
for(let i=0;i<idx;i++){
heightTop += imgArr[i].height
}
wx.pageScrollTo({
scrollTop: heightTop,
duration: 0
})
setTimeout(()=>{
this.data.throttle = false
},500)
})
},
getHeight(cla){
return new Promise((resolve,reject)=>{
let query = wx.createSelectorQuery().in(this)
query.selectAll(cla).boundingClientRect((rect) => {
resolve(rect)
}).exec()
})
},
changeNav(event){
this.setData({
activeNavIdx: event.target.dataset.index
})
},
downVideo(e) {
let {url} = e.target.dataset
this.setData({
curVideoUrl: url
})
wx.getSetting({
success: (res)=> {
if(res.authSetting['scope.writePhotosAlbum'] === false){
this.setData({
showAuth: true
})
}else{
this.toDown()
}
}
})
},
toDown(){
wx.$api.showToast('正在下载视频...')
wx.downloadFile({
url: this.data.curVideoUrl,
success (res) {
if (res.statusCode === 200) {
wx.saveVideoToPhotosAlbum({
filePath: res.tempFilePath,
success (resp) {
wx.$api.showToast('下载成功!')
}
})
}
}
})
},
authFail(){
wx.showToast({
title: "下载视频前需要您授权'添加到相册'权限",
icon: "none",
duration: 2500,
});
},
authSuccess(){
this.toDown()
},
toSharePage() {
let { actNum, activeNavIdx ,senceData} = this.data;
wx.$router.go("checkProduct", { actNum, activeNavIdx ,senceData, fromLocal:1});
},
}
})