page.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. import React from 'react';
  2. import { Form, Row, Col, Avatar, Button, Modal, Input, Upload } from 'antd';
  3. import './index.less';
  4. import Page from '@src/containers/Page';
  5. import Block from '@src/components/Block';
  6. import TableLayout from '@src/layouts/TableLayout';
  7. import ShowImage from '@src/components/ShowImage';
  8. import { formatDate, getMap, formatMoney, formatSeconds } from '@src/services/Tools';
  9. import { asyncSMessage, asyncForm, asyncDelConfirm } from '@src/services/AsyncTools';
  10. import { PcUrl, PrepareStatus, PrepareExaminationTime, ServiceKey } from '../../../../Constant';
  11. import { User } from '../../../stores/user';
  12. import { System } from '../../../stores/system';
  13. import { Exercise } from '../../../stores/exercise';
  14. const PrepareStatusMap = getMap(PrepareStatus, 'value', 'label');
  15. const PrepareExaminationTimeMap = getMap(PrepareExaminationTime, 'value', 'label');
  16. const ServiceKeyMap = getMap(ServiceKey, 'value', 'label');
  17. export default class extends Page {
  18. init() {
  19. this.categoryMap = {};
  20. this.moneyList = [{
  21. key: 'id',
  22. type: 'hidden',
  23. }, {
  24. key: 'money',
  25. type: 'number',
  26. name: '增加金额',
  27. min: 0,
  28. }];
  29. this.columns = [{
  30. title: '订单时间',
  31. dataIndex: 'createTime',
  32. render: (text) => {
  33. return formatDate(text, 'YYYY-MM-DD HH:mm:ss');
  34. },
  35. }, {
  36. title: '购买',
  37. dataIndex: 'service',
  38. render: (text, record) => {
  39. return `${ServiceKeyMap[text]} ${record.isUse ? '已使用' : ''}`;
  40. },
  41. }, {
  42. title: '消费金额',
  43. dataIndex: 'money',
  44. render: (text) => {
  45. return formatMoney(text);
  46. },
  47. }];
  48. Exercise.allStruct().then(result => {
  49. 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');
  50. this.setState({ exercise: result });
  51. });
  52. }
  53. initData() {
  54. const { id } = this.params;
  55. let handler;
  56. if (id) {
  57. handler = User.get({ id });
  58. } else {
  59. handler = Promise.resolve();
  60. }
  61. handler
  62. .then(result => {
  63. this.setState({ data: result });
  64. this.refreshService(this.state.search.page, this.state.search.size);
  65. });
  66. }
  67. realAction() {
  68. this.open({ id: this.state.data.id }, 'real');
  69. }
  70. changeInfo(field, value) {
  71. const { real = {}, realEmpty = {} } = this.state;
  72. real[field] = value;
  73. if (value) realEmpty[field] = !value;
  74. this.setState({ real, realEmpty });
  75. }
  76. submitReal() {
  77. const { real = {}, realEmpty = {} } = this.state;
  78. if (!real.realIdentity || !real.realName) {
  79. realEmpty.realIdentity = !real.realIdentity;
  80. realEmpty.realName = !real.realName;
  81. this.setState({ realEmpty });
  82. return;
  83. }
  84. User.real(real).then(() => {
  85. this.close(true, 'real');
  86. });
  87. }
  88. addMoneyAction() {
  89. asyncForm('增加金额', this.moneyList, { id: this.state.data.id }, data => {
  90. return User.addMoney(data).then(() => {
  91. asyncSMessage('添加成功!');
  92. this.refresh();
  93. });
  94. });
  95. }
  96. frozenAction() {
  97. asyncDelConfirm('操作确认', '是否要封禁账户?封禁后账户无法使用网站', () => {
  98. return User.frozen({ id: this.state.data.id })
  99. .then(() => {
  100. asyncSMessage('操作成功!');
  101. this.refresh();
  102. });
  103. });
  104. }
  105. noFrozenAction() {
  106. asyncDelConfirm('操作确认', '是否要取消封禁账户?取消后账户可以使用网站', () => {
  107. return User.noFrozen({ id: this.state.data.id })
  108. .then(() => {
  109. asyncSMessage('操作成功!');
  110. this.refresh();
  111. });
  112. });
  113. }
  114. refreshService(p, size) {
  115. const { id } = this.params;
  116. const { page } = this.state;
  117. page.current = p || 1;
  118. page.pageSize = size || 20;
  119. this.setState({ page });
  120. User.listService({ userId: id, page: page.current, size: page.pageSize, order: 'createTime', direction: 'desc' })
  121. .then(result => {
  122. this.setTableData(result.list, result.total);
  123. });
  124. }
  125. renderBase() {
  126. const { data = {} } = this.state;
  127. return <Block>
  128. <h1>用户基本信息{data.isFrozen === 0 && <Button type='danger' onClick={() => {
  129. this.frozenAction();
  130. }}>封禁账户</Button>}
  131. {data.isFrozen === 1 && <Button type='danger' onClick={() => {
  132. this.noFrozenAction();
  133. }}>取消封禁</Button>}</h1>
  134. <Form>
  135. <div className="group">
  136. <h2>个人资料</h2>
  137. <Row>
  138. <Col span={12}>
  139. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='用户ID'>
  140. {data.id}
  141. </Form.Item>
  142. </Col>
  143. <Col span={12}>
  144. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='用户昵称'>
  145. {data.nickname}
  146. </Form.Item>
  147. </Col>
  148. <Col span={12}>
  149. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='用户手机'>
  150. {data.mobile}
  151. </Form.Item>
  152. </Col>
  153. <Col span={12}>
  154. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='用户微信'>
  155. {data.wechatUnionid ? '已绑定' : '未绑定'}
  156. </Form.Item>
  157. </Col>
  158. <Col span={12}>
  159. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='邮箱'>
  160. {data.email ? '已绑定' : '未绑定'}
  161. </Form.Item>
  162. </Col>
  163. <Col span={12}>
  164. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='注册时间'>
  165. {data.createTime && formatDate(data.createTime, 'YYYY-MM-DD HH:mm:ss')}
  166. </Form.Item>
  167. </Col>
  168. <Col span={12}>
  169. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='头像'>
  170. <Avatar src={data.avatar} />
  171. </Form.Item>
  172. </Col>
  173. </Row>
  174. </div>
  175. <div className="group">
  176. <h2>实名认证{<Button onClick={() => {
  177. this.realAction();
  178. }}>人工认证</Button>}</h2>
  179. {data.realStatus > 0 && <Row>
  180. <Col span={12}>
  181. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='身份证id'>
  182. {data.realIdentity}
  183. </Form.Item>
  184. </Col>
  185. <Col span={12}>
  186. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='真实姓名'>
  187. {data.realName}
  188. </Form.Item>
  189. </Col>
  190. <Col span={12}>
  191. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='地区'>
  192. {data.realAddress}
  193. </Form.Item>
  194. </Col>
  195. <Col span={12}>
  196. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='身份证照片'>
  197. <ShowImage src={data.realPhotoFront} />
  198. <ShowImage src={data.realPhotoBack} />
  199. </Form.Item>
  200. </Col>
  201. </Row>}
  202. </div>
  203. <div className="group">
  204. <h2>备考信息</h2>
  205. {data.prepareTime && <Row>
  206. <Col span={12}>
  207. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='身份'>
  208. {PrepareStatusMap[data.prepareStatus]}
  209. </Form.Item>
  210. </Col>
  211. <Col span={12}>
  212. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='考试时间'>
  213. {PrepareExaminationTimeMap[data.prepareExaminationTime]}
  214. </Form.Item>
  215. </Col>
  216. <Col span={12}>
  217. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='出分时间'>
  218. {data.prepareScoreTime ? formatDate(data.prepareScoreTime, 'YYYY-MM-DD HH:mm:ss') : ''}
  219. </Form.Item>
  220. </Col>
  221. <Col span={12}>
  222. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='目标成绩'>
  223. {data.prepareGoal}
  224. </Form.Item>
  225. </Col>
  226. </Row>}
  227. </div>
  228. </Form>
  229. </Block>;
  230. }
  231. renderService() {
  232. const { data = {} } = this.state;
  233. return <Block>
  234. <h1>服务开通</h1>
  235. <div className="group">
  236. <h2>累计消费金额</h2>
  237. <p>{data.totalMoney}</p>
  238. <Button onClick={() => {
  239. this.addMoneyAction();
  240. }}>增加线下金额</Button>
  241. </div>
  242. <div className="group">
  243. <h2>已开通服务</h2>
  244. {(data.services || []).map(service => {
  245. return <p>{ServiceKeyMap[service.service]}: {formatDate(service.startTime, 'YYYY-MM-DD HH:mm:ss')} - {formatDate(service.expireTime, 'YYYY-MM-DD HH:mm:ss')}</p>;
  246. })}
  247. </div>
  248. <div className="group">
  249. <h2>消费记录</h2>
  250. <TableLayout
  251. columns={this.tableSort(this.columns)}
  252. list={this.state.list}
  253. pagination={this.state.page}
  254. loading={this.props.core.loading}
  255. onChange={(pagination) => this.refreshService(pagination.current, pagination.pageSize)}
  256. />
  257. </div>
  258. </Block>;
  259. }
  260. renderStudy() {
  261. const { data = {} } = this.state;
  262. return <Block>
  263. <h1>学习统计</h1>
  264. <div className="group">
  265. <h2>累计学习时间</h2>
  266. <p>{formatSeconds(data.totalTime)}</p>
  267. </div>
  268. <div className="group">
  269. <h2>学习数据</h2>
  270. <Button onClick={() => {
  271. User.locationUser(this.params.id, `${PcUrl}/my/data`);
  272. }}>查看</Button>
  273. </div>
  274. </Block>;
  275. }
  276. renderView() {
  277. const { real, realEmpty = {} } = this.state;
  278. return <div flex>
  279. {this.renderBase()}
  280. {this.renderService()}
  281. {this.renderStudy()}
  282. {real && <Modal visible closable title='实名认证' onCancel={() => {
  283. this.close(false, 'real');
  284. }} onOk={() => {
  285. this.submitReal();
  286. }}>
  287. <Form>
  288. <Form.Item labelCol={{ span: 5 }} validateStatus={realEmpty.realIdentity ? 'error' : ''} wrapperCol={{ span: 16 }} label='身份id'>
  289. <Input value={real.realIdentity || ''} placeholder='输入身份id' onChange={e => {
  290. this.changeInfo('realIdentity', e.target.value);
  291. }} />
  292. </Form.Item>
  293. <Form.Item labelCol={{ span: 5 }} validateStatus={realEmpty.realName ? 'error' : ''} wrapperCol={{ span: 16 }} label='真实姓名'>
  294. <Input value={real.realName || ''} placeholder='输入真实姓名' onChange={e => {
  295. this.changeInfo('realName', e.target.value);
  296. }} />
  297. </Form.Item>
  298. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='地址'>
  299. <Input value={real.realAddress || ''} placeholder='输入地址' onChange={e => {
  300. this.changeInfo('realAddress', e.target.value);
  301. }} />
  302. </Form.Item>
  303. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='正面照'><Upload
  304. showUploadList={false}
  305. beforeUpload={(file) => System.uploadImage(file).then((result) => {
  306. this.changeInfo('realPhotoFront', result.url);
  307. return Promise.reject();
  308. })}
  309. >
  310. <Button>上传正面{(real || {}).realPhotoFront ? '(已上传)' : ''}</Button>
  311. </Upload></Form.Item>
  312. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='反面照'><Upload
  313. showUploadList={false}
  314. beforeUpload={(file) => System.uploadImage(file).then((result) => {
  315. this.changeInfo('realPhotoBack', result.url);
  316. return Promise.reject();
  317. })}
  318. >
  319. <Button>上传反面{(real || {}).realPhotoBack ? '(已上传)' : ''}</Button>
  320. </Upload></Form.Item>
  321. </Form>
  322. </Modal>}
  323. </div>;
  324. }
  325. }