Commit 939e928a by wangshuo

公共方法提取

parent 533c5f55
......@@ -173,12 +173,8 @@ class Order extends Component {
info: !prevState.info
}));
};
componentDidMount() {
let _this = this;
console.log(this.props.location.state);
if(this.props.location.state && this.props.location.state.type === 1) {
http.get(`${API['base-api']}/m/order/preorder?type=1`).then((res) => {
if(res.data.errno === 200) {
// 公共方法 存储数据
publicGetData = (res) => {
const { course, total, user_account, user_info, discount } = res.data.data;
this.cacheObj = {
perfect: user_info,
......@@ -194,6 +190,9 @@ class Order extends Component {
total,
discount,
});
};
// 公共方法 本地存储
publicLocalStorage = () => {
if(this.props.history.action === 'PUSH') {
sessionStorage.removeItem('orderUseCacheObj');
} else{
......@@ -205,40 +204,24 @@ class Order extends Component {
this.computedMoneyByCache();
}
}
};
componentDidMount() {
let _this = this;
console.log(this.props.location.state);
if(this.props.location.state && this.props.location.state.type === 1) {
http.get(`${API['base-api']}/m/order/preorder?type=1`).then((res) => {
if(res.data.errno === 200) {
this.publicGetData(res);
this.publicLocalStorage();
}else{
Toast.info(res.data.msg, 2);
}
})
} else if (this.props.location.state && this.props.location.state.simple === 1) {
http.get(`${API.home}/m/order/preorder`).then(res => {
console.log(res);
if(res.data.code === 200) {
const { course, total, user_account, user_info, discount } = res.data.data;
this.cacheObj = {
perfect: user_info,
orderList: course,
user_account,
total,
discount,
};
this.setState({
perfect: user_info,
orderList: course,
user_account,
total,
discount,
});
if(this.props.history.action === 'PUSH') {
sessionStorage.removeItem('orderUseCacheObj');
} else{
const cacheObj = sessionStorage.getItem('orderUseCacheObj');
if(cacheObj !== null) {
this.setState({
useBalance: true
});
this.computedMoneyByCache();
}
}
this.publicGetData(res);
this.publicLocalStorage();
}else{
Toast.info(res.data.msg, 2);
}
......@@ -254,54 +237,17 @@ class Order extends Component {
return;
}
const { user_info, user_account, discount } = preorder.data.data;
this.cacheObj = {
perfect: user_info,
orderList: orderList,
user_account,
total: preorder.data.data.total,
discount,
};
_this.setState({
perfect: user_info,
orderList: orderList,
user_account,
total: preorder.data.data.total,
discount,
});
this.publicGetData(preorder);
})
}else{
http.get(`${API['base-api']}/m/order/preorder`).then((res) => {
console.log(res.data);
if (res.data.errno !== 200) {
Toast.info(res.data.msg, 2);
return;
}
const { course, total, user_account, user_info, discount } = res.data.data;
this.cacheObj = {
perfect: user_info,
orderList: course,
user_account,
total,
discount,
};
this.setState({
perfect: user_info,
orderList: course,
user_account,
total,
discount,
});
if(this.props.history.action === 'PUSH') {
sessionStorage.removeItem('orderUseCacheObj');
} else{
const cacheObj = sessionStorage.getItem('orderUseCacheObj');
if(cacheObj !== null) {
this.setState({
useBalance: true
});
this.computedMoneyByCache();
}
}
this.publicGetData(res);
this.publicLocalStorage();
})
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment