123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342 |
- import React from 'react';
- import { Form, Row, Col, Avatar, Button, Modal, Input, Upload } from 'antd';
- import './index.less';
- import Page from '@src/containers/Page';
- import Block from '@src/components/Block';
- import TableLayout from '@src/layouts/TableLayout';
- import ShowImage from '@src/components/ShowImage';
- import { formatDate, getMap, formatMoney, formatSeconds } from '@src/services/Tools';
- import { asyncSMessage, asyncForm, asyncDelConfirm } from '@src/services/AsyncTools';
- import { PcUrl, PrepareStatus, PrepareExaminationTime, ServiceKey } from '../../../../Constant';
- import { User } from '../../../stores/user';
- import { System } from '../../../stores/system';
- import { Exercise } from '../../../stores/exercise';
- const PrepareStatusMap = getMap(PrepareStatus, 'value', 'label');
- const PrepareExaminationTimeMap = getMap(PrepareExaminationTime, 'value', 'label');
- const ServiceKeyMap = getMap(ServiceKey, 'value', 'label');
- export default class extends Page {
- init() {
- this.categoryMap = {};
- this.moneyList = [{
- key: 'id',
- type: 'hidden',
- }, {
- key: 'money',
- type: 'number',
- name: '增加金额',
- min: 0,
- }];
- this.columns = [{
- title: '订单时间',
- dataIndex: 'createTime',
- render: (text) => {
- return formatDate(text, 'YYYY-MM-DD HH:mm:ss');
- },
- }, {
- title: '购买',
- dataIndex: 'service',
- render: (text, record) => {
- return `${ServiceKeyMap[text]} ${record.isUse ? '已使用' : ''}`;
- },
- }, {
- title: '消费金额',
- dataIndex: 'money',
- render: (text) => {
- return formatMoney(text);
- },
- }];
- Exercise.allStruct().then(result => {
- this.categoryMap = getMap(result.filter(row => row.level === 2).map(row => { row.title = `${row.titleZh}/${row.titleEn}`; row.value = row.id; return row; }), 'id', 'title');
- this.setState({ exercise: result });
- });
- }
- initData() {
- const { id } = this.params;
- let handler;
- if (id) {
- handler = User.get({ id });
- } else {
- handler = Promise.resolve();
- }
- handler
- .then(result => {
- this.setState({ data: result });
- this.refreshService(this.state.search.page, this.state.search.size);
- });
- }
- realAction() {
- this.open({ id: this.state.data.id }, 'real');
- }
- changeInfo(field, value) {
- const { real = {}, realEmpty = {} } = this.state;
- real[field] = value;
- if (value) realEmpty[field] = !value;
- this.setState({ real, realEmpty });
- }
- submitReal() {
- const { real = {}, realEmpty = {} } = this.state;
- if (!real.realIdentity || !real.realName) {
- realEmpty.realIdentity = !real.realIdentity;
- realEmpty.realName = !real.realName;
- this.setState({ realEmpty });
- return;
- }
- User.real(real).then(() => {
- this.close(true, 'real');
- });
- }
- addMoneyAction() {
- asyncForm('增加金额', this.moneyList, { id: this.state.data.id }, data => {
- return User.addMoney(data).then(() => {
- asyncSMessage('添加成功!');
- this.refresh();
- });
- });
- }
- frozenAction() {
- asyncDelConfirm('操作确认', '是否要封禁账户?封禁后账户无法使用网站', () => {
- return User.frozen({ id: this.state.data.id })
- .then(() => {
- asyncSMessage('操作成功!');
- this.refresh();
- });
- });
- }
- noFrozenAction() {
- asyncDelConfirm('操作确认', '是否要取消封禁账户?取消后账户可以使用网站', () => {
- return User.noFrozen({ id: this.state.data.id })
- .then(() => {
- asyncSMessage('操作成功!');
- this.refresh();
- });
- });
- }
- refreshService(p, size) {
- const { id } = this.params;
- const { page } = this.state;
- page.current = p || 1;
- page.pageSize = size || 20;
- this.setState({ page });
- User.listService({ userId: id, page: page.current, size: page.pageSize, order: 'createTime', direction: 'desc' })
- .then(result => {
- this.setTableData(result.list, result.total);
- });
- }
- renderBase() {
- const { data = {} } = this.state;
- return <Block>
- <h1>用户基本信息{data.isFrozen === 0 && <Button type='danger' onClick={() => {
- this.frozenAction();
- }}>封禁账户</Button>}
- {data.isFrozen === 1 && <Button type='danger' onClick={() => {
- this.noFrozenAction();
- }}>取消封禁</Button>}</h1>
- <Form>
- <div className="group">
- <h2>个人资料</h2>
- <Row>
- <Col span={12}>
- <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='用户ID'>
- {data.id}
- </Form.Item>
- </Col>
- <Col span={12}>
- <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='用户昵称'>
- {data.nickname}
- </Form.Item>
- </Col>
- <Col span={12}>
- <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='用户手机'>
- {data.mobile}
- </Form.Item>
- </Col>
- <Col span={12}>
- <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='用户微信'>
- {data.wechatUnionid ? '已绑定' : '未绑定'}
- </Form.Item>
- </Col>
- <Col span={12}>
- <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='邮箱'>
- {data.email ? '已绑定' : '未绑定'}
- </Form.Item>
- </Col>
- <Col span={12}>
- <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='注册时间'>
- {data.createTime && formatDate(data.createTime, 'YYYY-MM-DD HH:mm:ss')}
- </Form.Item>
- </Col>
- <Col span={12}>
- <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='头像'>
- <Avatar src={data.avatar} />
- </Form.Item>
- </Col>
- </Row>
- </div>
- <div className="group">
- <h2>实名认证{<Button onClick={() => {
- this.realAction();
- }}>人工认证</Button>}</h2>
- {data.realStatus > 0 && <Row>
- <Col span={12}>
- <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='身份证id'>
- {data.realIdentity}
- </Form.Item>
- </Col>
- <Col span={12}>
- <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='真实姓名'>
- {data.realName}
- </Form.Item>
- </Col>
- <Col span={12}>
- <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='地区'>
- {data.realAddress}
- </Form.Item>
- </Col>
- <Col span={12}>
- <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='身份证照片'>
- <ShowImage src={data.realPhotoFront} />
- <ShowImage src={data.realPhotoBack} />
- </Form.Item>
- </Col>
- </Row>}
- </div>
- <div className="group">
- <h2>备考信息</h2>
- {data.prepareTime && <Row>
- <Col span={12}>
- <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='身份'>
- {PrepareStatusMap[data.prepareStatus]}
- </Form.Item>
- </Col>
- <Col span={12}>
- <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='考试时间'>
- {PrepareExaminationTimeMap[data.prepareExaminationTime]}
- </Form.Item>
- </Col>
- <Col span={12}>
- <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='出分时间'>
- {data.prepareScoreTime ? formatDate(data.prepareScoreTime, 'YYYY-MM-DD HH:mm:ss') : ''}
- </Form.Item>
- </Col>
- <Col span={12}>
- <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='目标成绩'>
- {data.prepareGoal}
- </Form.Item>
- </Col>
- </Row>}
- </div>
- </Form>
- </Block>;
- }
- renderService() {
- const { data = {} } = this.state;
- return <Block>
- <h1>服务开通</h1>
- <div className="group">
- <h2>累计消费金额</h2>
- <p>{data.totalMoney}</p>
- <Button onClick={() => {
- this.addMoneyAction();
- }}>增加线下金额</Button>
- </div>
- <div className="group">
- <h2>已开通服务</h2>
- {(data.services || []).map(service => {
- return <p>{ServiceKeyMap[service.service]}: {formatDate(service.startTime, 'YYYY-MM-DD HH:mm:ss')} - {formatDate(service.expireTime, 'YYYY-MM-DD HH:mm:ss')}</p>;
- })}
- </div>
- <div className="group">
- <h2>消费记录</h2>
- <TableLayout
- columns={this.tableSort(this.columns)}
- list={this.state.list}
- pagination={this.state.page}
- loading={this.props.core.loading}
- onChange={(pagination) => this.refreshService(pagination.current, pagination.pageSize)}
- />
- </div>
- </Block>;
- }
- renderStudy() {
- const { data = {} } = this.state;
- return <Block>
- <h1>学习统计</h1>
- <div className="group">
- <h2>累计学习时间</h2>
- <p>{formatSeconds(data.totalTime)}</p>
- </div>
- <div className="group">
- <h2>学习数据</h2>
- <Button onClick={() => {
- User.locationUser(this.params.id, `${PcUrl}/my/data`);
- }}>查看</Button>
- </div>
- </Block>;
- }
- renderView() {
- const { real, realEmpty = {} } = this.state;
- return <div flex>
- {this.renderBase()}
- {this.renderService()}
- {this.renderStudy()}
- {real && <Modal visible closable title='实名认证' onCancel={() => {
- this.close(false, 'real');
- }} onOk={() => {
- this.submitReal();
- }}>
- <Form>
- <Form.Item labelCol={{ span: 5 }} validateStatus={realEmpty.realIdentity ? 'error' : ''} wrapperCol={{ span: 16 }} label='身份id'>
- <Input value={real.realIdentity || ''} placeholder='输入身份id' onChange={e => {
- this.changeInfo('realIdentity', e.target.value);
- }} />
- </Form.Item>
- <Form.Item labelCol={{ span: 5 }} validateStatus={realEmpty.realName ? 'error' : ''} wrapperCol={{ span: 16 }} label='真实姓名'>
- <Input value={real.realName || ''} placeholder='输入真实姓名' onChange={e => {
- this.changeInfo('realName', e.target.value);
- }} />
- </Form.Item>
- <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='地址'>
- <Input value={real.realAddress || ''} placeholder='输入地址' onChange={e => {
- this.changeInfo('realAddress', e.target.value);
- }} />
- </Form.Item>
- <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='正面照'><Upload
- showUploadList={false}
- beforeUpload={(file) => System.uploadImage(file).then((result) => {
- this.changeInfo('realPhotoFront', result.url);
- return Promise.reject();
- })}
- >
- <Button>上传正面{(real || {}).realPhotoFront ? '(已上传)' : ''}</Button>
- </Upload></Form.Item>
- <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='反面照'><Upload
- showUploadList={false}
- beforeUpload={(file) => System.uploadImage(file).then((result) => {
- this.changeInfo('realPhotoBack', result.url);
- return Promise.reject();
- })}
- >
- <Button>上传反面{(real || {}).realPhotoBack ? '(已上传)' : ''}</Button>
- </Upload></Form.Item>
- </Form>
- </Modal>}
- </div>;
- }
- }
|