rentPayDetails.vue
14.9 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
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
238
239
240
241
242
243
244
245
246
247
248
249
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
<template>
<view class="page">
<view class="title-top">
<div class="left">
<view @click="show = true">{{pageIndex.time}}年<u-icon name="arrow-down"></u-icon></view>
<u-picker v-model="show" mode="time" :params="{year: true}" @confirm="confirm"></u-picker>
</div>
<div class="right">
<view class="price" style="font-size: 40rpx;"><u-icon name="rmb" style="font-size: 24rpx;" />{{allPay}}
</view>
</div>
</view>
<view class="record-list">
<view class="record-item" v-for="(item, index) in dataList" :key="index">
<view class="info-title">
<!-- <view class="title">{{formatDate(item.tenementOrderDate)}}</view> -->
<view class="right">
<view class="price"><u-icon name="rmb" style="font-size: 24rpx;" />{{item.dingPay}}</view>
</view>
<view class="price">
<u-button type="success" @click="baoShow(item.id)"
style="height: 32px;border-radius: 10px;" v-if="item.isOpeningInvoice!='2'">申请开票</u-button>
<u-button type="primary" @click="sent(item.id)"
style="height: 32px;border-radius: 10px;" v-else>查看发票</u-button>
</view>
</view>
<view class="info-items" v-for="(value, ids) in item.ziList">
<view class="info-item">
<view class="left title">
{{value.tenementOrderParent==''?value.tenementOrder:value.tenementOrderParent}}
</view>
<view class="right">
<view class="price"><u-icon name="rmb" style="font-size: 24rpx;" />{{value.paymentAmount}}
</view>
</view>
</view>
<view class="info-item">
<view class="left" style="color: #0FBB59;">{{value.payState==1?'支付成功':''}}</view>
<view class="right" style="color: #8A8A8A;">{{formatDateTime(value.paymentTime)}}</view>
</view>
</view>
</view>
</view>
<view v-if="dataList.length === 0" class="nonemsg" style="font-size: 24rpx;">
暂无数据
</view>
<u-popup class="userForm" v-model="joinShow" mode="center" border-radius="20" :closeable="true" width="90%">
<view style="padding: 30rpx;">
<u-form class="form-box" :model="form" ref="uForm" label-width="140">
<view style="padding: 10rpx;">
<view class="title" style="font-size: 16px;font-weight: bold;">填写发票信息</view>
<u-form-item label="发票类型">
<view class="button-group">
<view class="invoice-btn" :class="{ active: invoiceType === 'ordinary' }"
@click="selectInvoiceType('ordinary')">
普通发票
</view>
<view class="invoice-btn" :class="{ active: invoiceType === 'special' }"
@click="selectInvoiceType('special')">
专用发票
</view>
</view>
</u-form-item>
<u-form-item label="抬头类型">
<view class="button-group">
<view class="invoice-btn" v-if="form.invoiceType!='专用发票'"
:class="{ active: taitoutype === 'ordinary' }" @click="ttType('ordinary')">
个人
</view>
<view class="invoice-btn" :class="{ active: taitoutype === 'special' }"
@click="ttType('special')">
单位
</view>
</view>
</u-form-item>
<u-form-item label="发票抬头" ><u-input v-model="form.invoiceTitle" placeholder="必填"/></u-form-item>
<u-form-item label="单位税号" v-if="form.titleType=='单位'">
<u-input v-model="form.unitTaxNo" placeholder="必填"/>
</u-form-item>
<u-form-item label="注册地址" v-if="form.titleType=='单位'">
<u-input v-model="form.registerAddress" :placeholder="form.invoiceType!='专用发票'?'选填':'必填'" />
</u-form-item>
<u-form-item label="注册电话" v-if="form.titleType=='单位'">
<u-input v-model="form.registerPhone"
:placeholder="form.invoiceType!='专用发票'?'选填':'必填'" /></u-form-item>
<u-form-item label="开户银行" v-if="form.titleType=='单位'">
<u-input v-model="form.openingBank"
:placeholder="form.invoiceType!='专用发票'?'选填':'必填'" /></u-form-item>
<u-form-item label="银行账号" v-if="form.titleType=='单位'">
<u-input v-model="form.bankAccount"
:placeholder="form.invoiceType!='专用发票'?'选填':'必填'" /></u-form-item>
<u-button type="success" style="height: 35px;" @click="submit">提交</u-button>
</view>
</u-form>
</view>
</u-popup>
</view>
</template>
<script>
export default {
data() {
return {
show: false,
dataList: [],
allPay: 0,
pageIndex: {
time: ''
},
merchants: '',
joinShow: false,
form: {
invoiceType: '普通发票', //发票类型
titleType: '个人', //抬头类型
invoiceTitle: '', //发票抬头
unitTaxNo: '', //单位税号
registerAddress: '', //注册地址
registerPhone: '', //注册电话
openingBank: '', //开户银行
bankAccount: '', //银行账号
tenementId: '', //缴费订单号ID
businessUserId: '', //商家ID
createTime: ''
},
invoiceType: 'ordinary',
taitoutype: 'ordinary',
}
},
onShow() {
this.pageIndex.time = this.getCurrentYear()
},
onLoad(options) {
console.log()
if (options.msg && options.merchants) {
this.allPay = 0
let receivedMsg = JSON.parse(decodeURIComponent(options.msg))
this.merchants = decodeURIComponent(options.merchants)
console.error(this.merchants)
this.getAll(receivedMsg.list)
}
},
methods: {
baoShow(val) {
this.form = {
invoiceType: '普通发票', //发票类型
titleType: '个人', //抬头类型
invoiceTitle: '', //发票抬头
unitTaxNo: '', //单位税号
registerAddress: '', //注册地址
registerPhone: '', //注册电话
openingBank: '', //开户银行
bankAccount: '', //银行账号
tenementId: val, //缴费订单号ID
businessUserId: '', //商家ID
createTime: ''
}
this.invoiceType = 'ordinary'
this.taitoutype = 'ordinary'
this.joinShow = true
},
submit() {
this.form.businessUserId = uni.getStorageSync('user').businessUserId
if (!this.form.invoiceTitle) {
uni.showToast({
icon: 'none',
title: '请输入发票抬头'
});
return false;
}
if(this.form.invoiceType == '专用发票'){
if (!this.form.unitTaxNo) {
uni.showToast({
icon: 'none',
title: '请输入单位税号'
});
return false;
}
if (!this.form.registerAddress) {
uni.showToast({
icon: 'none',
title: '请输入注册地址'
});
return false;
}
if (!this.form.registerPhone) {
uni.showToast({
icon: 'none',
title: '请输入注册电话'
});
return false;
}
if (!this.form.openingBank) {
uni.showToast({
icon: 'none',
title: '请输入开户银行'
});
return false;
}
if (!this.form.bankAccount) {
uni.showToast({
icon: 'none',
title: '请输入银行账号'
});
return false;
}
}
if(this.form.invoiceType == '普通发票' && this.form.titleType == '单位'){
if (!this.form.unitTaxNo) {
uni.showToast({
icon: 'none',
title: '请输入单位税号'
});
return false;
}
}
this.$http.sendRequest('/cereInvoiceTitle/add', 'POST', this.form, 2).then(res => {
uni.showToast({
icon: 'none',
title: '提交成功'
})
uni.navigateBack({
delta: 1
})
})
},
selectInvoiceType(type) {
if (type == 'ordinary') {
this.form.invoiceType = '普通发票'
} else {
this.form.invoiceType = '专用发票'
this.form.titleType = '单位'
this.taitoutype = 'special'
}
this.invoiceType = type; // 点击更新选中状态
},
ttType(type) {
if (type == 'ordinary') {
this.form.titleType = '个人'
this.form.unitTaxNo = ''
this.form.registerAddress = ''
this.form.registerPhone = ''
this.form.openingBank = ''
this.form.bankAccount = ''
} else {
this.form.titleType = '单位'
}
this.taitoutype = type; // 点击更新选中状态
},
sent(ids){
this.$http.sendRequest(`/cereInvoiceTitle/getByTenementId/${ids}`, 'GET', '', 2).then(res => {
const url = this.$img+res.data.data.invoiceUrl
uni.downloadFile({
url: url,
success: (res) => {
if (res.statusCode === 200) {
const filePath = res.tempFilePath;
// 保存到本地
uni.saveFile({
tempFilePath: filePath,
success: (saveRes) => {
const savedFilePath = saveRes.savedFilePath;
// 打开文件
if (uni.getSystemInfoSync().platform === 'ios') {
// iOS处理
plus.runtime.openFile(savedFilePath, {
contentType: 'application/pdf'
});
} else {
// 安卓或小程序处理
uni.openDocument({
filePath: savedFilePath,
success: () => {
console.log('打开成功');
},
fail: (err) => {
console.error('打开失败', err);
}
});
}
},
fail: (err) => {
console.error('保存失败', err);
}
});
}
},
fail: (err) => {
console.error('下载失败', err);
}
});
})
},
getAll(receivedMsg) {
let totalPay = 0
const redList = []
// 用于存储 tenementOrderParent 相同的项
const groupedItems = {};
// 遍历 receivedMsg.list 数组
receivedMsg.forEach(item => {
if (item.payState == 1) {
totalPay += item.paymentAmount
if (item.tenementOrderParent === '') {
// 如果 tenementOrderParent 为空,添加 dingPay 字段并添加到 redList
let newItem = {
...item,
ziList: [],
dingPay: item.paymentAmount
};
newItem.ziList.push(item)
redList.push(newItem);
} else {
// 如果 tenementOrderParent 不为空,将相同 tenementOrderParent 的项分组
if (!groupedItems[item.tenementOrderParent]) {
groupedItems[item.tenementOrderParent] = {
ziList: [],
dingPay: 0
};
}
groupedItems[item.tenementOrderParent].ziList.push(item);
groupedItems[item.tenementOrderParent].dingPay += item.paymentAmount;
groupedItems[item.tenementOrderParent].paymentTime = item.paymentTime;
groupedItems[item.tenementOrderParent].payDay = item.payDay;
groupedItems[item.tenementOrderParent].payState = item.payState;
}
}
});
// 将分组后的对象添加到 redList
for (const key in groupedItems) {
redList.push({
tenementOrderParent: key,
...groupedItems[key]
});
}
// receivedMsg.list.map(item=>{
// let obj ={
// ...item,
// dingPay:0,
// ziList:[]
// }
// if (item.payState == 1) {
// obj.ziList.push(item)
// if(item.tenementOrderParent ){
// }
// obj.dingPay +=item.paymentAmount
// this.orderPay+=item.paymentAmount
// this.allPay+=item.paymentAmount
// redList.push(obj)
// }
// })
this.allPay = totalPay;
this.dataList = redList
},
getCurrentYear() {
const year = new Date().getFullYear();
return `${year}`;
},
confirm(e) {
this.pageIndex.time = e.year
const {
firstDay,
lastDay
} = this.getYearFirstAndLastDay(e.year)
this.$http.sendRequest('/cerePropertyOrder/queryByName', 'POST', {
relatedMerchants: this.merchants,
paymentTimeStart: firstDay,
paymentTimeEnd: lastDay
}, 1).then(res => {
console.log(res)
if (res.data.data.length > 0) {
this.getAll(res.data.data[0].cerePropertyOrderList)
} else {
this.dataList = []
this.allPay = 0
}
})
},
getYearFirstAndLastDay(year) {
console.log(year)
const firstDay = new Date(year, 0, 1);
const lastDay = new Date(year, 11, 31);
console.log(firstDay.toISOString().split('T'))
return {
firstDay: firstDay.toISOString().split('T')[0],
lastDay: lastDay.toISOString().split('T')[0]
}
},
formatDateTime(dateTimeStr) {
// 创建 Date 对象
const date = new Date(dateTimeStr);
// 获取月份,由于 getMonth() 返回值从 0 开始,所以要加 1,并确保为两位数字
const month = String(date.getMonth() + 1).padStart(2, '0');
// 获取日期,并确保为两位数字
const day = String(date.getDate()).padStart(2, '0');
// 获取小时,并确保为两位数字
const hours = String(date.getHours()).padStart(2, '0');
// 获取分钟,并确保为两位数字
const minutes = String(date.getMinutes()).padStart(2, '0');
// 按照所需格式拼接并返回结果
return `${month}月${day}日 ${hours}:${minutes}`;
},
formatDate(dateStr) {
// 使用 split 方法将日期字符串按 - 分割成数组
const [year, month, day] = dateStr.split('-');
// 将 month 和 day 转换为数字,去除可能存在的前导零
const formattedMonth = parseInt(month, 10);
const formattedDay = parseInt(day, 10);
// 按照目标格式拼接字符串
return `${formattedMonth}月${formattedDay}号`;
},
currentTime() {
let date = new Date();
let year = date.getFullYear();
let month = date.getMonth() + 1; // 月份从0~11,所以加一
let day = date.getDate();
let hours = date.getHours();
let minutes = date.getMinutes();
let seconds = date.getSeconds();
// 为月、日、时、分、秒添加前导零(如果需要)
month = month < 10 ? '0' + month : month;
day = day < 10 ? '0' + day : day;
hours = hours < 10 ? '0' + hours : hours;
minutes = minutes < 10 ? '0' + minutes : minutes;
seconds = seconds < 10 ? '0' + seconds : seconds;
// 拼接日期和时间字符串
let strDate = `${year}-${month}-${day} ${hours}:${minutes}`;
return strDate;
},
}
}
</script>
<style scoped lang="scss">
@import 'rentPayDetails.scss';
/* 使用深度选择器覆盖 u-input 的样式*/
::v-deep .u-input__input {
text-align: right;
// padding-right: 15px;
}
.invoice-type-container {
display: flex;
align-items: center;
padding: 10rpx;
}
.label {
margin-right: 20rpx;
color: #666;
font-size: 28rpx;
}
.button-group {
display: flex;
}
.invoice-btn {
height: 30px;
line-height: 150%;
padding: 10rpx 24rpx;
border: 2rpx solid #ddd;
border-radius: 30rpx;
margin-right: 20rpx;
color: #333;
font-size: 28rpx;
transition: all 0.3s;
}
.invoice-btn.active {
border-color: #3F9B6A;
color: #3F9B6A;
border-width: 2rpx;
}
</style>