|
|
@@ -349,8 +349,7 @@ class AllGoods extends Component {
|
|
|
return (
|
|
|
<div className="loading">
|
|
|
<div className="align">
|
|
|
- <ActivityIndicator text="加载中..."
|
|
|
- size="large"/>
|
|
|
+ <ActivityIndicator text="加载中..." size="large"/>
|
|
|
</div>
|
|
|
</div>
|
|
|
)
|
|
|
@@ -409,11 +408,13 @@ class AddGoods extends Component {
|
|
|
imgDatas: [],
|
|
|
modal: false
|
|
|
}
|
|
|
- if (props.good === undefined) {
|
|
|
+ // console.log("goods",props.good)
|
|
|
+ if (props.good === undefined) {
|
|
|
this.state = {
|
|
|
...state,
|
|
|
+ id:'',
|
|
|
name: '',
|
|
|
- price: 0,
|
|
|
+ price: null,
|
|
|
intro: '',
|
|
|
stock: 20,
|
|
|
category: '',
|
|
|
@@ -421,7 +422,6 @@ class AddGoods extends Component {
|
|
|
newGood: true
|
|
|
}
|
|
|
} else {
|
|
|
- // console.log(props.good)
|
|
|
let {name, price, intro, stock, id} = props.good
|
|
|
this.state = {
|
|
|
...state,
|
|
|
@@ -437,7 +437,7 @@ class AddGoods extends Component {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- onChange = (id) => (files, operationType) => {
|
|
|
+ onChange = (id) => (files, operationType) => {
|
|
|
let imgDatas = []
|
|
|
let openid = getCookie("openid")
|
|
|
|
|
|
@@ -481,235 +481,238 @@ class AddGoods extends Component {
|
|
|
}
|
|
|
|
|
|
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="加载中..." size="large"/>
|
|
|
- </div>
|
|
|
- )
|
|
|
- }
|
|
|
- if (error) {
|
|
|
- return 'error!'
|
|
|
- }
|
|
|
-
|
|
|
- let specs = data.specificationStockbyprops
|
|
|
-
|
|
|
- return (
|
|
|
- <div>
|
|
|
- <List className="my-add-goods-list">
|
|
|
- <InputItem onChange={(e) => {
|
|
|
- console.log("my-add-goods-list e",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="加载中..." size="large"/>
|
|
|
- </div>
|
|
|
- )
|
|
|
- }
|
|
|
- if (error) {
|
|
|
- return 'error!'
|
|
|
- }
|
|
|
-
|
|
|
- let categoryList = data.categorybyprops.map(category => {
|
|
|
- category.value = category.id
|
|
|
- category.label = category.text
|
|
|
- return category
|
|
|
- })
|
|
|
+ let {files, imgDatas, name, intro, stock, price, category_id, newGood, modal, id} = this.state
|
|
|
|
|
|
- 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="加载中..."
|
|
|
- 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="加载中..."
|
|
|
- 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="加载中..."
|
|
|
- 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>
|
|
|
+ return (
|
|
|
+ <div>
|
|
|
+ <List className="my-add-goods-list">
|
|
|
+ <Query query={gql(category_by_props)} variables={categoryFilter}>
|
|
|
+ {
|
|
|
+ ({loading, error, data}) => {
|
|
|
+ if (loading) {
|
|
|
+ return (
|
|
|
+ <div className="loading-center">
|
|
|
+ <ActivityIndicator text="加载中..." 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({name: e})
|
|
|
+ }} value={name} placeholder="请输入名称">名称</InputItem>
|
|
|
+ <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="加载中..." size="large"/>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+ if (error)
|
|
|
+ return 'error'
|
|
|
+ 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 productId = id ? id : idGen('goods')
|
|
|
+ this.setState({id:productId})
|
|
|
+ // console.log("goods id",id)
|
|
|
+ let varObj = {
|
|
|
+ id: productId,
|
|
|
+ unit: '1件',
|
|
|
+ status: '1',
|
|
|
+ recommend: 1,
|
|
|
+ category_id: category_id[0],
|
|
|
+ name,
|
|
|
+ stock,
|
|
|
+ intro,
|
|
|
+ price: parseFloat(price),
|
|
|
+ discountRate: 100,
|
|
|
+ createdAt: moment().format('YYYY-MM-DD HH:mm:ss'),
|
|
|
+ updatedAt: ''
|
|
|
+ }
|
|
|
+ let variables = {...varObj}
|
|
|
+ if (imgDatas.length !== 0) {
|
|
|
+ variables.img = img
|
|
|
+ }
|
|
|
+ createproduct({variables}).then((data)=>{
|
|
|
+ // console.log("createproduct data",data)
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }}>创建</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="加载中..." size="large"/>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+ if (error)
|
|
|
+ return 'error'
|
|
|
+ let varObj = {
|
|
|
+ id,
|
|
|
+ unit: '1件',
|
|
|
+ status: '1',
|
|
|
+ recommend: 1,
|
|
|
+ category_id: category_id[0],
|
|
|
+ name,
|
|
|
+ stock,
|
|
|
+ intro,
|
|
|
+ price: parseFloat(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="加载中..." 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>
|
|
|
+ <Query query={gql(specificationStock_by_props)} variables={{product_id: id}}>
|
|
|
+ {
|
|
|
+ ({loading, error, data}) => {
|
|
|
+ if (loading) {
|
|
|
+ return (
|
|
|
+ <div className="loading-center">
|
|
|
+ <ActivityIndicator text="加载中5..." size="large"/>
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+ }
|
|
|
+ if (error) {
|
|
|
+ return 'error!'
|
|
|
+ }
|
|
|
+
|
|
|
+ let specs = data.specificationStockbyprops
|
|
|
+
|
|
|
+ return (
|
|
|
+ <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>
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ </Query>
|
|
|
+ </div>
|
|
|
)
|
|
|
}
|
|
|
}
|
|
|
@@ -827,8 +830,7 @@ class AddSpecStock extends Component {
|
|
|
return (
|
|
|
<div className="loading">
|
|
|
<div className="align">
|
|
|
- <ActivityIndicator text="加载中..."
|
|
|
- size="large"/>
|
|
|
+ <ActivityIndicator text="加载中..." size="large"/>
|
|
|
</div>
|
|
|
</div>
|
|
|
)
|