accounting-page 0.1.18 → 0.1.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +9 -9
- package/src/App.vue +20 -17
- package/src/views/BalanceSheet.vue +98 -98
- package/src/views/VoucherCreate.vue +298 -356
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "accounting-page",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.27",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "vite",
|
|
@@ -10,17 +10,17 @@
|
|
|
10
10
|
"update-check": "npm install --no-save npm-check && npm-check -u"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"axios": "^1.
|
|
14
|
-
"vant": "^4.
|
|
15
|
-
"vue": "^3.5.
|
|
16
|
-
"vue-router": "^5.
|
|
13
|
+
"axios": "^1.19.0",
|
|
14
|
+
"vant": "^4.10.0",
|
|
15
|
+
"vue": "^3.5.40",
|
|
16
|
+
"vue-router": "^5.2.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@types/node": "^
|
|
20
|
-
"@vitejs/plugin-vue": "^6.0.
|
|
19
|
+
"@types/node": "^26.1.2",
|
|
20
|
+
"@vitejs/plugin-vue": "^6.0.8",
|
|
21
21
|
"@vue/tsconfig": "^0.9.1",
|
|
22
22
|
"typescript": "~6.0.2",
|
|
23
|
-
"vite": "^8.0
|
|
24
|
-
"vue-tsc": "^3.3.
|
|
23
|
+
"vite": "^8.2.0",
|
|
24
|
+
"vue-tsc": "^3.3.9"
|
|
25
25
|
}
|
|
26
26
|
}
|
package/src/App.vue
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import {ref} from 'vue'
|
|
3
|
-
import {Tabbar as VanTabbar, TabbarItem as VanTabbarItem} from 'vant'
|
|
4
|
-
import {RouterView} from "vue-router";
|
|
5
|
-
|
|
6
|
-
const active = ref(0)
|
|
7
|
-
</script>
|
|
8
|
-
|
|
9
|
-
<template>
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
<
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import {ref} from 'vue'
|
|
3
|
+
import {Tabbar as VanTabbar, TabbarItem as VanTabbarItem} from 'vant'
|
|
4
|
+
import {RouterView} from "vue-router";
|
|
5
|
+
|
|
6
|
+
const active = ref(0)
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<template>
|
|
10
|
+
<router-view />
|
|
11
|
+
|
|
12
|
+
<div>
|
|
13
|
+
<van-tabbar v-model="active" route placeholder>
|
|
14
|
+
<van-tabbar-item icon="balance" to="/balance-sheet">资产负债表</van-tabbar-item>
|
|
15
|
+
<van-tabbar-item icon="orders" to="/voucher">凭证记账</van-tabbar-item>
|
|
16
|
+
</van-tabbar>
|
|
17
|
+
</div>
|
|
18
|
+
</template>
|
|
19
|
+
|
|
20
|
+
<style>
|
|
18
21
|
</style>
|
|
@@ -1,99 +1,99 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<
|
|
3
|
-
<van-nav-bar title="
|
|
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
|
-
const
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const loadData = () => {
|
|
82
|
-
axios.get('/balance-sheet', {
|
|
83
|
-
params: {startDate: startDate.value, endDate: endDate.value}
|
|
84
|
-
}).then(res => {
|
|
85
|
-
assets.value = res.data.assets
|
|
86
|
-
liabilities.value = res.data.liabilities
|
|
87
|
-
equity.value = res.data.equity
|
|
88
|
-
})
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// 进入页面自动加载一次
|
|
92
|
-
onMounted(() => {
|
|
93
|
-
loadData()
|
|
94
|
-
})
|
|
95
|
-
</script>
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
<style scoped>
|
|
1
|
+
<template>
|
|
2
|
+
<van-sticky>
|
|
3
|
+
<van-nav-bar title="资产负债表"/>
|
|
4
|
+
</van-sticky>
|
|
5
|
+
<van-field
|
|
6
|
+
v-model="startDate"
|
|
7
|
+
label="开始日期"
|
|
8
|
+
type="date"
|
|
9
|
+
value-format="YYYY-MM-DD"
|
|
10
|
+
/>
|
|
11
|
+
<van-field
|
|
12
|
+
v-model="endDate"
|
|
13
|
+
label="结束日期"
|
|
14
|
+
type="date"
|
|
15
|
+
value-format="YYYY-MM-DD"
|
|
16
|
+
/>
|
|
17
|
+
|
|
18
|
+
<van-button
|
|
19
|
+
type="primary"
|
|
20
|
+
block
|
|
21
|
+
@click="loadData">查询报表
|
|
22
|
+
</van-button>
|
|
23
|
+
|
|
24
|
+
<van-index-bar :index-list="indexList" :sticky-offset-top="stickyOffsetTop">
|
|
25
|
+
<van-index-anchor index="资产">资产</van-index-anchor>
|
|
26
|
+
<van-cell
|
|
27
|
+
v-for="item in assets"
|
|
28
|
+
:key="item.code"
|
|
29
|
+
:title="item.name"
|
|
30
|
+
:value="item.balance"
|
|
31
|
+
/>
|
|
32
|
+
|
|
33
|
+
<van-index-anchor index="负债">负债</van-index-anchor>
|
|
34
|
+
<van-cell
|
|
35
|
+
v-for="item in liabilities"
|
|
36
|
+
:key="item.code"
|
|
37
|
+
:title="item.name"
|
|
38
|
+
:value="item.balance"
|
|
39
|
+
/>
|
|
40
|
+
|
|
41
|
+
<van-index-anchor index="权益">权益</van-index-anchor>
|
|
42
|
+
<van-cell
|
|
43
|
+
v-for="item in equity"
|
|
44
|
+
:key="item.code"
|
|
45
|
+
:title="item.name"
|
|
46
|
+
:value="item.balance"
|
|
47
|
+
/>
|
|
48
|
+
</van-index-bar>
|
|
49
|
+
</template>
|
|
50
|
+
|
|
51
|
+
<script lang="ts" setup>
|
|
52
|
+
import {onMounted, ref} from 'vue'
|
|
53
|
+
import axios from 'axios'
|
|
54
|
+
|
|
55
|
+
// 自动获取:本月首日
|
|
56
|
+
const getMonthFirstDay = () => {
|
|
57
|
+
// 传入 Date,返回【当前系统时区】的 toISOString 格式日期(YYYY-MM-DD)
|
|
58
|
+
let now =new Date()
|
|
59
|
+
let date =new Date(now.getFullYear(), now.getMonth() ,1)
|
|
60
|
+
return new Date(date.getTime() - date.getTimezoneOffset() * 60000)
|
|
61
|
+
.toISOString().split('T')[0];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// 自动获取:今日
|
|
65
|
+
const getToday = () => {
|
|
66
|
+
return new Date().toISOString().slice(0, 10)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// 默认值:本月首日 — 今日
|
|
70
|
+
const startDate = ref(getMonthFirstDay())
|
|
71
|
+
const endDate = ref(getToday())
|
|
72
|
+
|
|
73
|
+
const assets = ref<Array<{ code: string; name: string; balance: number }>>([])
|
|
74
|
+
const liabilities = ref<Array<{ code: string; name: string; balance: number }>>([])
|
|
75
|
+
const equity = ref<Array<{ code: string; name: string; balance: number }>>([])
|
|
76
|
+
const indexList = ['资产', '负债', '权益']
|
|
77
|
+
const stickyOffsetTop = Number.parseFloat(
|
|
78
|
+
getComputedStyle(document.documentElement).getPropertyValue('--van-tabbar-height')
|
|
79
|
+
) || 0
|
|
80
|
+
|
|
81
|
+
const loadData = () => {
|
|
82
|
+
axios.get('/balance-sheet', {
|
|
83
|
+
params: {startDate: startDate.value, endDate: endDate.value}
|
|
84
|
+
}).then(res => {
|
|
85
|
+
assets.value = res.data.assets
|
|
86
|
+
liabilities.value = res.data.liabilities
|
|
87
|
+
equity.value = res.data.equity
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// 进入页面自动加载一次
|
|
92
|
+
onMounted(() => {
|
|
93
|
+
loadData()
|
|
94
|
+
})
|
|
95
|
+
</script>
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
<style scoped>
|
|
99
99
|
</style>
|
|
@@ -1,357 +1,299 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<
|
|
3
|
-
<van-nav-bar title="凭证记账"
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
readonly
|
|
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
|
-
<van-
|
|
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
|
-
const
|
|
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
|
-
showToast('
|
|
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
|
-
font-
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
.entry-card {
|
|
301
|
-
background: #f7f8fa;
|
|
302
|
-
border-radius: 8px;
|
|
303
|
-
padding: 8px;
|
|
304
|
-
margin-bottom: 10px;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
.account-popup {
|
|
308
|
-
width: 90%;
|
|
309
|
-
height: 70vh;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
.picker-header {
|
|
313
|
-
display: flex;
|
|
314
|
-
justify-content: space-between;
|
|
315
|
-
align-items: center;
|
|
316
|
-
padding: 12px 16px;
|
|
317
|
-
border-bottom: 1px solid #eee;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
.picker-title {
|
|
321
|
-
font-size: 16px;
|
|
322
|
-
font-weight: 500;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
.split-picker {
|
|
326
|
-
display: flex;
|
|
327
|
-
height: calc(100% - 48px);
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
.left-category {
|
|
331
|
-
width: 35%;
|
|
332
|
-
background: #f5f5f5;
|
|
333
|
-
overflow-y: auto;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
.cate-item {
|
|
337
|
-
padding: 14px 10px;
|
|
338
|
-
text-align: center;
|
|
339
|
-
font-size: 14px;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
.cate-item.active {
|
|
343
|
-
background: #fff;
|
|
344
|
-
color: #1989fa;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
.right-account {
|
|
348
|
-
flex: 1;
|
|
349
|
-
overflow-y: auto;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
.acc-item {
|
|
353
|
-
padding: 14px 16px;
|
|
354
|
-
border-bottom: 1px solid #f5f5f5;
|
|
355
|
-
font-size: 14px;
|
|
356
|
-
}
|
|
1
|
+
<template>
|
|
2
|
+
<van-sticky>
|
|
3
|
+
<van-nav-bar title="凭证记账" />
|
|
4
|
+
</van-sticky>
|
|
5
|
+
|
|
6
|
+
<van-form @submit="submit">
|
|
7
|
+
<van-index-bar :index-list="list.indexList" :sticky-offset-top="stickyOffsetTop">
|
|
8
|
+
<van-index-anchor index="1">凭证基本信息</van-index-anchor>
|
|
9
|
+
|
|
10
|
+
<van-field v-model="voucher.voucherNo" label="凭证号" placeholder="自动生成" readonly />
|
|
11
|
+
<van-field v-model="voucher.voucherDate" label="日期" type="date" value-format="YYYY-MM-DD" />
|
|
12
|
+
<van-field v-model="voucher.description" label="摘要" placeholder="输入备注" />
|
|
13
|
+
|
|
14
|
+
<van-index-anchor index="2">凭证明细(可添加多笔)</van-index-anchor>
|
|
15
|
+
<div v-for="(entry, index) in entries" :key="index" class="entry-card">
|
|
16
|
+
<van-cell-group :border="false">
|
|
17
|
+
<van-field :model-value="entry.accountName" label="科目" placeholder="点击选择科目" is-link
|
|
18
|
+
@click="openAccountPicker(index)" />
|
|
19
|
+
<van-field v-model="entry.debit" label="借方金额" type="number" @change="calcTotal" />
|
|
20
|
+
<van-field v-model="entry.credit" label="贷方金额" type="number" @change="calcTotal" />
|
|
21
|
+
</van-cell-group>
|
|
22
|
+
<van-row justify="end">
|
|
23
|
+
<van-col span="6">
|
|
24
|
+
<van-button size="small" type="danger" plain @click="removeEntry(index)">
|
|
25
|
+
删除此行
|
|
26
|
+
</van-button>
|
|
27
|
+
</van-col>
|
|
28
|
+
</van-row>
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
<van-button type="primary" plain block @click="addEntry" style="margin: 12px 0">
|
|
32
|
+
+ 添加一笔分录
|
|
33
|
+
</van-button>
|
|
34
|
+
<van-index-anchor index="3">凭证统计</van-index-anchor>
|
|
35
|
+
<van-cell-group style="margin-bottom: 12px">
|
|
36
|
+
<van-cell title="借方合计" :value="totalDebit" />
|
|
37
|
+
<van-cell title="贷方合计" :value="totalCredit" />
|
|
38
|
+
</van-cell-group>
|
|
39
|
+
|
|
40
|
+
<van-button type="primary" block native-type="submit" style="margin: 0 0 12px">保存凭证(借贷必须相等)</van-button>
|
|
41
|
+
</van-index-bar>
|
|
42
|
+
|
|
43
|
+
</van-form>
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
<!-- 左右分栏科目选择弹窗 -->
|
|
47
|
+
<van-popup v-model:show="showAccountPicker" position="center" round class="account-popup">
|
|
48
|
+
<div class="picker-header">
|
|
49
|
+
<span class="picker-title">选择会计科目</span>
|
|
50
|
+
<van-icon name="cross" size="22" @click="showAccountPicker = false" />
|
|
51
|
+
</div>
|
|
52
|
+
<div class="split-picker">
|
|
53
|
+
<!-- 左侧分类 -->
|
|
54
|
+
<div class="left-category">
|
|
55
|
+
<div v-for="cate in categoryList" :key="cate.id" class="cate-item" :class="{ active: activeCateId === cate.id }"
|
|
56
|
+
@click="switchCategory(cate.id)">
|
|
57
|
+
{{ cate.name }}
|
|
58
|
+
</div>
|
|
59
|
+
</div>
|
|
60
|
+
<!-- 右侧科目列表 -->
|
|
61
|
+
<div class="right-account">
|
|
62
|
+
<div v-for="acc in currentAccountList" :key="acc.id" class="acc-item" @click="selectAccount(acc)">
|
|
63
|
+
{{ acc.text }}
|
|
64
|
+
</div>
|
|
65
|
+
</div>
|
|
66
|
+
</div>
|
|
67
|
+
</van-popup>
|
|
68
|
+
</template>
|
|
69
|
+
|
|
70
|
+
<script lang="ts" setup>
|
|
71
|
+
import { ref, reactive, onMounted } from 'vue'
|
|
72
|
+
import { showToast } from 'vant'
|
|
73
|
+
import axios from 'axios'
|
|
74
|
+
|
|
75
|
+
const stickyOffsetTop = Number.parseFloat(
|
|
76
|
+
getComputedStyle(document.documentElement).getPropertyValue('--van-tabbar-height')
|
|
77
|
+
) || 0
|
|
78
|
+
|
|
79
|
+
const showAccountPicker = ref(false)
|
|
80
|
+
const currentEntryIndex = ref(0)
|
|
81
|
+
const rawAccountList = ref<any[]>([])
|
|
82
|
+
const categoryList = ref<any[]>([])
|
|
83
|
+
const currentAccountList = ref<any[]>([])
|
|
84
|
+
const activeCateId = ref<number>()
|
|
85
|
+
|
|
86
|
+
const totalDebit = ref(0)
|
|
87
|
+
const totalCredit = ref(0)
|
|
88
|
+
|
|
89
|
+
// 初始化空白凭证
|
|
90
|
+
const initVoucher = () => {
|
|
91
|
+
return {
|
|
92
|
+
voucherNo: 'PZ' + new Date().getTime(),
|
|
93
|
+
voucherDate: getLocalISODate(new Date()),
|
|
94
|
+
description: '',
|
|
95
|
+
status: '草稿',
|
|
96
|
+
ifrsBasis: 'IFRS',
|
|
97
|
+
entries: [],
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// 本地时区日期
|
|
102
|
+
const getLocalISODate = (date: Date) => {
|
|
103
|
+
return new Date(date.getTime() - date.getTimezoneOffset() * 60000).toISOString().split('T')[0]
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const list = reactive<{
|
|
107
|
+
indexList: number[];
|
|
108
|
+
}>({
|
|
109
|
+
indexList: [1, 2, 3]
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
const voucher = reactive<Voucher>(initVoucher())
|
|
113
|
+
const entries = ref([
|
|
114
|
+
{ accountName: '', accountId: null, debit: '', credit: '', remark: '' }
|
|
115
|
+
])
|
|
116
|
+
|
|
117
|
+
interface Voucher {
|
|
118
|
+
voucherNo: string
|
|
119
|
+
voucherDate: string
|
|
120
|
+
description: string
|
|
121
|
+
status: string
|
|
122
|
+
ifrsBasis: string
|
|
123
|
+
entries: any[]
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// 加载科目
|
|
127
|
+
onMounted(() => {
|
|
128
|
+
|
|
129
|
+
axios.get('/account/accounts').then(res => {
|
|
130
|
+
rawAccountList.value = res.data.map((item: { code: string; name: string; id: number; type?: string }) => ({
|
|
131
|
+
text: `${item.code} ${item.name}`,
|
|
132
|
+
value: item.id,
|
|
133
|
+
category: item.type
|
|
134
|
+
}))
|
|
135
|
+
splitCategory(rawAccountList.value)
|
|
136
|
+
})
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
// 分类处理
|
|
140
|
+
const splitCategory = (list: { category: string }[]) => {
|
|
141
|
+
const cateMap = new Map<string, { id: number; name: string }>()
|
|
142
|
+
list.forEach(item => {
|
|
143
|
+
const cateName = item.category || '其他'
|
|
144
|
+
if (!cateMap.has(cateName)) {
|
|
145
|
+
cateMap.set(cateName, { id: cateMap.size + 1, name: cateName })
|
|
146
|
+
}
|
|
147
|
+
})
|
|
148
|
+
categoryList.value = Array.from(cateMap.values())
|
|
149
|
+
if (categoryList.value.length) {
|
|
150
|
+
activeCateId.value = categoryList.value[0].id
|
|
151
|
+
if (activeCateId.value) switchCategory(activeCateId.value)
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// 切换分类
|
|
156
|
+
const switchCategory = (cateId: number) => {
|
|
157
|
+
activeCateId.value = cateId
|
|
158
|
+
const targetCate = categoryList.value.find(c => c.id === cateId)
|
|
159
|
+
currentAccountList.value = rawAccountList.value.filter(item => item.category === targetCate?.name)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// 选择科目
|
|
163
|
+
const selectAccount = (acc: any) => {
|
|
164
|
+
const entry = entries.value[currentEntryIndex.value]
|
|
165
|
+
entry.accountName = acc.text
|
|
166
|
+
entry.accountId = acc.value
|
|
167
|
+
showAccountPicker.value = false
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const openAccountPicker = (index: number) => {
|
|
171
|
+
currentEntryIndex.value = index
|
|
172
|
+
showAccountPicker.value = true
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const addEntry = () => {
|
|
176
|
+
entries.value.push({
|
|
177
|
+
accountName: '', accountId: null, debit: '', credit: '', remark: ''
|
|
178
|
+
})
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const removeEntry = (index: number) => {
|
|
182
|
+
if (entries.value.length === 1) {
|
|
183
|
+
showToast('至少保留一笔分录')
|
|
184
|
+
return
|
|
185
|
+
}
|
|
186
|
+
entries.value.splice(index, 1)
|
|
187
|
+
calcTotal()
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// 精确计算(保留2位小数)
|
|
191
|
+
const calcTotal = () => {
|
|
192
|
+
let debit = 0
|
|
193
|
+
let credit = 0
|
|
194
|
+
entries.value.forEach(e => {
|
|
195
|
+
debit += Math.round((parseFloat(e.debit) || 0) * 100)
|
|
196
|
+
credit += Math.round((parseFloat(e.credit) || 0) * 100)
|
|
197
|
+
})
|
|
198
|
+
totalDebit.value = Math.round(debit) / 100
|
|
199
|
+
totalCredit.value = Math.round(credit) / 100
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// ==============================================
|
|
203
|
+
// 保存成功 → 自动新建空白凭证(核心功能)
|
|
204
|
+
// ==============================================
|
|
205
|
+
const submit = () => {
|
|
206
|
+
calcTotal()
|
|
207
|
+
if (totalDebit.value !== totalCredit.value) {
|
|
208
|
+
showToast('❌ 借贷必须相等!')
|
|
209
|
+
return
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
voucher.entries = entries.value.map(e => ({
|
|
213
|
+
account: { id: e.accountId },
|
|
214
|
+
debit: parseFloat(e.debit) || 0,
|
|
215
|
+
credit: parseFloat(e.credit) || 0,
|
|
216
|
+
description: voucher.description
|
|
217
|
+
}))
|
|
218
|
+
|
|
219
|
+
axios.post('/voucher/create', voucher).then(() => {
|
|
220
|
+
showToast('✅ 凭证保存成功')
|
|
221
|
+
|
|
222
|
+
// 自动新开空白凭证
|
|
223
|
+
Object.assign(voucher, initVoucher())
|
|
224
|
+
entries.value = [{ accountName: '', accountId: null, debit: '', credit: '', remark: '' }]
|
|
225
|
+
calcTotal()
|
|
226
|
+
|
|
227
|
+
}).catch(err => {
|
|
228
|
+
showToast('❌ 保存失败')
|
|
229
|
+
console.error(err)
|
|
230
|
+
})
|
|
231
|
+
}
|
|
232
|
+
</script>
|
|
233
|
+
|
|
234
|
+
<style scoped>
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
.title {
|
|
238
|
+
padding: 10px 10px;
|
|
239
|
+
font-weight: bold;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
.entry-card {
|
|
243
|
+
background: #f7f8fa;
|
|
244
|
+
border-radius: 8px;
|
|
245
|
+
padding: 8px;
|
|
246
|
+
margin-bottom: 10px;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
.account-popup {
|
|
250
|
+
width: 90%;
|
|
251
|
+
height: 70vh;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
.picker-header {
|
|
255
|
+
display: flex;
|
|
256
|
+
justify-content: space-between;
|
|
257
|
+
align-items: center;
|
|
258
|
+
padding: 12px 16px;
|
|
259
|
+
border-bottom: 1px solid #eee;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
.picker-title {
|
|
263
|
+
font-size: 16px;
|
|
264
|
+
font-weight: 500;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
.split-picker {
|
|
268
|
+
display: flex;
|
|
269
|
+
height: calc(100% - 48px);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
.left-category {
|
|
273
|
+
width: 35%;
|
|
274
|
+
background: #f5f5f5;
|
|
275
|
+
overflow-y: auto;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
.cate-item {
|
|
279
|
+
padding: 14px 10px;
|
|
280
|
+
text-align: center;
|
|
281
|
+
font-size: 14px;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
.cate-item.active {
|
|
285
|
+
background: #fff;
|
|
286
|
+
color: #1989fa;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
.right-account {
|
|
290
|
+
flex: 1;
|
|
291
|
+
overflow-y: auto;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
.acc-item {
|
|
295
|
+
padding: 14px 16px;
|
|
296
|
+
border-bottom: 1px solid #f5f5f5;
|
|
297
|
+
font-size: 14px;
|
|
298
|
+
}
|
|
357
299
|
</style>
|