|
|
@@ -1,10 +1,12 @@
|
|
|
import React from 'react'
|
|
|
import './ActionSheet.css'
|
|
|
-
|
|
|
-import {PageContext} from '../../context/context'
|
|
|
import { ActionSheet, WingBlank, WhiteSpace, Button, Toast } from 'antd-mobile';
|
|
|
import { List, Stepper } from 'antd-mobile';
|
|
|
|
|
|
+import {graphqls} from '../../api/graphql_request'
|
|
|
+import {createShopCar} from '../../api/graphql/shopCar'
|
|
|
+import {PageContext} from '../../context/context'
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
@@ -14,6 +16,7 @@ class ActionSheets extends React.Component {
|
|
|
this.state = {
|
|
|
num:1
|
|
|
};
|
|
|
+ this.addCar=this.addCar.bind(this)
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -36,6 +39,26 @@ class ActionSheets extends React.Component {
|
|
|
this.props.setNum(num)
|
|
|
}
|
|
|
|
|
|
+ addCar(){
|
|
|
+ let that=this
|
|
|
+ let createdAt=new Date().toLocaleDateString()+' '+new Date().toLocaleTimeString().slice(2)
|
|
|
+ let id=new Date().getTime()+parseInt(Math.random()*100000,10)
|
|
|
+ let user_id=sessionStorage.getItem('openid')
|
|
|
+ console.log(user_id)
|
|
|
+ //console.log('-----',this.props)
|
|
|
+ const variable={
|
|
|
+ count:that.state.num,
|
|
|
+ id,
|
|
|
+ createdAt,
|
|
|
+ updatedAt:createdAt,
|
|
|
+ user_id,
|
|
|
+ product_id:this.props.product.id
|
|
|
+ }
|
|
|
+ console.log(variable)
|
|
|
+
|
|
|
+ graphqls(createShopCar,variable).then(e=>console.log(e))
|
|
|
+ }
|
|
|
+
|
|
|
render() {
|
|
|
return (
|
|
|
<div className="actionSheet">
|
|
|
@@ -50,7 +73,7 @@ class ActionSheets extends React.Component {
|
|
|
{(changePage)=>{
|
|
|
return(
|
|
|
<div className="buttonWraps">
|
|
|
- <button>加入购物车</button>
|
|
|
+ <button onClick={this.addCar}>加入购物车</button>
|
|
|
<button onClick={()=>changePage('order')}>立即购买</button>
|
|
|
</div>
|
|
|
)
|