import{e as F,i as y,o as m,g as v,S as I,x as C,p as P,w as O,h as t,j as w,n as M,k as L,F as S,t as E,P as T,m as g,l as z,f as D,U as Y,y as N,V as J,C as $,R as q,T as G}from"./vendor.961f4417.js";import{a as b,_ as U,d as R,T as h,R as K,c as j}from"./index.c104fbd6.js";import{d as V,g as Q}from"./dateFormat.a9df66b7.js";import{S as W}from"./Spinner.33b65f67.js";import{_ as X,d as Z}from"./dateFilter.a11ea60c.js";var k={expense:{getAll(){return b.get("/expense/all")},getOne(i){return b.get(`/expense/${i}`)},create(i){return b.post("/expense/create",i)},edit(i,o){return b.put(`/expense/edit/${i}`,o)},delete(i){return b.delete(`/expense/delete/${i}`)}},category:{getAll(){return b.get("/category/all")},getOne(i){return b.get(`/category/${i}`)},create(i){return b.post("/category/create",i)},edit(i,o){return b.put(`/category/edit/${i}`,o)},delete(i){return b.delete(`/category/delete/${i}`)}}};const ee=F({setup(i){const o=y("refetchCategories"),u=async()=>{try{const{value:a}=await R.fire({title:"\u65B0\u589E\u985E\u5225",html:`
\u65E5\u671F
`,preConfirm:()=>{const f=document.getElementById("swal-categoryId").value,x=document.getElementById("swal-item").value,B=document.getElementById("swal-amount").value,r=new Date(document.getElementById("swal-date").value),p=document.getElementById("swal-note").value;if((!x||!B||!r)&&I.showValidationMessage("\u9664\u4E86[\u5099\u8A3B]\uFF0C\u6240\u6709\u8CC7\u6599\u90FD\u662F\u5FC5\u586B\uFF01"),u.currentUser)return{input:{UserId:u.currentUser.id,CategoryId:Number(f),item:x,amount:B,note:p,date:r}};h.fire({icon:"error",title:"\u7121\u6CD5\u53D6\u5F97\u4F7F\u7528\u8005ID"})}});console.log("formValues",c),c!=null&&c.input&&n(c)}catch(l){console.error("error",l)}},n=async function(l){try{const{data:c}=await k.expense.edit(o.expense.id,l.input);if(c.status!=="success")throw new Error(`[SERVER ERROR] ${c.message}`);d(),h.fire({icon:"success",title:`\u6210\u529F\u7DE8\u8F2F\u8A18\u5E33[${c.data.item}]`})}catch(c){console.error("error",c),h.fire({icon:"error",title:"\u7DE8\u8F2F\u8A18\u5E33\u5931\u6557\uFF01"})}};return(l,c)=>(m(),v("i",{class:"fas fa-edit",onClick:e}))}});var we=U(Ee,[["__scopeId","data-v-05ea8b43"]]);const Fe=F({props:{expense:null},setup(i){const o=i,u=y("refetchExpenses"),d=async()=>{try{const{isConfirmed:s}=await R.fire({title:`\u78BA\u5B9A\u522A\u9664\u8A18\u5E33[${o.expense.item}]\u561B\uFF1F`,showCancelButton:!0});s&&a(o.expense.id)}catch(s){console.error("error",s)}},a=async function(s){try{const{data:e}=await k.expense.delete(s);if(e.status!=="success")throw new Error(`[SERVER ERROR] ${e.message}`);u(),h.fire({icon:"success",title:`\u6210\u529F\u522A\u9664\u8A18\u5E33[${e.data.item}]`})}catch(e){console.error("error",e),h.fire({icon:"error",title:"\u522A\u9664\u8A18\u5E33\u5931\u6557\uFF01"})}};return(s,e)=>(m(),v("i",{class:"fas fa-trash",onClick:d}))}});var xe=U(Fe,[["__scopeId","data-v-5dc5c3f6"]]);const Ce={class:"bg-secondary me-3 p-3"},ke={class:"form-check form-switch mb-4"},Be=t("label",{class:"form-check-label",for:"flexSwitchCheckChecked"},"\u5168\u9078",-1),$e=["value","id","checked","onClick"],Ae=["for"],De=F({props:{allCategories:null},setup(i){const o=i,u=C(!0),d=y("categoriesByType"),a=y("categoryFilters"),s=e=>{a.value.includes(e)?a.value.forEach((n,l)=>{if(e===n){a.value.splice(l,1);return}}):a.value.push(e)};return Y(u,()=>{u.value?a.value=o.allCategories:a.value=[]}),(e,n)=>(m(),v("div",Ce,[t("div",ke,[Be,N(t("input",{class:"form-check-input",type:"checkbox",role:"switch",id:"flexSwitchCheckChecked","onUpdate:modelValue":n[0]||(n[0]=l=>u.value=l)},null,512),[[J,u.value]])]),(m(!0),v(S,null,L(g(d),(l,c)=>(m(),v("div",{class:"form-check mb-2",key:c},[t("input",{class:"form-check-input",type:"checkbox",value:l.id,id:l.name,checked:g(a).includes(l.id),onClick:f=>s(l.id)},null,8,$e),t("label",{class:"form-check-label",for:l.name},E(l.name),9,Ae)]))),128))]))}}),Ie={key:0},Ue={class:"d-flex mb-3",style:{width:"100vw"}},Re={class:"d-flex mb-4",style:{width:"100%"}},Me={class:"mt-4",style:{width:"100px"}},Ve=t("label",{for:"type",style:{float:"left","font-size":"0.7em"}},"TYPE",-1),Se=t("option",{selected:""},"ALL",-1),Pe=t("option",null,"\u652F\u51FA",-1),Oe=t("option",null,"\u6536\u5165",-1),Le=[Se,Pe,Oe],Te={class:"d-flex align-items-center mb-4",style:{width:"100%"}},Ye={class:"badge bg-warning text-dark fs-3"},Ne=t("i",{class:"fas fa-minus mx-2"},null,-1),je={class:"badge bg-success fs-3"},He=t("i",{class:"fas fa-equals mx-2"},null,-1),ze={class:"badge bg-info fs-3"},Je={class:"d-flex align-items-start"},qe={key:0,class:"table table-striped table-success table-hover"},Ge=t("thead",null,[t("tr",{class:"table-light"},[t("th",{scope:"col"},"#"),t("th",{scope:"col"},"#"),t("th",{scope:"col"},"\u985E\u5225"),t("th",{scope:"col"},"\u9805\u76EE"),t("th",{scope:"col"},"\u91D1\u984D"),t("th",{scope:"col"},"\u5099\u8A3B"),t("th",{scope:"col"},"\u65E5\u671F")])],-1),Ke={key:1,class:"img-fluid",src:"https://stickershop.line-scdn.net/stickershop/v1/sticker/208430466/iPhone/sticker_animation@2x.png",alt:"img"},tt=F({setup(i){const o=C(),u=C(),d=C(!1),a=C([]),s=C({searchMode:"\u6708\u4EFD",filter:{year:V().year(),month:V().month()+1,startDate:V().startOf("month").format("YYYY-MM-DD hh:mm:ss"),finishDate:V().endOf("month").format("YYYY-MM-DD hh:mm:ss")}}),e=C("ALL"),n=D(()=>e.value!=="ALL"?u.value.filter(r=>r.type===e.value).map(r=>r.id):u.value.map(r=>r.id)),l=D(()=>e.value==="ALL"?u.value:u.value.filter(r=>r.type===e.value)),c=D(()=>{let r=[];return r=o.value.filter(p=>a.value.includes(p.Category.id)),Z(s.value,r)}),f=D(()=>{let r=0,p=0;return c.value.forEach(A=>{A.Category.type==="\u652F\u51FA"?p+=A.amount:r+=A.amount}),{income:r,expense:p}}),x=async function(){try{const{data:r}=await k.expense.getAll();o.value=r.data}catch(r){console.error("error",r)}},B=async()=>{try{const{data:r}=await k.category.getAll();u.value=r.data,a.value=u.value.map(p=>p.id)}catch(r){console.error("error",r)}};return x(),B(),Y(e,r=>{r!=="ALL"?a.value=u.value.filter(p=>p.type===e.value).map(p=>p.id):a.value=u.value.map(p=>p.id)}),$("refetchExpenses",x),$("refetchCategories",B),$("categories",u),$("categoryFilters",a),$("dateFilterData",s),$("categoryRPOpen",d),$("categoriesByType",l),(r,p)=>{var A;return o.value&&u.value?(m(),v("div",Ie,[t("div",Ue,[w(be),t("button",{type:"button",class:"btn btn-warning text-dark",onClick:p[0]||(p[0]=_=>d.value=!0)},"\u67E5\u770B\u985E\u5225")]),t("div",Re,[t("div",Me,[Ve,N(t("select",{class:"form-select",id:"type","aria-label":"Default select example","onUpdate:modelValue":p[1]||(p[1]=_=>e.value=_)},Le,512),[[q,e.value]])]),t("div",null,[w(X,{style:{width:"250px"}})])]),t("div",Te,[t("span",Ye,"\u6536\u5165 $ "+E(g(f).income),1),Ne,t("span",je,"\u652F\u51FA $ "+E(g(f).expense),1),He,t("span",ze,"$ "+E(g(f).income-g(f).expense),1)]),t("div",Je,[w(De,{allCategories:g(n)},null,8,["allCategories"]),(A=g(c))!=null&&A.length?(m(),v("table",qe,[Ge,t("tbody",null,[(m(!0),v(S,null,L(g(c),(_,H)=>(m(),v("tr",{key:H,class:M(_.Category.type==="\u652F\u51FA"?"table-success":"table-warning")},[t("td",null,[w(we,{expense:_},null,8,["expense"])]),t("td",null,[w(xe,{expense:_},null,8,["expense"])]),t("td",null,[t("i",{class:M(_.Category.icon)},null,2)]),t("td",null,E(_.item),1),t("td",null,E(_.amount),1),t("td",null,E(_.note),1),t("td",null,E(new Date(_.date).toLocaleDateString()+" "+g(Q)(_.date)),1)],2))),128))])])):(m(),v("img",Ke))]),w(G,{name:"slide-right"},{default:O(()=>[d.value?(m(),P(ge,{key:0})):T("",!0)]),_:1})])):(m(),P(W,{key:1}))}}});export{tt as default};