action.js
2.06 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
import NP from 'number-precision'
Component({
/**
* 组件的属性列表
*/
properties: {
carList: {
type: Array,
observer: function (val) {
if (val && val.length) {
this.computePrice(val)
}
}
},
total: Number
},
/**
* 组件的初始数据
*/
data: {
count: 0
},
/**
* 组件的方法列表
*/
methods: {
toShowDetailPopup() {
this.triggerEvent('show')
},
toBuyCar() {
wx.$router.go('/packageShopmall/packageMall/pages/shoppingCart/shoppingCart')
},
checkOut() {
let {
list,
payeeMerchantName,
payeeMerchantId
} = this.data.carList[0]
let _temp_source = {}
if(list.length==1){
_temp_source.discoverGoodsSource = list[0].goodsSource
}
if(list.length>1){
this.toBuyCar()
return
}
wx.$router.go('/packageDiscovery/pages/pay/index', {
goodsList: list,
merchantName: payeeMerchantName,
deliveryType: 0,
merchantId: payeeMerchantId,
isCarOwner: true,
..._temp_source
})
},
computePrice(arr) {
let total = 0,
count = 0,
list = [],
payeeMerchantName = '',
payeeMerchantId=''
if (arr.length) {
payeeMerchantName = arr[0].payeeMerchantName
payeeMerchantId = arr[0].payeeMerchantId
arr.forEach(el => {
el.list.forEach(ele => {
count = count + ele.goodsNumber
list.push(ele)
})
})
total = list.reduce((acc, cur) => NP.plus(acc,NP.times(cur.activityPrice,cur.goodsNumber)), 0);
}
wx.$eventbus.emit('MoneyDetail', {
list,
total,
payeeMerchantName,
payeeMerchantId
})
this.setData({
count,
// total,
})
}
},
lifetimes: {
attached() {
wx.$eventbus.on('getBuyCarList', (res) => {
this.computePrice(res || [])
})
},
detached: function () {
wx.$eventbus.off('getBuyCarList')
}
},
})