1 line
8.1 KiB
JavaScript
1 line
8.1 KiB
JavaScript
(this["webpackJsonpbeancount-web"]=this["webpackJsonpbeancount-web"]||[]).push([[13],{218:function(t,e,n){"use strict";var a=n(84),c=n(11),r=n(12),i=n(14),o=n(13),s=n(209),l=n(125),h=n.n(l),u=n(0),d=n(66),b=n(1),p=function(t){Object(i.a)(n,t);var e=Object(o.a)(n);function n(){var t;Object(c.a)(this,n);for(var a=arguments.length,r=new Array(a),i=0;i<a;i++)r[i]=arguments[i];return(t=e.call.apply(e,[this].concat(r))).currentYear=h()().format("YYYY"),t.currentMonth=h()().format("YYYY-M"),t.state={loading:!1,years:[t.currentYear],months:[t.currentMonth]},t.queryMonthList=function(){t.setState({loading:!0}),Object(d.b)("/api/auth/stats/months").then((function(e){var n=Array.from(new Set(e.map((function(t){return t.split("-")[0]}))));t.setState({months:e,years:n})})).catch(console.error).finally((function(){t.setState({loading:!1})}))},t}return Object(r.a)(n,[{key:"componentDidMount",value:function(){this.queryMonthList()}},{key:"render",value:function(){return Object(b.jsxs)(s.a,Object(a.a)(Object(a.a)({size:"small",showSearch:!0,placeholder:"\u9009\u62e9\u6708\u4efd",style:{width:"120px"}},this.props),{},{children:[Object(b.jsx)(s.a.Option,{value:"",children:"\u4e0d\u9650"}),this.state.years.map((function(t){return Object(b.jsx)(s.a.Option,{value:t,children:h()(t).format("YYYY\u5e74")},t)})),this.state.months.map((function(t){return Object(b.jsx)(s.a.Option,{value:t,children:h()(t).format("YYYY\u5e74MM\u6708")},t)}))]}))}}]),n}(u.Component);e.a=p},244:function(t,e,n){"use strict";var a=n(66);e.a=function(t,e){var n=Object(a.c)(t);return"Income"===n?e>0?"-\uffe5".concat(Math.abs(e)):"+\uffe5".concat(Math.abs(e)):"Assets"===n?e>0?"\uffe5".concat(Math.abs(e)):"-\uffe5".concat(Math.abs(e)):"Expenses"===n?e>0?"-\uffe5".concat(Math.abs(e)):"+\uffe5".concat(Math.abs(e)):"Liabilities"===n?e>0?"+\uffe5".concat(Math.abs(e)):"-\uffe5".concat(Math.abs(e)):String(e)}},245:function(t,e,n){"use strict";n(0);var a=n(1);e.a=function(t){var e=t.iconType;return Object(a.jsx)("img",{src:"../../icons/".concat(e,".png"),alt:"",width:32,height:32})}},345:function(t,e,n){},459:function(t,e,n){"use strict";n.r(e);var a=n(11),c=n(12),r=n(14),i=n(13),o=n(346),s=n(347),l=n(451),h=n(460),u=n(454),d=n(220),b=n(449),p=n(330),f=n(125),j=n.n(f),y=n(0),m=n.n(y),O=n(244),g=n(245),v=n(218),x=n(66),M=n(15),Y=n(76),S=(n(345),n(1)),I=function(t){Object(r.a)(n,t);var e=Object(i.a)(n);function n(){var t;Object(a.a)(this,n);for(var c=arguments.length,r=new Array(c),i=0;i<c;i++)r[i]=arguments[i];return(t=e.call.apply(e,[this].concat(r))).theme=t.context.theme,t.formRef=m.a.createRef(),t.ledgerId=window.localStorage.getItem("ledgerId"),t.currentMonth=j()().format("YYYY-M"),t.state={loading:!1,Income:0,Expenses:0,Liabilities:0,listLoading:!1,type:"Expenses",transactionDateGroup:{},selectedMonth:t.currentMonth},t.queryMonthStats=function(){t.setState({loading:!0}),Object(x.b)("/api/auth/stats/total?year=".concat(j()(t.state.selectedMonth).year(),"&month=").concat(j()(t.state.selectedMonth).month()+1)).then((function(e){var n=e.Income,a=void 0===n?0:n,c=e.Expenses,r=void 0===c?0:c,i=e.Liabilities,o=void 0===i?0:i;t.setState({Income:a,Expenses:r,Liabilities:o})})).catch(console.error).finally((function(){t.setState({loading:!1})}))},t.queryEntryList=function(){var e=t.state,n=e.type,a=e.selectedMonth,c=j()(a).year(),r=j()(a).month()+1;t.setState({listLoading:!0}),Object(x.b)("/api/auth/entry?type=".concat(n,"&year=").concat(c,"&month=").concat(r)).then((function(e){var n={};e.forEach((function(t){var e=t.date,a=n[e];a?a.children.push(t):n[e]={date:e,children:[t]}})),t.setState({transactionDateGroup:n})})).catch(console.error).finally((function(){t.setState({listLoading:!1})}))},t.handleChangeEntryType=function(e){t.setState({type:e},(function(){t.queryEntryList()}))},t.handleChangeMonth=function(e){t.setState({selectedMonth:e},(function(){t.queryMonthStats(),t.queryEntryList()}))},t}return Object(c.a)(n,[{key:"componentDidMount",value:function(){window.localStorage.getItem("ledgerId")?(this.queryMonthStats(),this.queryEntryList()):this.props.history.replace("/ledger")}},{key:"render",value:function(){var t=this;this.context.theme!==this.theme&&(this.theme=this.context.theme);var e=this.state,n=e.loading,a=e.type,c=e.listLoading,r=e.transactionDateGroup,i=Object.values(r);return Object(S.jsxs)("div",{className:"index-page page",children:[Object(S.jsx)("div",{style:{marginBottom:"2rem"},children:Object(S.jsx)(v.a,{value:this.state.selectedMonth,onChange:this.handleChangeMonth})}),Object(S.jsx)("div",{style:{textAlign:"center"},children:Object(S.jsxs)(o.a,{children:[Object(S.jsx)(s.a,{span:8,onClick:function(){t.handleChangeEntryType("Income")},children:Object(S.jsx)(l.a,{title:"\u672c\u6708".concat(x.a.Income),value:Math.abs(this.state.Income),loading:n,prefix:this.state.Income>0?"-":"+",valueStyle:{color:"#cf1322"}})}),Object(S.jsx)(s.a,{span:8,onClick:function(){t.handleChangeEntryType("Expenses")},children:Object(S.jsx)(l.a,{title:"\u672c\u6708".concat(x.a.Expenses),value:Math.abs(this.state.Expenses),loading:n,prefix:this.state.Expenses>=0?"-":"+",valueStyle:{color:"#3f8600"}})}),Object(S.jsx)(s.a,{span:8,onClick:function(){t.handleChangeEntryType("Liabilities")},children:Object(S.jsx)(l.a,{title:"\u672c\u6708".concat(x.a.Liabilities),value:Math.abs(this.state.Liabilities),loading:n,prefix:this.state.Liabilities>0?"+":"-",valueStyle:{color:"#3f8600"}})})]})}),Object(S.jsxs)(h.a,{plain:!0,children:["\u672c\u6708",x.a[this.state.type],"\u660e\u7ec6"]}),Object(S.jsx)("div",{children:c||0!==i.length?Object(S.jsx)(d.a,{tip:"\u52a0\u8f7d\u4e2d...",style:{marginTop:"1rem"},spinning:c,children:i.map((function(t){return Object(S.jsx)(b.b,{header:Object(S.jsxs)("div",{children:[j()(t.date).format("YYYY\u5e74M\u6708D\u53f7"),"\xa0\xa0",t.date===j()().format("YYYY-MM-DD")&&Object(S.jsx)(p.a,{color:"#1DA57A",children:"\u4eca\u5929"})]}),itemLayout:"horizontal",dataSource:t.children,renderItem:function(t){return Object(S.jsx)(b.b.Item,{actions:[t.amount?Object(S.jsx)("div",{children:Object(O.a)(t.account,t.amount)}):""],children:Object(S.jsx)(b.b.Item.Meta,{avatar:Object(S.jsx)(g.a,{iconType:Object(x.e)(t.account)}),title:t.desc,description:"".concat(t.date," ").concat(Object(x.d)(t.account)," ").concat(t.payee)})})}},t.date)}))}):Object(S.jsx)(u.a,{description:"\u65e0".concat(x.a[a],"\u5185\u5bb9")})})]})}}]),n}(y.Component);I.contextType=M.a,e.default=Object(Y.a)(I)},66:function(t,e,n){"use strict";n.d(e,"c",(function(){return i})),n.d(e,"e",(function(){return o})),n.d(e,"d",(function(){return s})),n.d(e,"a",(function(){return l})),n.d(e,"b",(function(){return u}));var a=n(456),c=n(196),r=n.n(c),i=function(t){var e=t.split(":");return e&&e.length>=1?t.split(":")[0]:""},o=function(t){var e=t.split(":");return e&&2===e.length?t.split(":")[1]:e&&e.length>=3?t.split(":")[e.length-2]:""},s=function(t){var e=t.split(":");return e&&e.length>=2?t.split(":")[e.length-1]:""},l={Income:"\u6536\u5165",Expenses:"\u652f\u51fa",Liabilities:"\u8d1f\u503a",Assets:"\u8d44\u4ea7"},h=function(t){return t},u=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=e.method,c=e.headers,i=e.body,o={"Content-Type":"application/json",ledgerId:window.localStorage.getItem("ledgerId")};return new Promise((function(e,s){r()(t,{method:n,headers:Object.assign({},o,c),body:JSON.stringify(i)}).then(h).then((function(t){return t.json()})).then((function(t){var n=t.code;200===n?e(t.data):200!==n&&(400===n?a.b.error("\u8bf7\u6c42\u53c2\u6570\u9519\u8bef"):1001===n?a.b.error("\u8d26\u76ee\u4e0d\u5e73\u8861"):1003===n?a.b.error("\u65e0\u6548\u8d26\u6237"):1005===n?a.b.error("\u65e0\u6548\u547d\u4ee4"):1006===n?a.b.error("\u5bc6\u7801\u9519\u8bef"):1010===n?window.location.href="/#/ledger":a.b.error("\u8bf7\u6c42\u5931\u8d25\uff0c\u8bf7\u5237\u65b0\u9875\u9762\u91cd\u8bd5"),s(t))})).catch((function(t){a.b.error("\u8bf7\u6c42\u5931\u8d25\uff0c\u8bf7\u5237\u65b0\u9875\u9762\u91cd\u8bd5"),s(t)}))}))}},76:function(t,e,n){"use strict";var a=n(84),c=n(11),r=n(12),i=n(14),o=n(13),s=n(0),l=n(1);e.a=function(t){return function(e){Object(i.a)(s,e);var n=Object(o.a)(s);function s(){return Object(c.a)(this,s),n.apply(this,arguments)}return Object(r.a)(s,[{key:"render",value:function(){return Object(l.jsx)(t,Object(a.a)({},this.props))}}]),s}(s.Component)}}}]); |