Quellcode durchsuchen

Merge remote-tracking branch 'origin/master'

Csy817 vor 6 Jahren
Ursprung
Commit
0eda8b94a3

+ 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}) => {

+ 1 - 1
src/pages/my/manage/goods/index.css

@@ -52,7 +52,7 @@
 }
 
 .modify-goods-modal{
-    height: 470px
+    height: 510px
 }
 
 .not-like {

+ 570 - 341
src/pages/my/manage/goods/index.js

@@ -17,11 +17,15 @@ import {withRouter} from 'react-router-dom'
 import {
     create_product,
     update_product,
+    delete_product_by_id,
     category_by_props,
     productbyprops,
     update_category,
     delete_category,
-    create_category
+    create_category,
+    specificationStock_by_props,
+    delete_specificationStock,
+    update_specificationStock
 } from "../../../../utils/gql"
 import {Query, Mutation} from "react-apollo"
 import gql from "graphql-tag"
@@ -63,7 +67,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]
@@ -88,345 +94,6 @@ class Goods extends Component {
     }
 }
 
-class AddGoods extends Component {
-    constructor(props) {
-        super(props)
-        let state = {
-            files: [],
-            imgDatas: [],
-        }
-        if (props.good === undefined) {
-            this.state = {
-                ...state,
-                name: '',
-                price: 0,
-                intro: '',
-                stock: 20,
-                category: '',
-                category_id: '',
-                newGood: true
-            }
-        } else {
-            // console.log(props.good)
-            let {name, price, intro, stock, id} = props.good
-            this.state = {
-                ...state,
-                id,
-                name,
-                price,
-                intro,
-                stock,
-                category: props.good.category_id.name,
-                category_id: [props.good.category_id.id],
-                newGood: false
-            }
-        }
-    }
-
-    onChange = (id) => (files, operationType) => {
-        let imgDatas = []
-
-        files.forEach((file, index) => {
-            let base64Cont = files[index].url.split(',')[1]
-            let imgType = files[index].file.type.split('/')[1]
-            let imgNewName = `good_id_${id}.${imgType}`
-
-            const imgData = {
-                'file-name': `e-commerce/images/${imgNewName}`,
-                'bucket': 'case',
-                'cont': base64Cont,
-                'public': true,
-                'format': 'base64'
-            }
-            imgDatas.push(imgData)
-        })
-
-        this.setState({
-            imgDatas,
-            files
-        })
-    }
-
-    uploadImg = () => {
-        let {imgDatas} = this.state
-
-        return imgDatas.map((imgData) => (
-            axios({
-                url: storeFile,
-                method: 'post',
-                data: imgData
-            })
-        ))
-    }
-
-    render() {
-        let {files, imgDatas, name, intro, stock, price, category_id, newGood} = this.state
-        let id = newGood ? idGen('goods') : this.state.id
-        return (
-            <List className="my-add-goods-list">
-                <InputItem onChange={(e) => {
-                    this.setState({name: e})
-                }} value={name} placeholder="请输入名称">名称</InputItem>
-                <Query query={gql(category_by_props)} variables={categoryFilter}>
-                    {
-                        ({loading, error, data}) => {
-                            if (loading) {
-                                return (
-                                    <div className="loading-center">
-                                        <ActivityIndicator text="Loading..." size="large"/>
-                                    </div>
-                                )
-                            }
-                            if (error) {
-                                return 'error!'
-                            }
-
-                            let categoryList = data.categorybyprops.map(category => {
-                                category.value = category.id
-                                category.label = category.text
-                                return category
-                            })
-
-                            return (
-                                <Picker data={categoryList}
-                                        cols={1}
-                                        value={this.state.category_id}
-                                        onChange={v => {
-                                            this.setState({category_id: v})
-                                        }}
-                                >
-                                    <List.Item arrow="horizontal">选择种类</List.Item>
-                                </Picker>
-                            )
-                        }
-                    }
-                </Query>
-                <InputItem onChange={(e) => {
-                    this.setState({intro: e})
-                }} value={intro} placeholder="请输入简介">简介</InputItem>
-                <InputItem onChange={(e) => {
-                    this.setState({price: e})
-                }} value={price} placeholder="请输入价格">价格</InputItem>
-                <Item extra={<Stepper onChange={(e) => {
-                    this.setState({stock: e})
-                }} value={stock} style={{width: '100%', minWidth: '100px'}} showNumber size="small"/>}>库存</Item>
-                <div className='list-others'>
-                    <div className='list-others-subtitle'>商品图片</div>
-                    <ImagePicker
-                        files={files}
-                        onChange={this.onChange(id)}
-                        onImageClick={(index, fs) => console.log(index, fs)}
-                        selectable={true}
-                        multiple={false}
-                    />
-                    {
-                        newGood ?
-                            <Mutation mutation={gql(create_product)} refetchQueries={[
-                                {query: gql(productbyprops), variables: {}},
-                                {query: gql(productbyprops), variables: {status: '1', recommend: 1}}
-                            ]}>
-                                {(createproduct, {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,
-                                        discountRate:100,
-                                        createdAt: moment().format('YYYY-MM-DD HH:mm:ss'),
-                                        updatedAt: ''
-                                    }
-                                    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
-                                                }
-                                                createproduct({variables})
-                                            })
-                                        }}>创建</Button>
-                                    )
-                                }}
-                            </Mutation>
-                            :
-                            <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 (
-                                        <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>
-                    }
-                </div>
-            </List>
-        )
-    }
-}
-
-class AllGoods extends Component {
-    constructor(props) {
-        super(props)
-        this.state = {
-            modal: false,
-            product: {}
-        }
-    }
-
-    controlModal = (bool) => () => {
-        this.setState({
-            modal: bool
-        })
-        if (!bool) {
-            this.setState({
-                product: {}
-            })
-        }
-    }
-
-    render() {
-        let {modal, product} = this.state
-        return (
-            <Query query={gql(productbyprops)} variables={{}}>
-                {
-                    ({loading, error, data}) => {
-                        if (loading) {
-                            return (
-                                <div className="loading-center">
-                                    <ActivityIndicator text="Loading..." size="large"/>
-                                </div>
-                            )
-                        }
-                        if (error) {
-                            return 'error!'
-                        }
-                        let products = data.productbyprops
-                        return (
-                            <div>
-                                <div className='all-goods'>
-                                    {
-                                        products.map(product => {
-                                            return (
-                                                <Row className='good-block' key={product.id}>
-                                                    <Col span={6}>
-                                                        <div className='good-image'
-                                                             style={{backgroundImage: `url(${product.img})`}}/>
-                                                    </Col>
-                                                    <Col span={11} offset={1}>{product.name}</Col>
-                                                    <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}}
-                                                        ]}>
-                                                            {(updateproduct, {loading, error}) => {
-                                                                if (loading)
-                                                                    return (
-                                                                        <div className="loading">
-                                                                            <div className="align">
-                                                                                <ActivityIndicator text="Loading..." size="large"/>
-                                                                            </div>
-                                                                        </div>
-                                                                    )
-                                                                if (error)
-                                                                    return 'error'
-                                                                let {id, recommend} = product
-                                                                let variables = {
-                                                                    id,
-                                                                    recommend: Number(!recommend),
-                                                                    updatedAt: moment().format('YYYY-MM-DD HH:mm:ss')
-                                                                }
-                                                                return (
-                                                                    <Icon type="like" className={classNames('not-like', {'like': recommend===1})} onClick={() => {
-                                                                        updateproduct({variables})
-                                                                    }}/>
-                                                                )
-                                                            }}
-                                                        </Mutation>
-                                                        <Icon type="form" onClick={() => {
-                                                            this.setState({modal: true, product})
-                                                        }}/>
-                                                    </Col>
-                                                </Row>
-                                            )
-                                        })
-                                    }
-                                </div>
-                                <Modal
-                                    popup
-                                    visible={modal}
-                                    onClose={this.controlModal(false)}
-                                    animationType="slide-up"
-                                    className='modify-goods-modal'
-                                >
-                                    <div className='close-popup' onClick={this.controlModal(false)}>X</div>
-                                    <div style={{paddingTop: 52}}>
-                                        <AddGoods good={product}/>
-                                    </div>
-                                </Modal>
-                            </div>
-                        )
-                    }
-                }
-            </Query>
-        )
-    }
-}
-
 class AllCategory extends Component {
     constructor(props) {
         super(props)
@@ -617,4 +284,566 @@ class AllCategoryInput extends Component {
 
 }
 
+class AllGoods extends Component {
+    constructor(props) {
+        super(props)
+        this.state = {
+            modal: false,
+            product: {}
+        }
+    }
+
+    controlModal = (bool) => () => {
+        this.setState({
+            modal: bool
+        })
+        if (!bool) {
+            this.setState({
+                product: {}
+            })
+        }
+    }
+
+    render() {
+        let {modal, product} = this.state
+        return (
+            <Query query={gql(productbyprops)} variables={{}}>
+                {
+                    ({loading, error, data}) => {
+                        if (loading) {
+                            return (
+                                <div className="loading-center">
+                                    <ActivityIndicator text="Loading..." size="large"/>
+                                </div>
+                            )
+                        }
+                        if (error) {
+                            return 'error!'
+                        }
+                        let products = data.productbyprops
+                        return (
+                            <div>
+                                <div className='all-goods'>
+                                    {
+                                        products.map(product => {
+                                            return (
+                                                <Row className='good-block' key={product.id}>
+                                                    <Col span={6}>
+                                                        <div className='good-image'
+                                                             style={{backgroundImage: `url(${product.img})`}}/>
+                                                    </Col>
+                                                    <Col span={11} offset={1}>{product.name}</Col>
+                                                    <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}
+                                                            }
+                                                        ]}>
+                                                            {(updateproduct, {loading, error}) => {
+                                                                if (loading)
+                                                                    return (
+                                                                        <div className="loading">
+                                                                            <div className="align">
+                                                                                <ActivityIndicator text="Loading..."
+                                                                                                   size="large"/>
+                                                                            </div>
+                                                                        </div>
+                                                                    )
+                                                                if (error)
+                                                                    return 'error'
+                                                                let {id, recommend} = product
+                                                                let variables = {
+                                                                    id,
+                                                                    recommend: Number(!recommend),
+                                                                    updatedAt: moment().format('YYYY-MM-DD HH:mm:ss')
+                                                                }
+                                                                return (
+                                                                    <Icon type="like"
+                                                                          className={classNames('not-like', {'like': recommend === 1})}
+                                                                          onClick={() => {
+                                                                              updateproduct({variables})
+                                                                          }}/>
+                                                                )
+                                                            }}
+                                                        </Mutation>
+                                                        <Icon type="form" onClick={() => {
+                                                            this.setState({modal: true, product})
+                                                        }}/>
+                                                    </Col>
+                                                </Row>
+                                            )
+                                        })
+                                    }
+                                </div>
+                                <Modal
+                                    popup
+                                    visible={modal}
+                                    onClose={this.controlModal(false)}
+                                    animationType="slide-up"
+                                    className='modify-goods-modal'
+                                >
+                                    <div className='close-popup' onClick={this.controlModal(false)}>X</div>
+                                    <div style={{paddingTop: 52}}>
+                                        <AddGoods good={product}/>
+                                    </div>
+                                </Modal>
+                            </div>
+                        )
+                    }
+                }
+            </Query>
+        )
+    }
+}
+
+class AddGoods extends Component {
+    constructor(props) {
+        super(props)
+        let state = {
+            files: [],
+            imgDatas: [],
+            modal: false
+        }
+        if (props.good === undefined) {
+            this.state = {
+                ...state,
+                name: '',
+                price: 0,
+                intro: '',
+                stock: 20,
+                category: '',
+                category_id: '',
+                newGood: true
+            }
+        } else {
+            // console.log(props.good)
+            let {name, price, intro, stock, id} = props.good
+            this.state = {
+                ...state,
+                id,
+                name,
+                price,
+                intro,
+                stock,
+                category: props.good.category_id.name,
+                category_id: [props.good.category_id.id],
+                newGood: false
+            }
+        }
+    }
+
+    onChange = (id) => (files, operationType) => {
+        let imgDatas = []
+
+        files.forEach((file, index) => {
+            let base64Cont = files[index].url.split(',')[1]
+            let imgType = files[index].file.type.split('/')[1]
+            let imgNewName = `good_id_${id}.${imgType}`
+
+            const imgData = {
+                'file-name': `e-commerce/images/${imgNewName}`,
+                'bucket': 'case',
+                'cont': base64Cont,
+                'public': true,
+                'format': 'base64'
+            }
+            imgDatas.push(imgData)
+        })
+
+        this.setState({
+            imgDatas,
+            files
+        })
+    }
+
+    uploadImg = () => {
+        let {imgDatas} = this.state
+
+        return imgDatas.map((imgData) => (
+            axios({
+                url: storeFile,
+                method: 'post',
+                data: imgData
+            })
+        ))
+    }
+
+    controlModal = (bool) => () => {
+        this.setState({
+            modal: bool
+        })
+    }
+
+    render() {
+        let {files, imgDatas, name, intro, stock, price, category_id, newGood, modal} = this.state
+        let id = newGood ? idGen('goods') : this.state.id
+        return (
+            <Query query={gql(specificationStock_by_props)} variables={{product_id: id}}>
+                {
+                    ({loading, error, data}) => {
+                        if (loading) {
+                            return (
+                                <div className="loading-center">
+                                    <ActivityIndicator text="Loading..." size="large"/>
+                                </div>
+                            )
+                        }
+                        if (error) {
+                            return 'error!'
+                        }
+
+                        let specs = data.specificationStockbyprops
+
+                        return (
+                            <div>
+                                <List className="my-add-goods-list">
+                                    <InputItem onChange={(e) => {
+                                        this.setState({name: e})
+                                    }} value={name} placeholder="请输入名称">名称</InputItem>
+                                    <Query query={gql(category_by_props)} variables={categoryFilter}>
+                                        {
+                                            ({loading, error, data}) => {
+                                                if (loading) {
+                                                    return (
+                                                        <div className="loading-center">
+                                                            <ActivityIndicator text="Loading..." size="large"/>
+                                                        </div>
+                                                    )
+                                                }
+                                                if (error) {
+                                                    return 'error!'
+                                                }
+
+                                                let categoryList = data.categorybyprops.map(category => {
+                                                    category.value = category.id
+                                                    category.label = category.text
+                                                    return category
+                                                })
+
+                                                return (
+                                                    <Picker data={categoryList}
+                                                            cols={1}
+                                                            value={this.state.category_id}
+                                                            onChange={v => {
+                                                                this.setState({category_id: v})
+                                                            }}
+                                                    >
+                                                        <List.Item arrow="horizontal">选择种类</List.Item>
+                                                    </Picker>
+                                                )
+                                            }
+                                        }
+                                    </Query>
+                                    <InputItem onChange={(e) => {
+                                        this.setState({intro: e})
+                                    }} value={intro} placeholder="请输入简介">简介</InputItem>
+                                    <InputItem onChange={(e) => {
+                                        this.setState({price: e})
+                                    }} value={price} placeholder="请输入价格">价格</InputItem>
+                                    <Item extra={<Stepper onChange={(e) => {
+                                        this.setState({stock: e})
+                                    }} value={stock} style={{width: '100%', minWidth: '100px'}} showNumber
+                                                          size="small"/>}>库存</Item>
+                                    <Item arrow="horizontal"
+                                          onClick={this.controlModal(true)}>{newGood ? '点击添加规格' : '点击修改规格'}</Item>
+                                    <div className='list-others'>
+                                        <div className='list-others-subtitle'>商品图片</div>
+                                        <ImagePicker
+                                            files={files}
+                                            onChange={this.onChange(id)}
+                                            onImageClick={(index, fs) => console.log(index, fs)}
+                                            selectable={true}
+                                            multiple={false}
+                                        />
+                                        {
+                                            newGood ?
+                                                <Mutation mutation={gql(create_product)} refetchQueries={[
+                                                    {query: gql(productbyprops), variables: {}},
+                                                    {query: gql(productbyprops), variables: {status: '1', recommend: 1}}
+                                                ]}>
+                                                    {(createproduct, {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,
+                                                            discountRate: 100,
+                                                            createdAt: moment().format('YYYY-MM-DD HH:mm:ss'),
+                                                            updatedAt: ''
+                                                        }
+                                                        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
+                                                                    }
+                                                                    createproduct({variables})
+                                                                })
+                                                            }}>创建</Button>
+                                                        )
+                                                    }}
+                                                </Mutation>
+                                                :
+                                                <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 (
+                                                                <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>
+                                                                )
+                                                            if (error)
+                                                                return 'error'
+                                                            return (
+                                                                <Button type="warning" size="small" inline
+                                                                        style={{marginLeft: 10}} onClick={() => {
+                                                                    deleteproduct({variables: {id}})
+                                                                }}>删除</Button>
+                                                            )
+                                                        }}
+                                                    </Mutation>
+                                                </div>
+                                        }
+                                    </div>
+                                </List>
+                                <Modal
+                                    popup
+                                    visible={modal}
+                                    onClose={this.controlModal(false)}
+                                    animationType="slide-up"
+                                    className='modify-goods-modal'
+                                >
+                                    <div className='close-popup' onClick={this.controlModal(false)}>X</div>
+                                    <div style={{paddingTop: 52}}>
+                                        <AddSpecStock specs={specs} productID={id}/>
+                                    </div>
+                                </Modal>
+                            </div>
+                        )
+                    }
+                }
+            </Query>
+        )
+    }
+}
+
+class AddSpecStock extends Component {
+    constructor(props) {
+        super(props)
+        this.state = {
+            list: true,
+            size: '',
+            color: '',
+            stock: 0,
+            id: ''
+        }
+    }
+
+    controlList = (bool, index) => () => {
+        let {specs} = this.props
+        this.setState({
+            list: bool,
+            index
+        })
+        if (index !== -1) {
+            let {size, color, stock, id} = specs[index]
+            this.setState({
+                size,
+                color,
+                stock,
+                id
+            })
+        } else {
+            this.setState({
+                size: '',
+                color: '',
+                stock: 20,
+                id: idGen('spec')
+            })
+        }
+    }
+
+    render() {
+        let {specs, productID} = this.props
+        let {list, size, color, stock, id, index} = this.state
+        return (
+            <div>
+                {
+                    list ?
+                        <List renderHeader={() => '规格设置'}>
+                            {
+                                specs.map((spec, index) => (
+                                    <Item key={spec.id} arrow="horizontal"
+                                          onClick={this.controlList(false, index)}>{spec.color} &nbsp; {spec.size}</Item>
+                                ))
+                            }
+                            <Item arrow="horizontal" onClick={this.controlList(false, -1)}>新增规格</Item>
+                        </List>
+                        :
+                        <List renderHeader={() => <div onClick={this.controlList(true, -1)}><Icon
+                            type="left"/>&nbsp;点击返回规格列表</div>}>
+                            <InputItem onChange={(e) => {
+                                this.setState({intro: e})
+                            }} value={size} placeholder="请输入简介">简介</InputItem>
+                            <InputItem onChange={(e) => {
+                                this.setState({price: e})
+                            }} value={color} placeholder="请输入价格">价格</InputItem>
+                            <Item extra={<Stepper onChange={(e) => {
+                                this.setState({stock: e})
+                            }} value={stock} style={{width: '100%', minWidth: '100px'}} showNumber
+                                                  size="small"/>}>库存</Item>
+                            <div className='list-others'>
+                                <div className='spec-button-group'>
+                                    {
+                                        index === -1?
+                                            <div>新增的按钮还没写</div>
+                                            :
+                                            <div>
+                                                <Mutation mutation={gql(update_specificationStock)} refetchQueries={[
+                                                    {query: gql(specificationStock_by_props), variables: {product_id: productID}}
+                                                ]}>
+                                                    {(updatespecificationStock, {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,
+                                                            color,
+                                                            size,
+                                                            stock,
+                                                            updatedAt: moment().format('YYYY-MM-DD HH:mm:ss')
+                                                        }
+                                                        return (
+                                                            <Button type="primary" size="small" inline
+                                                                    onClick={() => {
+                                                                        updatespecificationStock({variables: varObj})
+                                                                    }}>更新</Button>
+                                                        )
+                                                    }}
+                                                </Mutation>
+                                                <Mutation mutation={gql(delete_specificationStock)} refetchQueries={[
+                                                    {query: gql(specificationStock_by_props), variables: {product_id: productID}},
+                                                ]}>
+                                                    {(deletespecificationStock, {loading, error}) => {
+                                                        if (loading)
+                                                            return (
+                                                                <div className="loading">
+                                                                    <div className="align">
+                                                                        <ActivityIndicator text="Loading..." size="large"/>
+                                                                    </div>
+                                                                </div>
+                                                            )
+                                                        if (error)
+                                                            return 'error'
+                                                        return (
+                                                            <Button type="warning" size="small" inline
+                                                                    style={{marginLeft: 10}} onClick={() => {
+                                                                deletespecificationStock({variables: {id}})
+                                                            }}>删除</Button>
+                                                        )
+                                                    }}
+                                                </Mutation>
+                                                <div>更新删除的按钮还没测试</div>
+                                            </div>
+                                    }
+                                </div>
+                            </div>
+                        </List>
+                }
+            </div>
+        )
+    }
+}
+
 export default withRouter(Goods)

