HomePage.jsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import React, { Component } from 'react';
  2. import Lists from './List'
  3. import Buttons from './Button'
  4. import IconList from './IconList'
  5. import {graphqls} from '../../api/graphql_request'
  6. import {BILL_BY_PROPS} from '../../api/graphql/bills'
  7. import {getMonDayAndSunDay} from '../../untils/date'
  8. import './HomePage.css'
  9. //console.log(new Date().toLocaleString('chinese', { hour12: false }).slice(0,10))
  10. class HomePage extends Component{
  11. constructor(props){
  12. super(props)
  13. const month =new Date().getMonth()+1
  14. const year=new Date().getFullYear()
  15. this.state={
  16. month,
  17. year,
  18. weekBottom:'',
  19. weekTop:'',
  20. bills:[]
  21. }
  22. }
  23. getBills(){
  24. graphqls(BILL_BY_PROPS,{}).then((e)=>{
  25. console.log('1----',e.billbyprops)
  26. this.setState({
  27. bills:e.billbyprops
  28. })
  29. })
  30. }
  31. componentDidMount(){
  32. //console.log('组件已加载')
  33. this.props.setNavBarText('微记账本')
  34. this.getBills()
  35. let today=new Date().toLocaleString('chinese', { hour12: false }).slice(0,10)
  36. // 1: "118-12-10"
  37. // 2: "118-12-16"
  38. //console.log('110',getMonDayAndSunDay(today))
  39. let result=getMonDayAndSunDay(today)
  40. let weekBottom='20' + result[1].slice(1,10)
  41. let weekTop='20'+ result[2].slice(1,10)
  42. //console.log(weekTop,weekBottom)
  43. this.setState({weekTop,weekBottom})
  44. }
  45. render(){
  46. const weekTop=this.state.weekTop
  47. const weekBottom=this.state.weekBottom
  48. return(
  49. <div>
  50. <div className="dateWrap"><span className="month"> {this.state.month} </span> / {this.state.year}</div>
  51. <Lists bills={this.state.bills} year={this.state.year} month={this.state.month}/>
  52. <div className="buttonWrap">
  53. <Buttons />
  54. </div>
  55. <IconList bills={this.state.bills} week={{weekTop,weekBottom}}/>
  56. </div>
  57. )
  58. }
  59. }
  60. export default HomePage