index.js 16.7 KB
Newer Older
1
import React, { Component } from 'react';
2
import { Tabs, WhiteSpace, List, Flex, WingBlank, Modal, ListView, Toast } from 'antd-mobile';
3
import './scholarship.scss';
wangshuo committed
4
import { is_weixin, http, api } from "@/utils";
5 6 7
import CategoryItem from './CategoryItem/CategoryItem.js';
import SortItem from './SortItem/SortItem.js';
import { connect } from 'react-redux';
wangshuo committed
8
import OpenApp from '@/common/CallApp';
9 10 11 12 13 14 15

const Item = List.Item;

class _Scholarship extends Component {
    constructor(props) {
        super(props);
        this.state = {
wangshuo committed
16 17
            un_affirm: 0,
            affirm: 0.00,
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
            drawCashHtml: false,
            drawCashWechat: false,
            waitMoneyDetail: false,
            codeSrc: 'https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/tinypng-common/right_weixin.png',
            dataSource: new ListView.DataSource({
                rowHasChanged: (row1, row2) => row1 !== row2,
            }),
            page: 1,
            useBodyScroll: true,
            isLoading: false,
            showNoData: false,
            hasMore: true,
        }
        this.downImage = React.createRef();
        this.tabIndex = 0;
        this.searchObject = {};
        this.rData = [];
    }
    tabList = [
        { title: '课程列表', sub: '1' },
        { title: '分销榜单', sub: '2' },
    ];
    // 返回上一页
    goback = () => {
        this.props.history.push('/my');
    }
    // 关闭弹框
    closeModal = () => {
        this.setState({
            drawCashWechat: false,
            drawCashHtml: false,
            waitMoneyDetail: false,
        });
    };
    // 显示代收款提示modal
    showDetail = () => {
        this.setState({
            waitMoneyDetail: true,
        });
    }
    // 提现按钮 根据是否在微信环境中显示提示
    drawCash = () => {
wangshuo committed
60
        if (is_weixin()) {
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
            this.setState({
                drawCashWechat: true
            });
        } else {
            this.setState({
                drawCashHtml: true,
            });
        }
    };
    // 去登陆
    toLogin = () => {
        this.props.history.push('/passport');
    };
    // 跳转到规则说明页
    showDocument = () => {
        this.props.history.push('/document');
    };
    // 保存二维码 TODO 失败
    saveImage = () => {
80 81 82 83
        
    };
    // 分销赚钱
    shareCategory = (course_id, money) => {
xuzhenghua committed
84
        const {hasError, data = {}} = this.props.user;
85 86 87 88
        if(hasError) {
            Toast.info("请登录后分享!", undefined, undefined, false);
            return;
        }
zhanghaozhe committed
89
        http.post(`${API.home}/dist/createCode`, {course_id}).then((res) => {
90
            if (res.data.code === 200) {
xuzhenghua committed
91
                this.props.history.push(`/shareposter?courseId=${course_id}&dist_first=${money}&uid=${data.uid}&dist_code=${res.data.data.code}`)
92 93
            }
        })
94 95 96 97 98 99 100 101 102 103
    };
    onEndReached = () => {
        if (this.state.isLoading || !this.state.hasMore) {
            return;
        }

        this.setState({
            isLoading: true,
        });

zhanghaozhe committed
104
        let apiUrl = `${API.home}/m/dist/course_list`;
wangshuo committed
105

zhanghaozhe committed
106
        if (this.tabIndex === 1) { apiUrl = `${API.home}/m/dist/commission_ranking_list` };
wangshuo committed
107 108

        http.get(apiUrl).then((res) => {
109 110 111 112
            if (res.data.code !== 200) {
                this.setState({ isLoading: false });
                return;
            }
wangshuo committed
113 114 115 116 117 118 119 120 121 122 123 124 125 126

            let newData = [];
            if(this.tabIndex === 0) {
                if (!res.data.data.list || res.data.data.list.length === 0) {
                    this.setState({ isLoading: false, hasMore: false, showNoData: this.searchObject.page === 1 });
                    return;
                }
                newData = res.data.data.list;
            } else {
                if (!res.data.data || res.data.data.length === 0) {
                    this.setState({ isLoading: false, hasMore: false, showNoData: this.searchObject.page === 1 });
                    return;
                }
                newData = res.data.data;
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
            }

            this.searchObject.page++;

            this.rData = [...this.rData, ...newData];

            this.setState({
                dataSource: this.state.dataSource.cloneWithRows(this.rData),
                isLoading: false,
                // hasMore: newData.length >= 10,
                hasMore: false
            });
        })
        .catch(() => {
            this.setState({ isLoading: false });
        });
    }
    componentDidMount() {
        if (this.state.useBodyScroll) {
            document.body.style.overflow = 'auto';
        } else {
            document.body.style.overflow = 'hidden';
        }
zhanghaozhe committed
150
        http.get(`${API.home}/m/user_account`).then(res=>{
wangshuo committed
151 152 153 154 155 156
            if(res.data.code === 200) {
                this.setState({
                    ...res.data.data
                });
            }
        });
157 158 159 160 161 162 163
        this.onEndReached();
    }
    render() {
        const row = (
            rowData,
            rowID
        ) => {
164
            return <CategoryItem {...rowData} key={rowID} share={this.shareCategory}/>;
165 166 167
        };

        const row1 = (
wangshuo committed
168
            rowData,
169 170
            rowID
        ) => {
wangshuo committed
171
            return <SortItem {...rowData} sortNum={this.rData.indexOf(rowData) + 1} key={rowID} />;
172 173 174 175 176 177 178 179
        };

        const separator = (sectionID, rowID) => (
            <div key={`${sectionID}-${rowID}`}>
                <WhiteSpace />
            </div>
        );
        const {
wangshuo committed
180 181
            un_affirm,
            affirm,
182 183 184 185 186
            drawCashHtml,
            drawCashWechat,
            waitMoneyDetail,
            codeSrc,
        } = this.state;
wangshuo committed
187
        const { hasError } = this.props.user;
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
        return (
            <div className={'scholarship'}>
                <div className={'account-container'}>
                    <WhiteSpace></WhiteSpace>
                    <WingBlank>
                        <Flex justify='between'>
                            <i className={'iconfont iconiconfront-68 back'} onClick={this.goback}></i>
                            <span className={"common-ft-15"}>账户资金</span>
                            <i className={'iconfont iconaccounttip tip-info'} onClick={this.showDocument}></i>
                        </Flex>
                    </WingBlank>
                    <WhiteSpace></WhiteSpace>
                    <WingBlank>
                        <span className={'common-ft-14'}>
                            可提现余额:
                        </span>
                    </WingBlank>
                    <WhiteSpace></WhiteSpace>
                    {
wangshuo committed
207
                        hasError ? (
208 209 210 211 212 213 214 215 216
                            <>
                                <WhiteSpace></WhiteSpace>
                                <Flex justify='center'>
                                    <div className={'login-check'} onClick={this.toLogin}>登录后查看</div>
                                </Flex>
                            </>
                        ) : (
                                <>
                                    <Flex justify='center' align='baseline' style={{ height: '20px', lineHeight: '20px' }}>
wangshuo committed
217
                                        <span className={'common-ft-25'}>{affirm}</span>
218 219 220 221 222 223 224 225 226 227 228 229 230
                                        <span className={'common-ft-15'}></span>
                                    </Flex>
                                    <WhiteSpace></WhiteSpace>
                                    <Flex justify='center'>
                                        <div className={'draw-cash'} onClick={this.drawCash}>提现</div>
                                    </Flex>
                                </>
                            )
                    }
                </div>

                <div className={'over-am-list-item'} >
                    {
wangshuo committed
231
                        hasError ? (null) : (
232 233 234 235 236 237 238 239 240 241
                            <>
                                <div>
                                    <List>
                                        <Item
                                            arrow="horizontal"
                                            style={{ padding: '0 0 0 15px' }}
                                            onClick={this.showDetail}
                                        >
                                            <Flex direction='row' justify='between'>
                                                <span className={'common-ft-15'}>待确认金额</span>
wangshuo committed
242
                                                <span className={'money'}>{un_affirm}</span>
243 244 245 246 247 248 249 250
                                            </Flex>
                                        </Item>
                                    </List>
                                </div>
                                <WhiteSpace></WhiteSpace>
                            </>
                        )
                    }
wangshuo committed
251
                    <div style={{ backgroundColor: '#FFF' }}>
252 253 254 255 256 257 258 259 260
                        <Tabs tabs={this.tabList}
                            initialPage={0}
                            // onChange={this.changeTab}
                            onChange={(tab, index) => {
                                this.tabIndex = index;
                                this.pageIndex = 1;
                                this.rData = [];
                                this.searchObject.page = 1;
                                this.setState(
wangshuo committed
261 262 263 264 265 266 267 268
                                    {
                                        isLoading: false,
                                        hasMore: true,
                                        dataSource: this.state.dataSource.cloneWithRows(this.rData),
                                    },
                                    () => {
                                        this.onEndReached();
                                    }
269
                                );
wangshuo committed
270
                            }}
271
                        >
wangshuo committed
272
                            <div style={{ marginTop: '15px', backgroundColor: '#FFF' }}>
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
                                {
                                    this.state.dataSource._cachedRowCount !== 0 ? (
                                        <ListView
                                            useBodyScroll={this.state.useBodyScroll}
                                            dataSource={this.state.dataSource}
                                            renderRow={row}
                                            renderBodyComponent={() => <div />}
                                            onEndReached={this.onEndReached}
                                            pageSize={4}
                                            onEndReachedThreshold={100}
                                        />
                                    ) : (
                                            null
                                        )
                                }

                            </div>
                            <div>
                                <Flex justify='center' align='center' className={'runtimeList'}>榜单实时更新,仅显示前50</Flex>
                                {
                                    this.state.dataSource._cachedRowCount !== 0 ? (
                                        <ListView
                                            useBodyScroll={this.state.useBodyScroll}
                                            dataSource={this.state.dataSource}
                                            renderRow={row1}
                                            renderBodyComponent={() => <div />}
                                            onEndReached={this.onEndReached}
                                            pageSize={4}
                                            onEndReachedThreshold={100}
                                        />
                                    ) : (
                                            null
                                        )
                                }
                            </div>
                        </Tabs>
                    </div>
                </div>

                <Modal
                    visible={drawCashWechat}
                    transparent
                    maskClosable={true}
                    onClose={this.closeModal}
                    title="提现"
                    footer={[{ text: '确认', onPress: () => { this.closeModal() } }]}
                    className={'wechatModal'}
                    style={{ width: '300px' }}
                >
                    <p style={{ fontSize: '13px', color: '#666666' }}>
                        提现金额将通过微信零钱转账给您,识别下方二维码,关注【七月在线】服务号申请提现。
                    </p>
                    <WhiteSpace size='sm'></WhiteSpace>
                    <Flex justify='center'>
                        <img src={codeSrc} style={{ width: '90px', height: '90px', backgroundColor: '#666' }} alt="二维码" />
                    </Flex>
                </Modal>

331
                {/* <Modal
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
                    visible={drawCashHtml}
                    transparent
                    maskClosable={true}
                    onClose={this.closeModal}
                    title="提现"
                    footer={[
                        { text: '取消', onPress: () => { this.closeModal() } },
                        { text: '保存二维码', onPress: () => { this.saveImage() } }
                    ]}
                    style={{ width: '300px' }}
                >
                    <p style={{ fontSize: '13px', color: '#666666' }}>
                        提现金额将通过微信零钱转账给您,请微信扫码关注【七月在线】服务号后申请提现。
                    </p>
                    <WhiteSpace size='sm'></WhiteSpace>
                    <Flex justify='center'>
                        <img src={codeSrc} style={{ width: '90px', height: '90px' }} alt="二维码" />
                    </Flex>
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
                </Modal> */}
                <Modal
                    visible={drawCashHtml}
                    transparent
                    maskClosable={true}
                    onClose={this.closeModal}
                    style={{ width: '300px'}}
                >
                    <p style={{color: '#333333', fontSize: '16px', textAlign: 'center'}}>提现</p>
                    <WhiteSpace size='lg'></WhiteSpace>
                    <p style={{ fontSize: '12px', color: '#666666', textAlign: 'left' }}>
                        提现金额将通过微信零钱转账给您,请微信扫码关注【七月在线】服务号后申请提现。
                    </p>
                    <WhiteSpace size='lg'></WhiteSpace>
                    <Flex justify='center'>
                        <img src={codeSrc} style={{ width: '90px', height: '90px' }} alt="二维码" />
                    </Flex>
                    <WhiteSpace size='sm'></WhiteSpace>
                    <Flex justify='center' style={{color: '#333333', fontSize: '12px'}}>长按二维码保存到相册</Flex>
                    <i onClick={this.closeModal} className='iconfont iconiconfront-2' style={{zIndex: 99, fontSize: '40px', color: '#fff', position: "fixed", top: '70%', left: '50%', transform: 'translateX(-50%)'}}></i>
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
                </Modal>

                <Modal
                    visible={waitMoneyDetail}
                    transparent
                    maskClosable={true}
                    onClose={this.closeModal}
                    title="待确认金额"
                    footer={[
                        { text: '知道了', onPress: () => { this.closeModal() } }
                    ]}
                    style={{ width: '300px' }}
                >
                    <p style={{ fontSize: '13px', color: '#666666', textAlign: 'left', lineHeight: '20px' }}>
                        1.尚未开课的直播课程,用户购买后归属您的佣金会暂时存放在『待确认金额』中。
                    </p>
                    <p style={{ fontSize: '13px', color: '#666666', textAlign: 'left', lineHeight: '20px' }}>
                        2.该课程正式开课时,如果用户没有退款,对应的订单金额会自动转入您的账号余额,否则该佣金会自动收回。
                    </p>
                    <WhiteSpace></WhiteSpace>
wangshuo committed
390 391 392
                    <Flex style={{ fontSize: '14px', color: '#0099FF' }} justify='center'>
                        <span style={{color: "#333", marginRight: '10px'}}>待确认订单详情可</span>
                        <OpenApp className='toApp' text='前往APP查看'/>
393 394 395 396 397 398 399 400
                    </Flex>
                </Modal>
            </div>
        )
    }
}
const mapStateToProps = (state) => {
    return {
wangshuo committed
401 402 403
        user: {
            ...state.user
        },
404
    };
wangshuo committed
405 406 407
};

const mapDispatchToProps = (dispatch) => {
408
    return {};
wangshuo committed
409 410 411
};

export const Scholarship = connect(
412 413
    mapStateToProps,
    mapDispatchToProps
wangshuo committed
414
)(_Scholarship);