index.js 17.3 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';
4
import { is_weixin, http } 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
import {getCourses} from './../detail/actions';
10 11 12

const Item = List.Item;

13 14 15
@connect(state => ({
    user: state.user
}))
16 17 18 19
class _Scholarship extends Component {
    constructor(props) {
        super(props);
        this.state = {
wangshuo committed
20
            un_affirm: 0,
wangshuo committed
21
            account: 0.00,
22 23 24
            drawCashHtml: false,
            drawCashWechat: false,
            waitMoneyDetail: false,
wangshuo committed
25
            codeSrc: '',
26 27 28 29 30 31 32 33
            dataSource: new ListView.DataSource({
                rowHasChanged: (row1, row2) => row1 !== row2,
            }),
            page: 1,
            useBodyScroll: true,
            isLoading: false,
            showNoData: false,
            hasMore: true,
34
            tab: 0,
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 60 61 62 63 64
        }
        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
65 66 67 68 69 70 71 72 73
        if (is_weixin()) {
            this.setState({
                drawCashWechat: true
            });
        } else {
            this.setState({
                drawCashHtml: true
            });
        }
wangshuo committed
74 75 76 77
        const {hasError, data = {}} = this.props.user;
        if(hasError) {
            Toast.info("请登录提现!", undefined, undefined, false);
            return;
78
        }
wangshuo committed
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98

        http.get(`${API['base-api']}/wx/user_temporary_qrcode/${data.uid}`).then(res => {
            if(res.data.errno === 0) {
                if (is_weixin()) {
                    this.setState({
                        codeSrc: res.data.data.qr_image
                    });
                } else {
                    this.setState({
                        codeSrc: res.data.data.qr_image
                    });
                }
            }else{
                Toast.info(res.data.data.msg, 2);
            }

        });



99 100 101 102 103 104 105 106 107 108 109
    };
    // 去登陆
    toLogin = () => {
        this.props.history.push('/passport');
    };
    // 跳转到规则说明页
    showDocument = () => {
        this.props.history.push('/document');
    };
    // 保存二维码 TODO 失败
    saveImage = () => {
xuzhenghua committed
110

111 112 113
    };
    // 分销赚钱
    shareCategory = (course_id, money) => {
FE committed
114
        const {hasError, data = {}} = this.props.user;
115 116 117 118
        if(hasError) {
            Toast.info("请登录后分享!", undefined, undefined, false);
            return;
        }
zhanghaozhe committed
119
        http.post(`${API.home}/dist/createCode`, {course_id}).then((res) => {
120
            if (res.data.code === 200) {
FE committed
121
                this.props.history.push(`/shareposter?courseId=${course_id}&dist_first=${money}&uid=${data.uid}&dist_code=${res.data.data.code}`)
122 123
            }
        })
124 125 126 127 128 129 130 131 132 133
    };
    onEndReached = () => {
        if (this.state.isLoading || !this.state.hasMore) {
            return;
        }

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

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

zhanghaozhe committed
136
        if (this.tabIndex === 1) { apiUrl = `${API.home}/m/dist/commission_ranking_list` };
wangshuo committed
137 138

        http.get(apiUrl).then((res) => {
139 140 141 142
            if (res.data.code !== 200) {
                this.setState({ isLoading: false });
                return;
            }
wangshuo committed
143 144 145 146 147 148 149 150 151 152 153 154 155 156

            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;
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
            }

            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
180
        http.get(`${API.home}/m/user_account`).then(res=>{
wangshuo committed
181 182 183 184 185 186
            if(res.data.code === 200) {
                this.setState({
                    ...res.data.data
                });
            }
        });
187 188
        this.onEndReached();
    }
189 190 191

    toCourseDetail = (id) => {
        const { dispatch, history } = this.props;
192
        // dispatch(getCourses(id, () => {
193
            history.push(`/detail?id=${id}`)
194
        // }));
195 196
    }

197 198 199 200 201
    render() {
        const row = (
            rowData,
            rowID
        ) => {
202
            return (
xuzhenghua committed
203 204 205
                <CategoryItem
                    {...rowData}
                    key={rowID}
206 207 208 209
                    share={this.shareCategory}
                    toDetail={this.toCourseDetail}
                />
            );
210 211 212
        };

        const row1 = (
wangshuo committed
213
            rowData,
214 215
            rowID
        ) => {
wangshuo committed
216
            return <SortItem {...rowData} sortNum={this.rData.indexOf(rowData) + 1} key={rowID} />;
217 218 219 220 221 222 223 224
        };

        const separator = (sectionID, rowID) => (
            <div key={`${sectionID}-${rowID}`}>
                <WhiteSpace />
            </div>
        );
        const {
wangshuo committed
225
            un_affirm,
wangshuo committed
226
            account,
227 228 229 230 231
            drawCashHtml,
            drawCashWechat,
            waitMoneyDetail,
            codeSrc,
        } = this.state;
wangshuo committed
232
        const { hasError } = this.props.user;
233 234 235 236 237 238 239 240
        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>
xuzhenghua committed
241
                            <i className={'iconfont iconiconfront-22 tip-info'} onClick={this.showDocument}></i>
242 243 244 245 246 247 248 249 250 251
                        </Flex>
                    </WingBlank>
                    <WhiteSpace></WhiteSpace>
                    <WingBlank>
                        <span className={'common-ft-14'}>
                            可提现余额:
                        </span>
                    </WingBlank>
                    <WhiteSpace></WhiteSpace>
                    {
wangshuo committed
252
                        hasError ? (
253 254 255 256 257 258 259 260
                            <>
                                <WhiteSpace></WhiteSpace>
                                <Flex justify='center'>
                                    <div className={'login-check'} onClick={this.toLogin}>登录后查看</div>
                                </Flex>
                            </>
                        ) : (
                                <>
261
                                    <Flex justify='center' align='baseline' className={"drawCash"} >
wangshuo committed
262
                                        <span className={'common-ft-25'}>{account}</span>
263 264 265 266 267 268 269 270 271 272 273 274 275
                                        <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
276
                        hasError ? (null) : (
277 278 279 280 281 282 283 284 285 286
                            <>
                                <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
287
                                                <span className={'money'}>{un_affirm}</span>
288 289 290 291 292 293 294 295
                                            </Flex>
                                        </Item>
                                    </List>
                                </div>
                                <WhiteSpace></WhiteSpace>
                            </>
                        )
                    }
wangshuo committed
296
                    <div style={{ backgroundColor: '#FFF' }}>
297 298
                        <Tabs tabs={this.tabList}
                            initialPage={0}
xuzhenghua committed
299
                              swipeable={false}
300 301 302 303 304 305 306
                            // onChange={this.changeTab}
                            onChange={(tab, index) => {
                                this.tabIndex = index;
                                this.pageIndex = 1;
                                this.rData = [];
                                this.searchObject.page = 1;
                                this.setState(
wangshuo committed
307 308 309 310
                                    {
                                        isLoading: false,
                                        hasMore: true,
                                        dataSource: this.state.dataSource.cloneWithRows(this.rData),
311
                                        tab: index,
wangshuo committed
312 313 314 315
                                    },
                                    () => {
                                        this.onEndReached();
                                    }
316
                                );
wangshuo committed
317
                            }}
318
                        >
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
                        </Tabs>
                        {
                            this.state.tab === 0 ? (
                                <div style={{ marginTop: '15px', backgroundColor: '#FFF' }}>
                                    {
                                        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}
                                            />
                                        ) : (
335 336
                                            null
                                        )
337 338 339 340 341
                                    }

                                </div>
                            ) : null
                        }
342

343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
                        {
                            this.state.tab === 1 ? (
                                <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}
                                            />
                                        ) : (
359 360
                                            null
                                        )
361 362 363 364
                                    }
                                </div>
                            ) : null
                        }
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
                    </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>

387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
                <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>
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
                </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
426 427 428
                    <Flex style={{ fontSize: '14px', color: '#0099FF' }} justify='center'>
                        <span style={{color: "#333", marginRight: '10px'}}>待确认订单详情可</span>
                        <OpenApp className='toApp' text='前往APP查看'/>
429 430 431 432 433 434
                    </Flex>
                </Modal>
            </div>
        )
    }
}
435 436 437 438 439 440 441 442 443 444 445
// const mapStateToProps = (state) => {
//     return {
//         user: {
//             ...state.user
//         },
//     };
// };

// const mapDispatchToProps = (dispatch) => {
//     return {};
// };
wangshuo committed
446

447 448 449 450
// export const Scholarship = connect(
//     mapStateToProps,
//     mapDispatchToProps
// )(_Scholarship);
wangshuo committed
451

452
export default _Scholarship;