PickerSelect.js
2.67 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
// packageCrowdFunding/components/PickerSelect/PickerSelect.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
},
/**
* 组件的初始数据
*/
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 } = 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['activityPrice'] = `¥${this.priceFilter(arr[0]?.activityPrice / 100 || 0)}`
// 尾款金额 = 众筹价 - 定金金额
orderInfo['tailPayment'] = `¥${this.priceFilter((arr[0]?.crowdFundingPrice - arr[0]?.activityPrice) / 100 || 0)}`
orderInfo['crowdFundingPrice'] = `¥${this.priceFilter(arr[0]?.crowdFundingPrice / 100 || 0)}`
// 筛选交易流水号 订单金额字段
orderInfo['totalFee'] = arr[0]?.crowdFundingPrice || 0
// 切换商品 清空选中的交易流水号
if (copyOrderInfo.goodsId !== arr[0][pickerObj.optionId]) orderInfo['outTradeNo'] = ''
}
thisPage.setData({
orderInfo,
showPickerSelect: false
})
},
priceFilter(num) {
var pow = Math.pow(10, 2)
return (Math.round(num * pow) / pow).toFixed(2)
},
cancel() {
let thisPage = wx.$router.getPageInstance()
thisPage.setData({
showPickerSelect: false
})
}
}
})