Commit 939e928a by wangshuo

公共方法提取

parent 533c5f55
......@@ -173,137 +173,83 @@ class Order extends Component {
info: !prevState.info
}));
};
// 公共方法 存储数据
publicGetData = (res) => {
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,
});
};
// 公共方法 本地存储
publicLocalStorage = () => {
if(this.props.history.action === 'PUSH') {
sessionStorage.removeItem('orderUseCacheObj');
} else{
const cacheObj = sessionStorage.getItem('orderUseCacheObj');
if(cacheObj !== null) {
this.setState({
useBalance: true
});
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) {
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);
}
})
} 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);
}
});
} else {
if(getParam('id')) {
Promise.all([http.get(`${API.home}/m/del_cart_order/${getParam('id')}`), http.get(`${API.home}/m/order/preorder`)]).then(res => {
console.log(res);
let preorder = res[1],
orderList = preorder.data.data.course;
if(getParam('id')) {
Promise.all([http.get(`${API.home}/m/del_cart_order/${getParam('id')}`), http.get(`${API.home}/m/order/preorder`)]).then(res => {
console.log(res);
let preorder = res[1],
orderList = preorder.data.data.course;
if(preorder.data.code !== 200) {
Toast.info(preorder.data.msg, 2);
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,
});
})
}else{
http.get(`${API['base-api']}/m/order/preorder`).then((res) => {
console.log(res.data);
if (res.data.errno !== 200) {
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(preorder);
})
}else{
http.get(`${API['base-api']}/m/order/preorder`).then((res) => {
if (res.data.errno !== 200) {
Toast.info(res.data.msg, 2);
return;
}
this.publicGetData(res);
this.publicLocalStorage();
})
}
})
}
}
};
render() {
......
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