Kaynağa Gözat

增加删除商品按钮

kulley 6 yıl önce
ebeveyn
işleme
6325216161
4 değiştirilmiş dosya ile 100 ekleme ve 59 silme
  1. 1 1
      src/App.js
  2. 8 8
      src/pages/home/kind/index.js
  3. 83 49
      src/pages/my/manage/goods/index.js
  4. 8 1
      src/utils/gql.js

+ 1 - 1
src/App.js

@@ -85,7 +85,7 @@ class App extends Component {
 
     oauthLogin = () => {
         let openid =  getCookie("openid")
-        // setCookie("openid","obR_j5GbxDfGlOolvSeTdZUwfpKA")
+        setCookie("openid","obR_j5GbxDfGlOolvSeTdZUwfpKA")
         let user_id =  getCookie("user_id")
         console.log('oauthLogin openid',openid)
 

+ 8 - 8
src/pages/home/kind/index.js

@@ -32,7 +32,7 @@ class Kind extends Component {
 
     render() {
         let {id, category} = this.state
-        let contentHeight = window.innerHeight - 95
+        let contentHeight = window.innerHeight - 45
         return (
             <div className='kind-wrap'  style={{height: contentHeight}}>
                 <div className='kind-navbar-wrap'>
@@ -43,13 +43,13 @@ class Kind extends Component {
                         onLeftClick={() => {this.props.history.go(-1)}}
                     >{category}</NavBar>
                 </div>
-                <div className='kind-search-wrap'>
-                    <Search
-                        className='kind-search'
-                        placeholder="请输入搜索内容"
-                        onSearch={value => console.log(value)}
-                    />
-                </div>
+                {/*<div className='kind-search-wrap'>*/}
+                    {/*<Search*/}
+                        {/*className='kind-search'*/}
+                        {/*placeholder="请输入搜索内容"*/}
+                        {/*onSearch={value => console.log(value)}*/}
+                    {/*/>*/}
+                {/*</div>*/}
                 <Query query={gql(productbyprops)} variables={{category_id: id}}>
                     {
                         ({loading, error, data}) => {

+ 83 - 49
src/pages/my/manage/goods/index.js

@@ -17,6 +17,7 @@ import {withRouter} from 'react-router-dom'
 import {
     create_product,
     update_product,
+    delete_product_by_id,
     category_by_props,
     productbyprops,
     update_category,
@@ -63,7 +64,9 @@ class Goods extends Component {
                     }}
                 >商品管理</NavBar>
                 <div className='content-wrap'>
-                    <div className='my-list-subtitle' style={{color: 'grey'}}><Icon type="bulb" style={{marginRight: 10}}/>{accordionKey? '折叠单项以展开更多分类':'请选择需要打开的分类'}</div>
+                    <div className='my-list-subtitle' style={{color: 'grey'}}><Icon type="bulb"
+                                                                                    style={{marginRight: 10}}/>{accordionKey ? '折叠单项以展开更多分类' : '请选择需要打开的分类'}
+                    </div>
                     <Accordion className="my-accordion" onChange={(key) => {
                         this.setState({
                             accordionKey: key[0]
@@ -246,7 +249,7 @@ class AddGoods extends Component {
                                         stock,
                                         intro,
                                         price,
-                                        discountRate:100,
+                                        discountRate: 100,
                                         createdAt: moment().format('YYYY-MM-DD HH:mm:ss'),
                                         updatedAt: ''
                                     }
@@ -268,50 +271,74 @@ class AddGoods extends Component {
                                 }}
                             </Mutation>
                             :
-                            <Mutation mutation={gql(update_product)} refetchQueries={[
-                                {query: gql(productbyprops), variables: {}},
-                                {query: gql(productbyprops), variables: {status: '1', recommend: 1}}
-                            ]}>
-                                {(updateproduct, {loading, error}) => {
-                                    if (loading)
+                            <div>
+                                <Mutation mutation={gql(update_product)} refetchQueries={[
+                                    {query: gql(productbyprops), variables: {}},
+                                    {query: gql(productbyprops), variables: {status: '1', recommend: 1}}
+                                ]}>
+                                    {(updateproduct, {loading, error}) => {
+                                        if (loading)
+                                            return (
+                                                <div className="loading">
+                                                    <div className="align">
+                                                        <ActivityIndicator text="Loading..." size="large"/>
+                                                    </div>
+                                                </div>
+                                            )
+                                        if (error)
+                                            return 'error'
+                                        let varObj = {
+                                            id,
+                                            unit: '1件',
+                                            status: '1',
+                                            recommend: 0,
+                                            category_id: category_id[0],
+                                            name,
+                                            stock,
+                                            intro,
+                                            price,
+                                            updatedAt: moment().format('YYYY-MM-DD HH:mm:ss')
+                                        }
                                         return (
-                                            <div className="loading">
-                                                <div className="align">
-                                                    <ActivityIndicator text="Loading..." size="large"/>
+                                            <Button type="primary" size="small" inline onClick={() => {
+                                                Promise.all(this.uploadImg()).then(res => {
+                                                    let prefix = 'https://case-1254337200.cos.ap-beijing.myqcloud.com/'
+                                                    let img = imgDatas.length === 1 ? prefix + imgDatas[0]['file-name'] : imgDatas.map((imgData, index) => (
+                                                        prefix + imgDatas[index]['file-name']
+                                                    ))
+                                                    let variables = {...varObj}
+                                                    if (imgDatas.length !== 0) {
+                                                        variables.img = img
+                                                    }
+                                                    updateproduct({variables})
+                                                })
+                                            }}>更新</Button>
+                                        )
+                                    }}
+                                </Mutation>
+                                <Mutation mutation={gql(delete_product_by_id)} refetchQueries={[
+                                    {query: gql(productbyprops), variables: {}},
+                                    {query: gql(productbyprops), variables: {status: '1', recommend: 1}}
+                                ]}>
+                                    {(deleteproduct, {loading, error}) => {
+                                        if (loading)
+                                            return (
+                                                <div className="loading">
+                                                    <div className="align">
+                                                        <ActivityIndicator text="Loading..." size="large"/>
+                                                    </div>
                                                 </div>
-                                            </div>
+                                            )
+                                        if (error)
+                                            return 'error'
+                                        return (
+                                            <Button type="warning" size="small" inline onClick={() => {
+                                                deleteproduct({variables: {id}})
+                                            }}>删除</Button>
                                         )
-                                    if (error)
-                                        return 'error'
-                                    let varObj = {
-                                        id,
-                                        unit: '1件',
-                                        status: '1',
-                                        recommend: 0,
-                                        category_id: category_id[0],
-                                        name,
-                                        stock,
-                                        intro,
-                                        price,
-                                        updatedAt: moment().format('YYYY-MM-DD HH:mm:ss')
-                                    }
-                                    return (
-                                        <Button type="primary" size="small" inline onClick={() => {
-                                            Promise.all(this.uploadImg()).then(res => {
-                                                let prefix = 'https://case-1254337200.cos.ap-beijing.myqcloud.com/'
-                                                let img = imgDatas.length === 1 ? prefix + imgDatas[0]['file-name'] : imgDatas.map((imgData, index) => (
-                                                    prefix + imgDatas[index]['file-name']
-                                                ))
-                                                let variables = {...varObj}
-                                                if (imgDatas.length !== 0) {
-                                                    variables.img = img
-                                                }
-                                                updateproduct({variables})
-                                            })
-                                        }}>更新</Button>
-                                    )
-                                }}
-                            </Mutation>
+                                    }}
+                                </Mutation>
+                            </div>
                     }
                 </div>
             </List>
@@ -368,17 +395,22 @@ class AllGoods extends Component {
                                                              style={{backgroundImage: `url(${product.img})`}}/>
                                                     </Col>
                                                     <Col span={11} offset={1}>{product.name}</Col>
-                                                    <Col span={5} style={{display: 'flex', justifyContent: 'space-around'}}>
+                                                    <Col span={5}
+                                                         style={{display: 'flex', justifyContent: 'space-around'}}>
                                                         <Mutation mutation={gql(update_product)} refetchQueries={[
                                                             {query: gql(productbyprops), variables: {}},
-                                                            {query: gql(productbyprops), variables: {status: '1', recommend: 1}}
+                                                            {
+                                                                query: gql(productbyprops),
+                                                                variables: {status: '1', recommend: 1}
+                                                            }
                                                         ]}>
                                                             {(updateproduct, {loading, error}) => {
                                                                 if (loading)
                                                                     return (
                                                                         <div className="loading">
                                                                             <div className="align">
-                                                                                <ActivityIndicator text="Loading..." size="large"/>
+                                                                                <ActivityIndicator text="Loading..."
+                                                                                                   size="large"/>
                                                                             </div>
                                                                         </div>
                                                                     )
@@ -391,9 +423,11 @@ class AllGoods extends Component {
                                                                     updatedAt: moment().format('YYYY-MM-DD HH:mm:ss')
                                                                 }
                                                                 return (
-                                                                    <Icon type="like" className={classNames('not-like', {'like': recommend===1})} onClick={() => {
-                                                                        updateproduct({variables})
-                                                                    }}/>
+                                                                    <Icon type="like"
+                                                                          className={classNames('not-like', {'like': recommend === 1})}
+                                                                          onClick={() => {
+                                                                              updateproduct({variables})
+                                                                          }}/>
                                                                 )
                                                             }}
                                                         </Mutation>

+ 8 - 1
src/utils/gql.js

@@ -780,6 +780,12 @@ const update_product = `
     }
 `
 
+const delete_product_by_id = `
+    mutation deleteproduct($id: ID) {
+        deleteproduct: delete_product(id: $id)
+    }
+`
+
 export {
     create_user,
     find_user_by_openid,
@@ -808,5 +814,6 @@ export {
     create_shop,
     update_shop,
     create_product,
-    update_product
+    update_product,
+    delete_product_by_id
 }