index.js
9.27 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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
const navStyle = 'background-color: transparent;'
let navBarHeight = 38
// import { mineApi, shopmallApi } from '~/api/api'
// import MineApi from '~/api/mineApi/index'
// import NP from 'number-precision'
// import USERAPI from '~/api/usersApi/index'
Page({
data: {
navStyle,
tabs: ['商品详情', '商品参数'],
curTabIndex: 0,
service: {
1001: '不支持无理由退货',
1002: '支持7天无理由退货',
1003: '支持7天无理由退货(拆封后不支持)',
1004: '支持7天无理由退货(激活后不支持)',
1005: '支持7天无理由退货(安装后不支持)',
1006: '支持7天无理由退货(使用后不支持)',
},
skuInfo: '',
staffShop: false,
isCarOwner: false,
payWayActions: [{ name: '金额支付', type: 1, disabled: false }, { name: '积分兑换', type: 2, disabled: false }],
detailInfo: {
pointsPrice: 25,
marketPrice: 30,
imageResponses: [{
imgUrl: 'https://img02.glsx.com.cn/weapp/resource/miniprogram/points-mall/index/index-bg.png'
}],
saleNum: 600,
remaining: 56,
goodsName: '九阳保温饭盒焖烧杯九阳保温饭盒焖烧杯九阳保温饭盒焖烧杯九阳',
goodsDescribe: '<figure class="image"><img src="https://img.yunzhonghe.com/image/1592793907468wHVTWiUHIc.png"></figure>'
}
},
appHide() {
wx.offAppHide()
wx.onAppHide(() => {
if (this.timer) clearInterval(this.timer)
this.trackQuery.view = 5
})
},
/**添加埋点结束 */
navbarReady(e) {
navBarHeight = e.detail.height
},
onPageScroll(e) {
const { curTabIndex } = this.data
if (curTabIndex == 0) {
this.scrollY = e.scrollTop
}
this.setData({
navStyle: e.scrollTop >= navBarHeight || curTabIndex ? '' : navStyle,
opacity: curTabIndex == 1 ? 1 : e.scrollTop / 200,
})
},
goodsActionReady(e) {
this.setData({
padding_bottom: e.detail
})
},
goodsActionClick(e) {
if (e.detail == 'join') return this.toAddShopCar()
if (this.data.isCarOwner) return this.judgePayWay()
this.showSkuModal(e.detail)
},
onLoad(options) {
wx.p.router.getRouterParams(options).then(params => {
// this.getDetail(options)
}).catch(err => {
console.error('参数获取失败:', err)
})
// this.getPlatFormAddress(staff)
},
showSkuModal(type) {
console.log('111')
// if (this.data.isCarOwner) return
this.setData({
showSku: true,
clickType: type
})
wx.setPageStyle({
style: {
overflow: 'hidden'
}
})
},
// 获取默认的地址
getPlatFormAddress(staff) {
wx.showLoading()
let para = {}
if (staff) {
para.businessType = 1
}else{
const SID = wx.$util.getSessionId()
if (!SID) return wx.hideLoading()
}
shopmallApi.platformAddressList(para).then(data => {
wx.hideLoading()
let contactAddress = '', defaultAddress = {}
let _isSetDefault = false
if (data && data.length) {
data.forEach(el => {
if (el.isDefault == 1) {
contactAddress = el.provinceName + el.cityName + el.countyName + el.address,
defaultAddress = el
_isSetDefault = true
}
})
if (!_isSetDefault) {
let _first = data[0]
contactAddress = _first.provinceName + _first.cityName + _first.countyName + _first.address,
defaultAddress = _first
}
}
this.setData({
addressList: data,
contactAddress,
defaultAddress
})
})
},
jump(e) {
let { url, isChooseAddress } = e.currentTarget.dataset
wx.$router.go(url, {
isChooseAddress,
platform: true,
staff: this.data.staffShop,
notIntercept: this.data.staffShop
})
},
back() {
wx.$router.back()
},
changeTab(e) {
if (this.data.opacity < 0.8) return
this.setData({
curTabIndex: e.currentTarget.dataset.index,
opacity: e.currentTarget.dataset.index
}, () => {
setTimeout(() => {
wx.pageScrollTo({
scrollTop: this.scrollY
})
}, 200)
})
},
// 获取详情
getDetail(options) {
if(!options || !options.id)return
const { id, staff, score, isCarOwner, openId } = options
const merchantId = wx.$storage.get("srcm_shopmall_merchant_id");
this.merchantId = merchantId
let para = { id }, canPay = true
if (staff) para.businessType = 1
if (isCarOwner) {
if (openId) {
this.shareOpenId = options.openId
}
this.data.enter_time = new Date().format('yyyy-MM-dd hh:mm:ss')
this.firstEnter = true
this.appHide()
this.getMyIntegral()
para.merchantId = merchantId
}
shopmallApi.platformGoodsDetail(para).then(res => {
if (res && res.specificationResponses) {
this.toGetSpecString(res, res.startQty)
}
if (staff) {
canPay = score > res.redeemPoints
}
// if (isCarOwner) {
// res.retailPrice = NP.divide(res.retailPrice, 100)
// }
this.setData({
detailInfo: res || {},
canPay,
isCarOwner
})
})
},
toGetSpecString(info, count) {
let skuInfo = this.data, num = '', weight = ''
num = `${count}${info.goodsUnit}`
weight = `${info.grossWeight}${info.grossWeightUnit}`
skuInfo = `${info.specificationResponses[0].specValue}` + `,${weight}` + `,${num}`
this.setData({
skuInfo
})
},
getCount(e) {
this.toGetSpecString(this.data.detailInfo, e.detail)
this.count = e.detail
},
// 添加购物车
toAddShopCar() {
const { detailInfo, isCarOwner } = this.data
const PARAMS = {
goodsId: detailInfo.id,
goodsNumber: this.count || detailInfo.startQty,
cartType: 2,
goodsSkuCode: detailInfo.goodsSkuCode
}
if (isCarOwner) {
PARAMS.carOwnerPlatformFlag = 1
PARAMS.merchantId = this.merchantId
PARAMS.cartType = 4
}
if(isCarOwner&&!detailInfo.retailPrice&&detailInfo.exchangeIntegral)return
shopmallApi.platformAddCar(PARAMS).then(res => {
wx.$api.showToast('添加成功!在购物车等亲~')
})
},
// 同步选择的地址
resetAddress(e) {
this.setData(e.detail)
},
toDuiHuang() {
if (this.data.canPay) {
this.showSkuModal('pay')
}
},
getViewInfo() {
wx.$api.getViewInfo(
'.fixed_btn_wrap',
res => {
this.setData({
padding_bottom: res.height
})
},
this
)
},
closeSku() {
wx.setPageStyle({
style: {
overflow: 'unset'
}
})
},
//获取我的积分
getMyIntegral() {
shopmallApi.getMyIntegralApi({}).then(res => {
if (res) {
this.setData({
availableIntegral: res.availableIntegral
})
}
})
},
judgePayWay() {
const { availableIntegral, detailInfo, payWayActions } = this.data
if (detailInfo.exchangeIntegralFlag) {
const canPay = +availableIntegral > +detailInfo.exchangeIntegral
const canMoneyPay = !detailInfo.retailPrice
if (!canPay) {
payWayActions[1].disabled = true
payWayActions[1].name = '积分不足'
}
if(canMoneyPay){
payWayActions[0].disabled = true
}
this.setData({
showPayWay: true,
canPay,
payWayActions
})
} else {
this.jumpToPay()
}
},
closePayWayModal() {
this.setData({
showPayWay: false
})
},
//选择支付方式
selectPayWay(e) {
const val = e.detail
if (val.type == 2) {
this.useJFtoPay = true
} else {
this.useJFtoPay = false
}
this.jumpToPay()
this.closePayWayModal()
},
// 跳转确认支付订单页面
jumpToPay() {
const { detailInfo } = this.data
const obj = {
useJFtoPay: this.useJFtoPay,
merchantName: detailInfo.merchantName,
merchantId: detailInfo.merchantId,
goodsList: [{
goodsImage: detailInfo.imageResponses[0].imgUrl,
goodsSkuName: detailInfo.goodsSkuName,
retailPrice: detailInfo.retailPrice,
exchangeIntegral: detailInfo.exchangeIntegral,
goodsNumber: 1,
goodsStock: detailInfo.goodsStock,
goodsId: detailInfo.id,
isPay: false,
goodsSkuCode: detailInfo.goodsSkuCode,
}]
}
const query = `?goodsInfo=${JSON.stringify(obj)}`
wx.navigateTo({
url: '/packageShopmall/packageMall/pages/platformShop/pay/index' + query,
});
},
onUnload: function () {
const {
isCarOwner
} = this.data
if (!isCarOwner) return
if (this.timer) clearInterval(this.timer)
this.trackQuery.view = 5
},
onShareAppMessage: function () {
const merchantId = wx.$storage.get('srcm_shopmall_merchant_id')
const userInfo = wx.$util.getUserInfo()
let {
detailInfo,
isCarOwner
} = this.data, open_id = ''
if (!isCarOwner) return
this.trackQuery.view = 4
if (userInfo) open_id = userInfo.openId
let title = detailInfo.goodsSkuName
let path = `${this.route}?id=${detailInfo.id}&openId=${open_id}`
let imageUrl = ''
detailInfo.imageResponses.map(e => {
imageUrl = e.imgUrl
})
if (merchantId) path = `${path}&merchantId=${merchantId}&isCarOwner=${isCarOwner || false}`
return {
imageUrl,
title,
path
}
},
})