index.js
4.59 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
// pages/crowdfunding/components/service/index.js
import {
shopmallApi
} from '../../api/index'
let backgroundAudioManager
Component({
/**
* 组件的属性列表
*/
properties: {
detail: {
type: Object,
value: {},
observer: function (n) {
this.init(n)
}
},
groupInfo: {
type: Object,
value: () => {}
},
isFestival: {
type: Boolean,
value: false,
},
musicStatus: {
type: Boolean,
value: false,
observer: function (n) {
// true:播放状态,false:暂停状态
this.changeMusicStatus(n)
}
},
showTopButton: {
type: Boolean,
value: false
}
},
/**
* 组件的初始数据
*/
data: {
musicState: false,
showOnlineService: false,
showOrderBtn: false,
activityBigImg: 'https://img02.glsx.com.cn/weapp/resource/miniprogram/expandedGold/festival_38.png',
},
/**
* 组件的方法列表
*/
methods: {
// 初始化
init(n) {
let _this = this
if (n.activityMusic) {
backgroundAudioManager = wx.createInnerAudioContext()
wx.setInnerAudioOption && wx.setInnerAudioOption({
obeyMuteSwitch: false
})
backgroundAudioManager.src = n.activityMusic
backgroundAudioManager.onCanplay(_=>{
backgroundAudioManager.play()
const thisPage = wx.$router.getPageInstance()
if(thisPage.isLiveFull) backgroundAudioManager.pause()
})
// 监听背景音乐暂停播放
backgroundAudioManager.onPause(function () {
_this.setData({
musicState: true
})
})
// 监听背景音乐播完
backgroundAudioManager.onPlay(function () {
_this.setData({
musicState: false,
showMusic: true
})
})
// 监听背景音乐播完完毕,重新播放
backgroundAudioManager.onEnded(function () {
backgroundAudioManager.play()
})
}
},
// 打开客服
goService() {
const appEnter = wx.getEnterOptionsSync()
let o = this.data.detail
if (!o.customerServerUrl) {
this.setData({
showOnlineService: true
})
return false;
}
if (appEnter.scene === 1154) {
wx.$eventbus.emit('showTimeLineToast')
return
}
wx.openCustomerServiceChat({
extInfo: {
url: o.customerServerUrl
},
corpId: 'wx51bda2e574d24a91',
fail: function (e) {
wx.showModal({
title: '提示',
content: JSON.stringify(e),
})
}
})
},
// 背景音乐暂停、播放
musicPause() {
let n = this.data.detail,
{
musicState
} = this.data
if (!backgroundAudioManager) {
backgroundAudioManager = wx.createInnerAudioContext()
backgroundAudioManager.src = n.activityMusic
}
if (musicState) {
backgroundAudioManager.play()
this.triggerEvent('change', true)
} else {
backgroundAudioManager.pause()
this.triggerEvent('change', false)
}
wx.vibrateShort()
},
// 停止播放背景音乐
changeMusicStatus(musicStatus) {
let n = this.data.detail
if (!n.activityMusic) return
if (!backgroundAudioManager) {
backgroundAudioManager = wx.createInnerAudioContext()
backgroundAudioManager.src = n.activityMusic
}
if (!musicStatus) {
backgroundAudioManager.pause()
} else {
backgroundAudioManager.play()
}
},
// 滚动到顶部
goTop() {
wx.pageScrollTo({
scrollTop: 0
})
},
// 拨打电话
makePhone() {
let o = this.data.detail;
if (o.customerServicePhone) {
return false;
}
wx.makePhoneCall({
phoneNumber: o.customerServicePhone
})
},
// 关闭客服弹框
closeService() {
this.setData({
showOnlineService: false
})
},
// 获取订单列表
getOrderList() {
shopmallApi.getOrderList(this.data.detail.id).then(res => {
let data = res.data || []
if (data && data.length) {
this.setData({
showOrderBtn: true
})
}
})
},
// 查看订单
lookOrderList() {
let n = this.data.detail;
wx.$router.go(`/packageShopmall/packageCrowdfunding/pages/order/list?id=${n.id}`)
}
},
lifetimes: {
ready() {
wx.$eventbus.on('musicPause', _ => {
this.musicPause()
})
}
}
})