index.js 16.8 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 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 60 61 62 63
            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
64 65 66 67 68 69 70 71 72
        if (is_weixin()) {
            this.setState({
                drawCashWechat: true
            });
        } else {
            this.setState({
                drawCashHtml: true
            });
        }
wangshuo committed
73 74 75 76
        const {hasError, data = {}} = this.props.user;
        if(hasError) {
            Toast.info("请登录提现!", undefined, undefined, false);
            return;
77
        }
wangshuo committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97

        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);
            }

        });



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

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

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

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

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

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

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

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

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

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

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

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

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

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

435 436 437 438
// export const Scholarship = connect(
//     mapStateToProps,
//     mapDispatchToProps
// )(_Scholarship);
wangshuo committed
439

440
export default _Scholarship;