-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
196 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,16 @@ | ||
import * as actionTypes from '~constants/store'; | ||
|
||
export function update(data) { | ||
return { | ||
type: actionTypes.STORE_UPDATE, | ||
data | ||
}; | ||
}; | ||
export const update = data => ({ | ||
type: actionTypes.STORE_UPDATE, | ||
data | ||
}); | ||
|
||
export function add(item) { | ||
return { | ||
type: actionTypes.STORE_ADD, | ||
data: item | ||
}; | ||
}; | ||
export const add = item => ({ | ||
type: actionTypes.STORE_ADD, | ||
data: item | ||
}); | ||
|
||
export function rm(item) { | ||
return { | ||
type: actionTypes.STORE_RM, | ||
data: item | ||
}; | ||
}; | ||
export const rm = item => ({ | ||
type: actionTypes.STORE_RM, | ||
data: item | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
import * as actionTypes from '~constants/userinfo'; | ||
|
||
export function update(data) { | ||
return { | ||
type: actionTypes.USERINFO_UPDATE, | ||
data | ||
} | ||
}; | ||
export const update = data => ({ | ||
type: actionTypes.USERINFO_UPDATE, | ||
data | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,110 @@ | ||
import React from 'react'; | ||
import React, { PureComponent } from 'react'; | ||
import { getImage } from '~static/js/common'; | ||
import './style.scss'; | ||
|
||
// 无状态组件可以直接使用函数形式创建 | ||
const Item = props => { | ||
const data = props.data; | ||
|
||
return ( | ||
<div className="order-list-item"> | ||
<div className="item-img"> | ||
<img src={getImage(data.img)} alt="{data.title}" /> | ||
</div> | ||
<div className="item-content"> | ||
<span>商户: {data.title}</span> | ||
<span>数量: {data.count}</span> | ||
<span>价格: ¥{data.price}</span> | ||
</div> | ||
<div className="item-comment"> | ||
<button>评价</button> | ||
class Item extends PureComponent { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
commentState: 1, // 0未评价,1评价中,2已经评价 | ||
comment: '' // 评论的值 | ||
} | ||
}; | ||
render() { | ||
const data = this.props.data; | ||
return ( | ||
<div className="order-list-item"> | ||
<div className="item-img"> | ||
<img src={getImage(data.img)} alt="{data.title}" /> | ||
</div> | ||
<div className="item-content"> | ||
<span>商户: {data.title}</span> | ||
<span>数量: {data.count}</span> | ||
<span>价格: ¥{data.price}</span> | ||
</div> | ||
<div className="item-comment"> | ||
{ | ||
this.state.commentState === 0 | ||
? <button className="btn" onClick={this.showComment}>评价</button> | ||
: | ||
this.state.commentState === 1 | ||
// 评价中 | ||
? '' | ||
// 已经评价 | ||
: <button className="btn unseleted-btn">已评价</button> | ||
} | ||
</div> | ||
{ | ||
this.state.commentState === 1 | ||
? | ||
<div className="comment-text-container"> | ||
<textarea | ||
placeholder="请输入评价" | ||
onChange={this.textareaChange} | ||
value={this.state.comment} | ||
> | ||
</textarea> | ||
<button className="btn" onClick={this.submitHandle}>提交</button> | ||
<button className="btn unseleted-btn" onClick={this.hideComment}>取消</button> | ||
</div> | ||
: '' | ||
} | ||
</div> | ||
</div> | ||
); | ||
); | ||
}; | ||
|
||
componentDidMount() { | ||
// 更新评价状态 | ||
this.setState({ | ||
commentState: this.props.data.commentState | ||
}); | ||
}; | ||
|
||
// 将状态改为1,显示评价框 | ||
showComment = () => { | ||
this.setState({ | ||
commentState: 1 | ||
}); | ||
}; | ||
|
||
// 将状态改为0,隐藏评价框,清空值 | ||
hideComment = () => { | ||
this.setState({ | ||
commentState: 0, | ||
comment: '' | ||
}); | ||
}; | ||
|
||
// 处理提交 | ||
submitHandle = () => { | ||
const id = this.props.data.id; | ||
const submitComment = this.props.submitComment; | ||
const comment = this.state.comment; | ||
|
||
// 如果输入的值是空格则不提交 | ||
if (!comment.trim()) { | ||
return | ||
} | ||
|
||
// 提交评论内容 | ||
submitComment(id, comment, this.commentOk); | ||
}; | ||
|
||
// 上传后清空值,将状态改为3已评价 | ||
commentOk = () => { | ||
this.setState({ | ||
commentState: 2, | ||
comment: '' | ||
}); | ||
}; | ||
|
||
// 约束textarea | ||
textareaChange = e => { | ||
this.setState({ | ||
comment: e.target.value | ||
}); | ||
}; | ||
}; | ||
|
||
export default Item; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,20 @@ | ||
import get from '../get'; | ||
import post from '../post'; | ||
|
||
export function getOrderListData(username) { | ||
|
||
// 获取订单列表 | ||
export const getOrderListData = username => { | ||
const result = get(`/api/orderList/${username}`); | ||
|
||
return result; | ||
}; | ||
|
||
// 提交评价 | ||
export const postComment = (id, comment) => { | ||
const result = post('/api/submitComment', { | ||
id: id, | ||
comment: comment | ||
}); | ||
|
||
return result; | ||
}; |