forked from Gitlink/forgeplus-react
新增:修改赞助关系
This commit is contained in:
parent
fc55df4d30
commit
ccace2a879
|
@ -1,6 +1,6 @@
|
|||
import React, { Component } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { Avatar, Tag, Button, Spin, Input, Divider, Form, Radio, Alert, message} from "antd";
|
||||
import { Avatar, Tag, Button, Spin, Input, Divider, Form, Radio, Alert, message, Modal} from "antd";
|
||||
import { Route, Switch } from "react-router-dom";
|
||||
import { withRouter } from "react-router";
|
||||
|
||||
|
@ -24,6 +24,7 @@ import { submitUserCode } from "../../redux/actions/ojForUser";
|
|||
const tempData = {amount:100, description: "如果您更加慷慨的话就选择这个"};
|
||||
const tempBalance = 999;
|
||||
const FormItem = Form.Item;
|
||||
const { confirm } = Modal;
|
||||
|
||||
const SponsorConfirmation = Form.create()(
|
||||
class extends Component{
|
||||
|
@ -34,8 +35,11 @@ class extends Component{
|
|||
isSpin: false,
|
||||
user: undefined,
|
||||
tier: undefined,
|
||||
single: true,
|
||||
single: false,
|
||||
balance: undefined,
|
||||
is_sponsoring: false,
|
||||
visible: false,
|
||||
sponsorship_id: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -84,7 +88,9 @@ class extends Component{
|
|||
.get(url)
|
||||
.then((result) => {
|
||||
this.setState({
|
||||
tier: result.data,
|
||||
tier: result.data.tier,
|
||||
is_sponsoring: result.data.is_sponsoring,
|
||||
sponsorship_id: result.data.sponsorship_id,
|
||||
})
|
||||
})
|
||||
.catch((error) => {
|
||||
|
@ -130,6 +136,24 @@ class extends Component{
|
|||
})
|
||||
}
|
||||
|
||||
updateSponsorship = () => {
|
||||
const value = this.props.form.getFieldsValue();
|
||||
const {tier, user, sponsorship_id} = this.state;
|
||||
const {current_user} = this.props;
|
||||
let url = `/sponsorships/${sponsorship_id}.json`;
|
||||
axios.put(url, {
|
||||
amount: tier.tier,
|
||||
visible: value.visible
|
||||
})
|
||||
.then((result) => {
|
||||
if (result && result.data.status == 1)
|
||||
message.success(result.data.message);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
})
|
||||
}
|
||||
|
||||
submit = () => {
|
||||
const value = this.props.form.getFieldsValue();
|
||||
const {tier, user} = this.state;
|
||||
|
@ -143,7 +167,7 @@ class extends Component{
|
|||
developer_id: user.user_id,
|
||||
})
|
||||
.then((result) => {
|
||||
console.log(result);
|
||||
// console.log(result);
|
||||
if (result && result.data.status == 1)
|
||||
message.success(result.data.message);
|
||||
})
|
||||
|
@ -152,17 +176,48 @@ class extends Component{
|
|||
})
|
||||
}
|
||||
|
||||
handleCancel = e => {
|
||||
this.setState({
|
||||
visible: false,
|
||||
});
|
||||
};
|
||||
|
||||
showModal = () => {
|
||||
this.setState({
|
||||
visible: true,
|
||||
});
|
||||
};
|
||||
|
||||
showConfirm = () => {
|
||||
const {user} = this.state;
|
||||
const fun = this.state.is_sponsoring?this.updateSponsorship:this.submit;
|
||||
let text = this.state.is_sponsoring?`确认要修改对 ${user && user.username} 的赞助吗?若修改金额,将在下次自动扣款生效。`
|
||||
:`确认要赞助 ${user && user.username} 吗?`;
|
||||
confirm({
|
||||
// title: '确认赞助',
|
||||
// icon: <ExclamationCircleOutlined />,
|
||||
content: text,
|
||||
onOk() {
|
||||
fun()
|
||||
},
|
||||
onCancel() {
|
||||
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
render(){
|
||||
const {tier_id, username} = this.props.match.params;
|
||||
const {current_user, form} = this.props;
|
||||
const {user, isSpin, tier, balance} = this.state;
|
||||
const {user, isSpin, tier, balance, is_sponsoring, single} = this.state;
|
||||
const {getFieldDecorator} = form;
|
||||
|
||||
const current_username = current_user && current_user.username;
|
||||
const alert_text = this.state.single? `您选择了单次付费,本次扣除${tier && tier.tier}硬币`
|
||||
:`您选择了按月付费,每月20日将扣除${tier && tier.tier}硬币`;
|
||||
|
||||
// console.log("user", user)
|
||||
// console.log("sponsoring", is_sponsoring);
|
||||
// console.log("tier: ", tier);
|
||||
// console.log("current user", current_user);
|
||||
|
||||
const radioStyle = {
|
||||
|
@ -208,9 +263,9 @@ class extends Component{
|
|||
rules: [{
|
||||
required: true
|
||||
}],
|
||||
initialValue: true
|
||||
initialValue: single
|
||||
})(
|
||||
<Radio.Group onChange={(e) => this.changeSingle(e)}>
|
||||
<Radio.Group onChange={(e) => this.changeSingle(e)} disabled={is_sponsoring}>
|
||||
<Radio style={radioStyle} value={true}>单次付费</Radio>
|
||||
<Radio style={radioStyle} value={false}>按月支付</Radio>
|
||||
</Radio.Group>
|
||||
|
@ -249,7 +304,7 @@ class extends Component{
|
|||
</Radio.Group>
|
||||
)}
|
||||
</FormItem>
|
||||
<Button type='primary' onClick={() => this.submit()}>赞助{user && user.username}</Button>
|
||||
<Button type='primary' className="confirm-btn" onClick={() => this.showConfirm()}>赞助 {user && user.username}</Button>
|
||||
</Form>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -67,4 +67,14 @@
|
|||
|
||||
.mr10{
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.confirm-btn{
|
||||
width: 100%;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.sponsor-item-btn{
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
|
@ -189,10 +189,10 @@ class Infos extends Component {
|
|||
|
||||
<div>
|
||||
{user && current_user && user.login === current_user.login && (
|
||||
<div className="user-info-star-button ">
|
||||
<div className="user-info-star-button">
|
||||
<Button
|
||||
block
|
||||
className="text-button-grey"
|
||||
className="text-button-grey mr5"
|
||||
href={`${
|
||||
mygetHelmetapi &&mygetHelmetapi.new_course&&
|
||||
mygetHelmetapi.new_course.edit_account
|
||||
|
@ -200,7 +200,7 @@ class Infos extends Component {
|
|||
target="_blank"
|
||||
>
|
||||
{" "}
|
||||
<i className="iconfont icon-shezhi4 font-15 mr5"></i>
|
||||
<i className="iconfont icon-shezhi4 font-15"></i>
|
||||
修改资料
|
||||
</Button>
|
||||
<Button
|
||||
|
@ -225,7 +225,7 @@ class Infos extends Component {
|
|||
/>
|
||||
<Button
|
||||
block
|
||||
className="text-button-grey"
|
||||
className="text-button-grey ml-5"
|
||||
href={`/sponsor/${user && user.login}`}
|
||||
>
|
||||
赞助
|
||||
|
|
|
@ -28,10 +28,15 @@
|
|||
.mt-n15{margin-top: -15px;}
|
||||
.position-relative{position: relative;}
|
||||
.mr-5{margin-right: 5px;}
|
||||
.mt-5{margin-top: 5px;}
|
||||
.ml-5{margin-left: 5px;}
|
||||
a.text-button-grey{
|
||||
color: rgba(0, 0, 0, 0.65)
|
||||
}
|
||||
.user-info-star-button{margin: 20px 50px 0 50px}
|
||||
.user-info-star-button{
|
||||
display: flex;
|
||||
margin: 20px 20px 0 20px
|
||||
}
|
||||
.list-l-p{
|
||||
width: 100%;
|
||||
display: -ms-flexbox;
|
||||
|
|
|
@ -212,6 +212,7 @@ class SponsorManagement extends Component{
|
|||
current_user={current_user}
|
||||
users={displayList}
|
||||
rerender={this.get_sponsors}
|
||||
history={this.props.history}
|
||||
></SponsorList>
|
||||
:
|
||||
<Nodata _html={`暂时没有数据`} />
|
||||
|
|
|
@ -28,10 +28,15 @@ class SponsorList extends Component {
|
|||
})
|
||||
}
|
||||
|
||||
to_sponsor_page = (item, key, e) => {
|
||||
this.props.history.push(`/sponsor/${item.login}`);
|
||||
}
|
||||
|
||||
renderList = (users, userClass, current_user) => {
|
||||
|
||||
if (users && users.length > 0) {
|
||||
return users.map((item, key) => {
|
||||
// console.log(item);
|
||||
return (
|
||||
<div className="p-r-Item" key={key}>
|
||||
{/* <div className="mr10">
|
||||
|
@ -62,6 +67,7 @@ class SponsorList extends Component {
|
|||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="sponsor-item-btn">
|
||||
{item.stop_time? "":(
|
||||
<Popconfirm
|
||||
title="确认终止?"
|
||||
|
@ -71,7 +77,12 @@ class SponsorList extends Component {
|
|||
cancelText="否"
|
||||
>
|
||||
<Button >终止赞助关系</Button>
|
||||
</Popconfirm>)}
|
||||
</Popconfirm>
|
||||
)}
|
||||
{!item.stop_time && item.sponsor_id==current_user.user_id? (
|
||||
<Button className="mt5" onClick={e => this.to_sponsor_page(item, key, e)}>修改赞助</Button>
|
||||
):""}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue