Blame view

src/components/fee/addProxyFee.vue 9.15 KB
24d3590f   wuxw   房屋收费页面开发完成
1
  <template>
814833f5   wuxw   优化费用缴费代码
2
    <el-dialog :title="$t('addProxyFee.title')" :visible.sync="visible" width="40%" :before-close="handleClose">
24d3590f   wuxw   房屋收费页面开发完成
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
      <el-form ref="form" :model="formData" label-width="120px">
        <el-form-item :label="$t('addProxyFee.feeType')" prop="feeTypeCd">
          <el-select v-model="formData.feeTypeCd" @change="handleFeeTypeChange"
            :placeholder="$t('addProxyFee.feeTypePlaceholder')" style="width: 100%">
            <el-option v-for="item in feeTypeOptions" :key="item.value" :label="item.label"
              :value="item.value"></el-option>
          </el-select>
        </el-form-item>
  
        <el-form-item :label="$t('addProxyFee.feeItem')" prop="configId">
          <el-select v-model="formData.configId" @change="handleConfigChange"
            :placeholder="$t('addProxyFee.feeItemPlaceholder')" style="width: 100%">
            <el-option v-for="item in feeConfigOptions" :key="item.configId" :label="item.feeName"
              :value="item.configId"></el-option>
          </el-select>
          <span class="tip">{{ $t('addProxyFee.feeItemTip') }}</span>
        </el-form-item>
  
        <el-form-item :label="$t('addProxyFee.chargeObject')">
          <el-input v-model="formData.ownerName" disabled
            :placeholder="$t('addProxyFee.chargeObjectPlaceholder')"></el-input>
        </el-form-item>
  
        <template v-if="formData.feeTypeCd !== '888800010014'">
          <el-form-item :label="$t('addProxyFee.consumption')" prop="consumption">
            <el-input v-model="formData.consumption" @blur="handleConsumptionBlur"
              :placeholder="$t('addProxyFee.consumptionPlaceholder')"></el-input>
          </el-form-item>
  
          <el-form-item :label="$t('addProxyFee.amount')" prop="amount">
            <el-input v-model="formData.amount" @blur="handleAmountBlur"
              :placeholder="$t('addProxyFee.amountPlaceholder')"></el-input>
          </el-form-item>
        </template>
  
        <template v-else>
          <el-form-item :label="$t('addProxyFee.quantity')" prop="consumption">
            <el-input v-model="formData.consumption" @blur="handleConsumptionBlur"
              :placeholder="$t('addProxyFee.consumptionPlaceholder')"></el-input>
          </el-form-item>
  
          <el-form-item :label="$t('addProxyFee.amount')">
            <el-input v-model="formData.amount" disabled :placeholder="$t('addProxyFee.amountPlaceholder')"></el-input>
          </el-form-item>
        </template>
  
        <el-form-item :label="$t('addProxyFee.startTime')" prop="startTime">
          <el-date-picker v-model="formData.startTime" type="date" :placeholder="$t('addProxyFee.startTimePlaceholder')"
            value-format="yyyy-MM-dd" @change="validateStartTime"></el-date-picker>
        </el-form-item>
  
        <el-form-item :label="$t('addProxyFee.endTime')" prop="endTime">
          <el-date-picker v-model="formData.endTime" type="date" :placeholder="$t('addProxyFee.endTimePlaceholder')"
            value-format="yyyy-MM-dd" @change="validateEndTime"></el-date-picker>
        </el-form-item>
      </el-form>
  
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">{{ $t('common.cancel') }}</el-button>
        <el-button type="primary" @click="handleSubmit">{{ $t('common.save') }}</el-button>
      </span>
    </el-dialog>
  </template>
  
  <script>
  import { saveProxyFee, listFeeConfigs } from '@/api/fee/addProxyFeeApi'
  import { getCommunityId } from '@/api/community/communityApi'
  import { dateFormat } from '@/utils/dateUtil'
  
  export default {
    name: 'AddProxyFee',
    props: {
      callBackListener: String,
      callBackFunction: String
    },
    data() {
      return {
        visible: false,
        formData: {
          remark: '',
          roomId: '',
          objId: '',
          objName: '',
          feeTypeCd: '',
          feeConfigs: [],
          amount: '',
          consumption: '',
          configId: '',
          ownerName: '',
          objType: '3333',
          startTime: dateFormat(new Date()),
          endTime: dateFormat(new Date())
        },
        feeTypeOptions: [
          { value: '888800010015', label: this.$t('addProxyFee.waterFee') },
          { value: '888800010016', label: this.$t('addProxyFee.electricityFee') },
          { value: '888800010014', label: this.$t('addProxyFee.otherFee') }
        ],
        feeConfigOptions: [],
        rules: {
          amount: [
            { required: true, message: this.$t('addProxyFee.validate.amountRequired'), trigger: 'blur' },
            { pattern: /^\d+(\.\d{1,2})?$/, message: this.$t('addProxyFee.validate.amountFormat'), trigger: 'blur' }
          ],
          consumption: [
            { required: true, message: this.$t('addProxyFee.validate.consumptionRequired'), trigger: 'blur' },
            { pattern: /^\d+(\.\d{1,2})?$/, message: this.$t('addProxyFee.validate.consumptionFormat'), trigger: 'blur' }
          ],
          objId: [
            { required: true, message: this.$t('addProxyFee.validate.roomRequired'), trigger: 'blur' }
          ],
          configId: [
            { required: true, message: this.$t('addProxyFee.validate.feeRequired'), trigger: 'change' }
          ],
          startTime: [
            { required: true, message: this.$t('addProxyFee.validate.startTimeRequired'), trigger: 'blur' }
          ],
          endTime: [
            { required: true, message: this.$t('addProxyFee.validate.endTimeRequired'), trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      open(params) {
        this.resetForm()
        if (params.objType) {
          this.formData.objType = params.objType
        }
        this.formData.roomId = params.roomId
        this.formData.objId = params.roomId
        this.formData.objName = params.roomName
        this.formData.ownerName = `${params.roomName}(${params.ownerName})`
        this.visible = true
      },
  
      handleFeeTypeChange(value) {
        this.formData.amount = ''
        this.formData.consumption = ''
        this.formData.configId = ''
        this.loadFeeConfigs(value)
      },
  
      loadFeeConfigs(feeTypeCd) {
        listFeeConfigs({
          page: 1,
          row: 20,
          communityId: getCommunityId(),
          feeTypeCd,
          isDefault: 'F',
          computingFormula: '6006',
          valid: '1'
        }).then(response => {
0c52f32a   wuxw   优化按量收费不能创建的问题
156
          this.feeConfigOptions = response.feeConfigs
24d3590f   wuxw   房屋收费页面开发完成
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
        })
      },
  
      handleConfigChange() {
        this.formData.amount = ''
        this.formData.consumption = ''
      },
  
      getCurrentConfig() {
        return this.feeConfigOptions.find(
          item => this.formData.configId === item.configId && item.computingFormula === '6006'
        )
      },
  
      handleAmountBlur() {
        const config = this.getCurrentConfig()
        const amount = parseFloat(this.formData.amount)
  
        if (!config) {
          this.$message.error(this.$t('addProxyFee.validate.invalidConfig'))
          this.formData.amount = ''
          this.formData.consumption = ''
          return
        }
  
        if (amount < config.additionalAmount) {
          this.$message.error(this.$t('addProxyFee.validate.amountTooSmall'))
          this.formData.amount = ''
          this.formData.consumption = ''
          return
        }
  
        const consumption = (amount - config.additionalAmount) / config.squarePrice
        this.formData.consumption = consumption.toFixed(2)
      },
  
      handleConsumptionBlur() {
        const config = this.getCurrentConfig()
        const consumption = parseFloat(this.formData.consumption)
  
        if (!config) {
          this.$message.error(this.$t('addProxyFee.validate.invalidConfig'))
          this.formData.amount = ''
          this.formData.consumption = ''
          return
        }
  
        const amount = config.squarePrice * consumption + parseFloat(config.additionalAmount)
        this.formData.amount = amount.toFixed(2)
      },
  
      validateStartTime(value) {
        const start = new Date(value)
        const end = new Date(this.formData.endTime)
        if (start >= end) {
          this.$message.error(this.$t('addProxyFee.validate.startBeforeEnd'))
          this.formData.startTime = ''
        }
      },
  
      validateEndTime(value) {
        const start = new Date(this.formData.startTime)
        const end = new Date(value)
        if (start >= end) {
          this.$message.error(this.$t('addProxyFee.validate.endAfterStart'))
          this.formData.endTime = ''
        }
      },
  
      handleSubmit() {
        this.$refs.form.validate(valid => {
          if (!valid) return
  
          const params = {
            ...this.formData,
            communityId: getCommunityId()
          }
  
  
  
          saveProxyFee(params).then(() => {
0c52f32a   wuxw   优化按量收费不能创建的问题
238
239
             this.$message.success(this.$t('addProxyFee.successMessage'))
             this.$emit('success')
24d3590f   wuxw   房屋收费页面开发完成
240
241
242
243
244
245
246
247
248
            this.handleClose()
          }).catch(error => {
            this.$message.error(error.message)
          })
        })
      },
  
      resetForm() {
        if (this.$refs.form) {
0c52f32a   wuxw   优化按量收费不能创建的问题
249
          //this.$refs.form.resetFields()
24d3590f   wuxw   房屋收费页面开发完成
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
        }
        this.formData = {
          remark: '',
          roomId: '',
          objId: '',
          objName: '',
          feeTypeCd: '',
          feeConfigs: [],
          amount: '',
          consumption: '',
          configId: '',
          ownerName: '',
          objType: '3333',
          startTime: dateFormat(new Date()),
          endTime: dateFormat(new Date())
        }
      },
  
      handleClose() {
        this.visible = false
        this.resetForm()
      }
    }
  }
  </script>
  
  <style scoped>
  .tip {
    font-size: 12px;
    color: #909399;
  }
814833f5   wuxw   优化费用缴费代码
281
282
283
284
285
286
287
  .el-form-item{
    width: 90%;
    text-align: left;
  }
  .el-date-editor{  
    width: 100%;
  }
24d3590f   wuxw   房屋收费页面开发完成
288
  </style>