diff --git a/src/views/rental/Detail.vue b/src/views/rental/Detail.vue
index d05d7be..bb0b265 100644
--- a/src/views/rental/Detail.vue
+++ b/src/views/rental/Detail.vue
@@ -51,7 +51,7 @@
-
+
@@ -102,8 +102,8 @@
-
- {{ scope.row.status === 'paid' ? '已支付' : '未支付' }}
+
+ {{ getWaterBillStatusText(scope.row.status) }}
@@ -139,16 +139,17 @@
-
+
-
+
-
+
+
@@ -226,14 +227,21 @@ export default {
startReading: '',
endReading: '',
unitPrice: '',
- status: 'unpaid'
+ status: 'unbilled'
},
waterBillRules: {
startDate: [{ required: true, message: '请选择开始日期', trigger: 'change' }],
- endDate: [{ required: true, message: '请选择结束日期', trigger: 'change' }],
- startReading: [{ required: true, message: '请输入起始度数', trigger: 'blur' }],
- endReading: [{ required: true, message: '请输入结束度数', trigger: 'blur' }],
- unitPrice: [{ required: true, message: '请输入单价', trigger: 'blur' }],
+ startReading: [
+ { required: true, message: '请输入起始度数', trigger: 'blur' },
+ { pattern: /^\d+(\.\d{1,2})?$/, message: '请输入有效的数字,最多保留两位小数', trigger: 'blur' }
+ ],
+ endReading: [
+ { pattern: /^\d+(\.\d{1,2})?$/, message: '请输入有效的数字,最多保留两位小数', trigger: 'blur' }
+ ],
+ unitPrice: [
+ { required: true, message: '请输入单价', trigger: 'blur' },
+ { pattern: /^\d+(\.\d{1,2})?$/, message: '请输入有效的数字,最多保留两位小数', trigger: 'blur' }
+ ],
status: [{ required: true, message: '请选择状态', trigger: 'change' }]
},
rentalDialogVisible: false,
@@ -280,6 +288,30 @@ export default {
}
},
methods: {
+ formatDate(date) {
+ if (!date) return null
+ const d = new Date(date)
+ const year = d.getFullYear()
+ const month = String(d.getMonth() + 1).padStart(2, '0')
+ const day = String(d.getDate()).padStart(2, '0')
+ return `${year}-${month}-${day}`
+ },
+ getWaterBillStatusType(status) {
+ switch (status) {
+ case 'paid': return 'success'
+ case 'unpaid': return 'warning'
+ case 'unbilled': return 'info'
+ default: return ''
+ }
+ },
+ getWaterBillStatusText(status) {
+ switch (status) {
+ case 'paid': return '已支付'
+ case 'unpaid': return '未支付'
+ case 'unbilled': return '未出账'
+ default: return status
+ }
+ },
handleResize() {
this.$forceUpdate()
},
@@ -494,12 +526,12 @@ export default {
this.waterBillForm = {
id: '',
roomId: this.$route.params.id,
- startDate: '',
+ startDate: new Date(),
endDate: '',
startReading: '',
endReading: '',
unitPrice: '',
- status: 'unpaid'
+ status: 'unbilled'
}
this.waterBillDialogVisible = true
},
@@ -514,11 +546,21 @@ export default {
async handleSaveWaterBill() {
try {
const roomId = this.$route.params.id
+ const data = {
+ roomId,
+ startDate: this.waterBillForm.startDate ? this.formatDate(this.waterBillForm.startDate) : null,
+ endDate: this.waterBillForm.endDate ? this.formatDate(this.waterBillForm.endDate) : null,
+ startReading: this.waterBillForm.startReading !== '' ? parseFloat(this.waterBillForm.startReading) : null,
+ endReading: this.waterBillForm.endReading !== '' ? parseFloat(this.waterBillForm.endReading) : null,
+ unitPrice: this.waterBillForm.unitPrice !== '' ? parseFloat(this.waterBillForm.unitPrice) : null,
+ status: this.waterBillForm.status
+ }
+
if (this.waterBillForm.id) {
- await waterBillApi.update(this.waterBillForm.id, this.waterBillForm)
+ await waterBillApi.update(this.waterBillForm.id, data)
this.$message.success('水费记录更新成功')
} else {
- await waterBillApi.create({ ...this.waterBillForm, roomId })
+ await waterBillApi.create(data)
this.$message.success('水费记录添加成功')
}
this.waterBillDialogVisible = false
diff --git a/src/views/rental/RentalArchive.vue b/src/views/rental/RentalArchive.vue
index a962c9e..9a324e8 100644
--- a/src/views/rental/RentalArchive.vue
+++ b/src/views/rental/RentalArchive.vue
@@ -51,7 +51,7 @@
重置
-
+
@@ -73,7 +73,7 @@
-
+
@@ -93,7 +93,7 @@
-
+
-
+