import React, {Component} from 'react' import {NavBar, ActivityIndicator} from 'antd-mobile' import {Query} from "react-apollo" import gql from "graphql-tag" import CartDetail from "./detail" import CartEdit from "./edit" import Empty from "../empty" import './index.css' import {cart_by_userid} from "../../../utils/gql" class All extends Component { constructor(props) { super(props) this.state = { page: 'detail' } } componentWillMount() { this.getHash() } componentWillReceiveProps(nextProps, nextContext) { this.getHash() } getHash = () => { // console.log('location',window.location.hash) let hash = window.location.hash || '#tab=cart&page=detail' let page = 'detail' if (window.location.hash && hash.indexOf("&") > 0) { let pageHash = hash.split("&")[1] page = pageHash.substr(pageHash.indexOf("=") + 1) } this.setState({ page }) } changeCartPage = () => { this.setState((preState) => ({ page: preState.page === 'detail' ? 'edit' : 'detail' })) } renderPage = (data) => { let {page} = this.state switch (page) { case 'detail': return case 'edit': return default: return
test
} } render() { let {page} = this.state return ( { ({loading, error, data}) => { if (loading) { return (
正在加载...
) } if (error) { return 'error!' } // console.log('cart data',data) return (
{page === 'detail' ? "编辑" : "完成"} : '' ]} >购物袋
{data.cartList.length ? this.renderPage(data) : }
) } }
) } } export default All