Blame view

src/components/fee/payFeeDiscount.vue 7.22 KB
1a0bdbe0   wuxw   优化缴费页面
1
  <template>
1a0bdbe0   wuxw   优化缴费页面
2
      <el-card v-if="shouldShowDiscounts">
ab1ebb3c   wuxw   缴费支持 押金 优惠券 优惠折扣 ...
3
        <div slot="header" class="flex justify-between">
1a0bdbe0   wuxw   优化缴费页面
4
5
6
          <span>{{ $t('payFeeDiscount.discountInfo') }}</span>
        </div>
  
ab1ebb3c   wuxw   缴费支持 押金 优惠券 优惠折扣 ...
7
8
        <el-table :data="feeDiscounts" border style="width: 100%">
          <el-table-column align="center" width="60">
1a0bdbe0   wuxw   优化缴费页面
9
            <template slot-scope="scope">
ab1ebb3c   wuxw   缴费支持 押金 优惠券 优惠折扣 ...
10
11
              <el-checkbox v-model="selectDiscountIds" :label="scope.row.discountId"
                @change="computeFeeDiscount"></el-checkbox>
1a0bdbe0   wuxw   优化缴费页面
12
13
            </template>
          </el-table-column>
ab1ebb3c   wuxw   缴费支持 押金 优惠券 优惠折扣 ...
14
          <el-table-column prop="discountType" align="center" :label="$t('payFeeDiscount.discountType')">
1a0bdbe0   wuxw   优化缴费页面
15
16
17
18
            <template slot-scope="scope">
              {{ getDiscountTypeName(scope.row.discountType) }}
            </template>
          </el-table-column>
ab1ebb3c   wuxw   缴费支持 押金 优惠券 优惠折扣 ...
19
20
21
          <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')">
1a0bdbe0   wuxw   优化缴费页面
22
            <template slot-scope="scope">
ab1ebb3c   wuxw   缴费支持 押金 优惠券 优惠折扣 ...
23
              <div v-for="(item, index) in scope.row.feeDiscountSpecs" :key="index">
1a0bdbe0   wuxw   优化缴费页面
24
25
26
27
                {{ item.specName }}:{{ item.specValue }}
              </div>
            </template>
          </el-table-column>
ab1ebb3c   wuxw   缴费支持 押金 优惠券 优惠折扣 ...
28
          <el-table-column align="center" :label="$t('payFeeDiscount.discountAmount')">
1a0bdbe0   wuxw   优化缴费页面
29
30
            <template slot="header">
              <span>{{ $t('payFeeDiscount.discountAmount') }}</span>
ab1ebb3c   wuxw   缴费支持 押金 优惠券 优惠折扣 ...
31
              <el-tooltip effect="dark" :content="$t('payFeeDiscount.discountTooltip')" placement="top">
1a0bdbe0   wuxw   优化缴费页面
32
33
34
35
36
37
38
39
40
41
                <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>
ab1ebb3c   wuxw   缴费支持 押金 优惠券 优惠折扣 ...
42
  
1a0bdbe0   wuxw   优化缴费页面
43
44
45
46
  </template>
  
  <script>
  import { getCommunityId } from '@/api/community/communityApi'
ab1ebb3c   wuxw   缴费支持 押金 优惠券 优惠折扣 ...
47
48
  import { dateAdd } from '@/utils/dateUtil'
  import { computeFeeDiscount } from '@/api/fee/payFeeOrderApi'
1a0bdbe0   wuxw   优化缴费页面
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
  
  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()
1a0bdbe0   wuxw   优化缴费页面
83
84
85
86
87
88
89
90
      },
      close() {
        this.dialogVisible = false
      },
      async listFeeDiscounts() {
        try {
          this.communityId = await getCommunityId()
          let cycles = this.cycles
ab1ebb3c   wuxw   缴费支持 押金 优惠券 优惠折扣 ...
91
  
1a0bdbe0   wuxw   优化缴费页面
92
93
94
95
96
97
98
99
100
101
102
103
          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) : ''
          }
  
ab1ebb3c   wuxw   缴费支持 押金 优惠券 优惠折扣 ...
104
105
          const response = await computeFeeDiscount(params)
          this.feeDiscounts = response.data || []
1a0bdbe0   wuxw   优化缴费页面
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
          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 = []
ab1ebb3c   wuxw   缴费支持 押金 优惠券 优惠折扣 ...
131
  
1a0bdbe0   wuxw   优化缴费页面
132
133
134
135
136
137
138
139
140
        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
                }
              })
ab1ebb3c   wuxw   缴费支持 押金 优惠券 优惠折扣 ...
141
142
              if ((disItem.discountType === '1001' || disItem.discountType === '3003') &&
                parseFloat(this.cycles) < parseFloat(specValue)) {
1a0bdbe0   wuxw   优化缴费页面
143
144
145
                return
              }
            }
ab1ebb3c   wuxw   缴费支持 押金 优惠券 优惠折扣 ...
146
  
1a0bdbe0   wuxw   优化缴费页面
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
            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") {
ab1ebb3c   wuxw   缴费支持 押金 优惠券 优惠折扣 ...
172
173
              if (disItem.feeDiscountSpecs != null && disItem.feeDiscountSpecs != undefined &&
                disItem.feeDiscountSpecs.length > 0) {
1a0bdbe0   wuxw   优化缴费页面
174
175
176
177
178
179
180
181
182
183
184
185
186
                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)
                }
              }
            }
          })
        })
ab1ebb3c   wuxw   缴费支持 押金 优惠券 优惠折扣 ...
187
  
1a0bdbe0   wuxw   优化缴费页面
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
        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>