payFeeDiscount.vue
7.22 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
<template>
<el-card v-if="shouldShowDiscounts">
<div slot="header" class="flex justify-between">
<span>{{ $t('payFeeDiscount.discountInfo') }}</span>
</div>
<el-table :data="feeDiscounts" border style="width: 100%">
<el-table-column align="center" width="60">
<template slot-scope="scope">
<el-checkbox v-model="selectDiscountIds" :label="scope.row.discountId"
@change="computeFeeDiscount"></el-checkbox>
</template>
</el-table-column>
<el-table-column prop="discountType" align="center" :label="$t('payFeeDiscount.discountType')">
<template slot-scope="scope">
{{ getDiscountTypeName(scope.row.discountType) }}
</template>
</el-table-column>
<el-table-column prop="discountName" align="center" :label="$t('payFeeDiscount.discountName')" />
<el-table-column prop="ruleName" align="center" :label="$t('payFeeDiscount.ruleName')" />
<el-table-column align="center" :label="$t('payFeeDiscount.rule')">
<template slot-scope="scope">
<div v-for="(item, index) in scope.row.feeDiscountSpecs" :key="index">
{{ item.specName }}:{{ item.specValue }}
</div>
</template>
</el-table-column>
<el-table-column align="center" :label="$t('payFeeDiscount.discountAmount')">
<template slot="header">
<span>{{ $t('payFeeDiscount.discountAmount') }}</span>
<el-tooltip effect="dark" :content="$t('payFeeDiscount.discountTooltip')" placement="top">
<i class="el-icon-info" style="margin-left:5px"></i>
</el-tooltip>
</template>
<template slot-scope="scope">
{{ formatDiscountPrice(scope.row) }}
<span>{{ $t('payFeeDiscount.yuan') }}</span>
</template>
</el-table-column>
</el-table>
</el-card>
</template>
<script>
import { getCommunityId } from '@/api/community/communityApi'
import { dateAdd } from '@/utils/dateUtil'
import { computeFeeDiscount } from '@/api/fee/payFeeOrderApi'
export default {
name: 'PayFeeDiscount',
data() {
return {
dialogVisible: false,
feeDiscounts: [],
feeId: '',
payerObjId: '',
payerObjType: '',
endTime: '',
custEndTime: '',
communityId: '',
cycles: 1,
selectDiscountIds: [],
totalDiscountMoney: 0.0
}
},
computed: {
shouldShowDiscounts() {
return (this.feeDiscounts.length > 0) ||
(this.selectDiscountIds.length === 0 && this.feeDiscounts.length !== 0) ||
(this.selectDiscountIds.length !== this.feeDiscounts.length && this.totalDiscountMoney === 0)
}
},
methods: {
open(params) {
this.feeId = params.feeId
this.payerObjId = params.payerObjId
this.payerObjType = params.payerObjType
this.endTime = params.endTime
this.custEndTime = params.custEndTime
this.cycles = params.cycles || 1
this.listFeeDiscounts()
},
close() {
this.dialogVisible = false
},
async listFeeDiscounts() {
try {
this.communityId = await getCommunityId()
let cycles = this.cycles
const params = {
page: 1,
row: 20,
feeId: this.feeId,
communityId: this.communityId,
cycles,
payerObjId: this.payerObjId,
payerObjType: this.payerObjType,
endTime: this.endTime,
custEndTime: this.custEndTime ? dateAdd(this.custEndTime) : ''
}
const response = await computeFeeDiscount(params)
this.feeDiscounts = response.data || []
this.selectDiscountIds = this.feeDiscounts.map(item => item.discountId)
this.computeFeeDiscount()
} catch (error) {
console.error('查询折扣信息失败:', error)
}
},
getDiscountTypeName(type) {
const types = {
'1001': this.$t('payFeeDiscount.discount'),
'2002': this.$t('payFeeDiscount.penalty'),
'3003': this.$t('payFeeDiscount.specialDiscount')
}
return types[type] || type
},
formatDiscountPrice(row) {
if (row.discountType === '1001' || row.discountType === '3003') {
return row.discountPrice < 0 ? row.discountPrice : row.discountPrice * -1
} else if (row.discountType === '2002') {
return row.discountPrice > 0 ? row.discountPrice : row.discountPrice * -1
}
return row.discountPrice
},
computeFeeDiscount() {
let totalDiscountMoney = 0.0
let selectDiscount = []
this.selectDiscountIds.forEach(item => {
this.feeDiscounts.forEach(disItem => {
if (disItem.feeDiscountSpecs && disItem.feeDiscountSpecs.length > 0) {
let specValue = ""
disItem.feeDiscountSpecs.forEach(feeItem => {
if (feeItem.specName === this.$t('payFeeDiscount.monthSpec')) {
specValue = feeItem.specValue
}
})
if ((disItem.discountType === '1001' || disItem.discountType === '3003') &&
parseFloat(this.cycles) < parseFloat(specValue)) {
return
}
}
if (item === disItem.discountId && disItem.discountPrice !== 0 && disItem.ruleId !== "102020008") {
if (disItem.feeDiscountSpecs && disItem.feeDiscountSpecs.length > 0) {
let specValue = ""
disItem.feeDiscountSpecs.forEach(feeItem => {
if (feeItem.specName === this.$t('payFeeDiscount.monthSpec')) {
specValue = feeItem.specValue
}
})
if (specValue && parseFloat(this.cycles) >= parseFloat(specValue)) {
totalDiscountMoney += parseFloat(disItem.discountPrice)
selectDiscount.push(disItem)
}
specValue = ""
disItem.feeDiscountSpecs.forEach(feeItem => {
if (feeItem.specName === this.$t('payFeeDiscount.penaltySpec')) {
specValue = feeItem.specValue
}
})
if (specValue) {
totalDiscountMoney += parseFloat(disItem.discountPrice)
selectDiscount.push(disItem)
}
}
} else if (item === disItem.discountId && disItem.ruleId === "102020008") {
if (disItem.feeDiscountSpecs != null && disItem.feeDiscountSpecs != undefined &&
disItem.feeDiscountSpecs.length > 0) {
let specValue = ""
disItem.feeDiscountSpecs.forEach(feeItem => {
if (feeItem.specName === this.$t('payFeeDiscount.monthSpec')) {
specValue = feeItem.specValue
}
})
if (specValue !== "" && parseFloat(this.cycles) >= parseFloat(specValue)) {
selectDiscount.push(disItem)
}
}
}
})
})
this.totalDiscountMoney = totalDiscountMoney
this.$emit('changeDiscountPrice', {
totalDiscountMoney,
selectDiscount
})
},
handleClose() {
this.feeDiscounts = []
this.selectDiscountIds = []
this.totalDiscountMoney = 0.0
}
}
}
</script>
<style scoped>
.el-table {
margin-top: 20px;
}
</style>