+ 1 - 1
src/pages/my/manage/index.js

@@ -29,7 +29,7 @@ class Manage extends Component {
                     <Route path="/my/manage/shop" component={Shop}/>
                     <Route path="/my/manage/goods" component={Goods}/>
                     <Route path="/my/manage/orders" component={Orders}/>
-                    <Route path="/my/manage/*" component={Orders}/>
+                    <Route path="/my/manage/*" component={Goods}/>
                 </Switch>
             </div>
         )

+ 52 - 1
src/utils/gql.js

@@ -128,6 +128,47 @@ const productAndSpec_by_id = `
         }
     }
 `
+const specificationStock_by_props = `
+    query specificationStockbyprops($product_id: ID) {
+        specificationStockbyprops: specificationStock_by_props(product_id: $product_id) {
+            updatedAt
+            color
+            createdAt
+            size
+            slideImg
+            status
+            id
+            detailImg
+            stock
+        }
+    }
+`
+
+const delete_specificationStock = `
+    mutation deletespecificationStock($id: ID) {
+        deletespecificationStock: delete_specificationStock(id: $id)
+    }
+
+`
+
+const update_specificationStock = `
+    mutation updatespecificationStock($id: ID, $updatedAt: String, $color: String, $size: String, $slideImg: String, $status: String, $detailImg: String, $stock: Int) {
+        updatespecificationStock: update_specificationStock(id: $id updatedAt: $updatedAt color: $color size: $size slideImg: $slideImg status: $status detailImg: $detailImg stock: $stock) {
+            result
+            specificationStock {
+                updatedAt
+                color
+                createdAt
+                size
+                slideImg
+                status
+                id
+                detailImg
+                stock
+            }
+        }
+    }
+`
 
 const create_userCart = `
     mutation createuserCart($id: ID!, $user_id: ID, $product_id: ID, $specificationStock_id: ID, $count: Int, $createdAt: String, $updatedAt: String) {
@@ -780,6 +821,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,
@@ -789,6 +836,9 @@ export {
     create_category,
     productbyprops,
     productAndSpec_by_id,
+    specificationStock_by_props,
+    update_specificationStock,
+    delete_specificationStock,
     create_userCart,
     cart_by_userid,
     update_userCart,
@@ -808,5 +858,6 @@ export {
     create_shop,
     update_shop,
     create_product,
-    update_product
+    update_product,
+    delete_product_by_id
 }