PickerSelect.js
2.94 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
// packageCrowdFunding/components/PickerSelect/PickerSelect.js
import { formatPriceDisplay } from '~/packageCrowdFunding/utils/price.helpers.js'
Component({
/**
* 组件的属性列表
*/
properties: {
show: {
type: Boolean,
observer: function(n) {
let { pickerObj, orderInfo } = this.data
orderInfo = wx.$util.deepClone(orderInfo)
if (n) {
pickerObj?.optionList?.map(i => {
i.active = false
if (i[pickerObj?.optionId] == orderInfo[pickerObj?.optionId]) {
i.active = true
}
return i
})
this.setData({
optionList: pickerObj?.optionList || []
})
}
}
},
title: String,
orderInfo: Object,
pickerObj: Object,
isAdditionRecordOrder: Boolean,
popupHeight: {
type: String,
value: '60%'
},
goodsNumber: {
type: Number,
value: 1
}
},
/**
* 组件的初始数据
*/
data: {
},
/**
* 组件的方法列表
*/
methods: {
changeitem(e) {
let { target } = e.currentTarget.dataset
let { optionList, pickerObj } = this.data
optionList.map(i => {
i.active = false
if (i[pickerObj?.optionId] == target[pickerObj?.optionId]) {
i.active = true
}
return i
})
this.setData({optionList})
},
confirm() {
let { optionList, orderInfo, pickerObj, title, isAdditionRecordOrder, goodsNumber } = this.data
let arr = optionList?.filter(v => v.active) || []
if (!arr.length) {
return wx.showToast({
title: `请${title}`,
icon: 'none'
})
}
let thisPage = wx.$router.getPageInstance()
let copyOrderInfo = wx.$util.deepClone(orderInfo)
orderInfo[pickerObj.optionId] = arr[0][pickerObj.optionId] || ''
orderInfo[pickerObj.optionName] = arr[0][pickerObj.optionName] || ''
if (pickerObj.flag) { // 商品带出金额
orderInfo['depositPrice'] = formatPriceDisplay((arr[0]?.activityPrice * goodsNumber) / 100)
orderInfo['tailPayment'] = formatPriceDisplay(((arr[0]?.crowdFundingPrice - arr[0]?.activityPrice) * goodsNumber) / 100)
orderInfo['crowdFundingPrice'] = formatPriceDisplay((arr[0]?.crowdFundingPrice * goodsNumber) / 100)
if (isAdditionRecordOrder) {
orderInfo['totalFee'] = arr[0]?.crowdFundingPrice || 0
} else {
orderInfo['totalFee'] = (arr[0]?.crowdFundingPrice - arr[0]?.activityPrice) || 0
}
if (copyOrderInfo.goodsId !== arr[0][pickerObj.optionId]) orderInfo['outTradeNo'] = ''
orderInfo.specialGoodsId = arr[0]?.goodsId
}
thisPage.setData({
orderInfo,
showPickerSelect: false
})
this.triggerEvent('confirm', orderInfo)
},
cancel() {
let thisPage = wx.$router.getPageInstance()
thisPage.setData({
showPickerSelect: false
})
}
}
})