kulley vor 6 Jahren
Ursprung
Commit
54ba4e4aaa

+ 2 - 1
src/App.js

@@ -92,7 +92,8 @@ class App extends Component {
         if (!openid) {
             window.location.href = "/subscribe"
 
-        }else if(!user_id){
+        }
+        if(!user_id){
             request(graphqlFC, find_user_by_openid ,{openid})
                 .then(data => {
                     console.log('find user data',data)

+ 2 - 1
src/pages/my/all/index.js

@@ -93,9 +93,10 @@ class All extends Component {
 
     render() {
         let user_id = getCookie('user_id')
+        console.log(user_id)
         return (
             <div className='my-wrap all'>
-                <Query query={gql(user_by_id)} variables={{user_id}}>
+                <Query query={gql(user_by_id)} variables={{id: user_id}}>
                     {
                         ({loading, error, data}) => {
                             if (loading) {

+ 37 - 9
src/pages/my/order/display/index.js

@@ -3,10 +3,11 @@ import {withRouter} from 'react-router-dom'
 import {Row, Col} from 'antd'
 import {NavBar, Icon, ActivityIndicator, Button} from 'antd-mobile'
 import {Query} from "react-apollo"
+import {Mutation} from "react-apollo"
 import gql from "graphql-tag"
 import classNames from 'classnames'
 
-import {orderbyprops, orderProduct_by_props} from "../../../../utils/gql"
+import {delete_order, orderbyprops, orderProduct_by_props} from "../../../../utils/gql"
 import {getCookie} from "../../../../utils/cookie"
 import './index.css'
 
@@ -155,7 +156,7 @@ class DisplayRender extends Component {
                                             return (
                                                 <div>
                                                     {
-                                                        button?
+                                                        button ?
                                                             <div className='order-card-content' onClick={() => {
                                                                 this.props.history.push({
                                                                     pathname: '/my/order/detail',
@@ -185,12 +186,14 @@ class DisplayRender extends Component {
                                     <div
                                         className='order-card-count'>共{order.count}件商品&nbsp;&nbsp;{content}:
                                     </div>
-                                    <div className='order-card-pay'>¥{Math.round(order.productTotalPay * 100) / 100}</div>
+                                    <div
+                                        className='order-card-pay'>¥{Math.round(order.productTotalPay * 100) / 100}</div>
                                 </div>
 
                                 {
-                                    button?
-                                        <ButtonGroupRender orderStatus={this.props.orderStatus} history={this.props.history}/>
+                                    button ?
+                                        <ButtonGroupRender id={order.id} orderStatus={this.props.orderStatus}
+                                                           history={this.props.history}/>
                                         :
                                         ''
                                 }
@@ -204,15 +207,40 @@ class DisplayRender extends Component {
 }
 
 const ButtonGroupRender = (props) => {
-    let {orderStatus} = props
+    let {orderStatus, id} = props
+    let user_id = getCookie('user_id')
     switch (orderStatus) {
         case '0':
             return (
                 <div className='order-card-button-group'>
-                    <Button size="small" className='pay-button order-button' onClick={()=>{
+                    <Mutation
+                        mutation={gql(delete_order)}
+                        refetchQueries={[{query: gql(orderbyprops), variables: {user_id, orderStatus}}]}
+                    >
+                        {(delete_order, {loading, error}) => {
+                            if (loading) {
+                                return (
+                                    <div className="loading-center">
+                                        <ActivityIndicator text="Loading..." size="large"/>
+                                    </div>
+                                )
+                            }
+                            if (error) {
+                                return 'error!'
+                            }
+                            return (
+                                <Button size="small" className='pay-button order-button' onClick={() => {
+                                    delete_order({variables: {id}})
+                                }}>取消</Button>
+                            )
+                        }}
+                    </Mutation>
+
+
+                    <Button size="small" className='pay-button order-button' style={{marginLeft: 5}} onClick={() => {
                         props.history.push({
-                            pathname:'/cart/pay',
-                            state:{}
+                            pathname: '/cart/pay',
+                            state: {}
                         })
                     }}>去支付</Button>
                 </div>

+ 3 - 1
src/pages/my/profile/index.js

@@ -35,7 +35,7 @@ class Profile extends Component {
 
                 <Mutation
                     mutation={gql(update_user)}
-                    refetchQueries={[{query: gql(user_by_id), variables: {user_id}}]}
+                    refetchQueries={[{query: gql(user_by_id), variables: {id: user_id}}]}
                 >
                     {(update_user, {loading, error}) => {
                         if (loading) {
@@ -56,6 +56,8 @@ class Profile extends Component {
                                     }} value={username} placeholder="请输入昵称">昵称</InputItem>
                                 </List>
                                 <Button onClick={() => {
+                                    console.log(username)
+                                    console.log(user_id)
                                     update_user({variables: {id: user_id, username}})
                                 }}>确认</Button>
                             </div>

+ 5 - 5
src/utils/cookie.js

@@ -1,8 +1,8 @@
-export function setCookie(name,value,exdays) {
+export function setCookie(name, value, exdays) {
     // expires表示过期时间。如果不设置,默认会话结束即关闭浏览器的时候就消失。
     // 第一步,设置过期时间
     let date = new Date();
-    date.setDate(date.getDate()+(exdays*24*60*60*1000));
+    date.setDate(date.getDate() + (exdays * 24 * 60 * 60 * 1000));
     document.cookie = name + "=" + value + ";expires=" + date;
     // alert(document.cookie);
 }
@@ -13,9 +13,9 @@ export function getCookie(key) {
     // 第二步:将数组arrStr中的元素再次切割,转换成数组
     let arrStrLength = arrStr.length;
 
-    for (let i=0;i<arrStrLength;i++){
+    for (let i = 0; i < arrStrLength; i++) {
         let arr = arrStr[i].split('=');
-        if(arr[0] === key){
+        if (arr[0] === key) {
             return arr[1];
         }
     }
@@ -23,5 +23,5 @@ export function getCookie(key) {
 }
 
 export function removeCookie(key) {
-    setCookie(key,"任意值",-1);
+    setCookie(key, "任意值", -1);
 }

+ 9 - 2
src/utils/gql.js

@@ -50,8 +50,8 @@ const user_by_id = `
 `
 
 const update_user = `
-    mutation updateuser($email: String, $updatedAt: String, $where: user_filter, $password: String, $telephone: String, $username: String, $createdAt: String, $openid: String, $id: ID, $userData_id: ID) {
-        updateuser: update_user(email: $email updatedAt: $updatedAt where: $where password: $password telephone: $telephone username: $username createdAt: $createdAt openid: $openid id: $id userData_id: $userData_id) {
+    mutation updateuser($id: ID, $email: String, $updatedAt: String, $where: user_filter, $password: String, $telephone: String, $username: String, $createdAt: String, $openid: String, $userData_id: ID) {
+        updateuser: update_user(id: $id email: $email updatedAt: $updatedAt where: $where password: $password telephone: $telephone username: $username createdAt: $createdAt openid: $openid userData_id: $userData_id) {
             result
             user {
                 email
@@ -612,6 +612,12 @@ const update_order = `
     }
 `
 
+const delete_order = `
+    mutation deleteorder($id: ID) {
+        deleteorder: delete_order(id: $id)
+    }
+`
+
 const orderProduct_by_props = `
     query orderProductbyprops($order_id: ID) {
         orderProductbyprops: orderProduct_by_props(order_id: $order_id) {
@@ -917,6 +923,7 @@ export {
     orderbyprops,
     order_by_id,
     update_order,
+    delete_order,
     orderProduct_by_props,
     create_order,
     create_order_product,