33 <v-card >
44 <v-card-title >
55<!-- 月選択-->
6- <v-col cols =" 8" >
6+ <v-col cols =" 8" sm = " 3 " >
77 <v-menu
88ref =" menu"
99v-model =" menu"
4444 <v-icon >mdi-plus</v-icon >
4545 </v-btn >
4646 </v-col >
47+ <!-- 収支総計-->
48+ <v-col class =" overflow-x-auto" cols =" 12" sm =" 8" >
49+ <div class =" summary" >
50+ <div class =" mr-4" >
51+ <table class =" text-right" >
52+ <tr >
53+ <td >収入:</td >
54+ <td >{{ separate(sum.income) }}</td >
55+ </tr >
56+ <tr >
57+ <td >支出:</td >
58+ <td >{{ separate(sum.outgo) }}</td >
59+ </tr >
60+ <tr >
61+ <td >収支差:</td >
62+ <td >{{ separate(sum.income - sum.outgo) }}</td >
63+ </tr >
64+ </table >
65+ </div >
66+ <div v-for =" category in sum.categories" :key =" category[0]" >
67+ <v-progress-circular
68+ class =" mr-2"
69+ :rotate =" -90"
70+ :size =" 60"
71+ :width =" 5"
72+ :value =" category[1]"
73+ color =" teal"
74+ >
75+ {{ category[0] }}
76+ </v-progress-circular >
77+ </div >
78+ </div >
79+ </v-col >
4780<!-- 検索フォーム-->
48- <v-col cols =" 12" >
81+ <v-col cols =" 12" sm = " 4 " >
4982 <v-text-field
5083v-model =" search"
5184append-icon =" mdi-magnify"
@@ -162,6 +195,41 @@ export default {
162195/** テーブルのフッター設定*/
163196footerProps () {
164197return { itemsPerPageText: ' ' , itemsPerPageOptions: [] }
198+ },
199+
200+ /** 収支総計*/
201+ sum () {
202+ let income= 0
203+ let outgo= 0
204+ const categoryOutgo = {}
205+ const categories = []
206+
207+ // 収支の合計とカテゴリ別の支出を計算
208+ for (const row of this .tableData ) {
209+ if (row .income !== null ) {
210+ income+= row .income
211+ }else {
212+ outgo+= row .outgo
213+ if (categoryOutgo[row .category ]) {
214+ categoryOutgo[row .category ]+= row .outgo
215+ }else {
216+ categoryOutgo[row .category ]= row .outgo
217+ }
218+ }
219+ }
220+
221+ // カテゴリ別の支出を降順にソート
222+ const sorted = Object .entries (categoryOutgo).sort ((a ,b )=> b[1 ]- a[1 ])
223+ for (const [category ,value ]of sorted) {
224+ const percent = parseInt ((value/ outgo)* 100 )
225+ categories .push ([category, percent])
226+ }
227+
228+ return {
229+ income,
230+ outgo,
231+ categories
232+ }
165233 }
166234 },
167235
@@ -215,3 +283,12 @@ export default {
215283 }
216284}
217285 </script >
286+
287+ <style >
288+ .summary {
289+ display :flex ;
290+ font-size :0.8rem ;
291+ white-space :nowrap ;
292+ line-height :1.2rem ;
293+ }
294+ </style >