account.jsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. /*
  2. @author:李霆
  3. @update:2018/05/29
  4. @descript:复制粘贴,拿起来就是干!!
  5. */
  6. import React from 'react';
  7. import ajax from 'jquery/src/ajax/xhr.js';
  8. import $ from 'jquery/src/ajax';
  9. import { Row, Col, Form, Button, Spin, message, Modal, Input } from 'antd';
  10. import {getStatuslist} from '@/tools.js';
  11. import './account.less';
  12. import SpinContainer from "../../SpinContainer";
  13. const FormItem = Form.Item;
  14. class Account extends React.Component {
  15. constructor(props) {
  16. super(props);
  17. this.state = {
  18. loading: false,
  19. visible: false,
  20. editState: false,
  21. };
  22. }
  23. loadData() {
  24. this.setState({
  25. loading: true
  26. });
  27. $.ajax({
  28. method: 'get',
  29. dataType: 'json',
  30. crossDomain: false,
  31. url: globalConfig.context + '/api/user/userBase',
  32. success: function(data) {
  33. if (data.error.length || data.data == '') {
  34. if (data.error && data.error.length) {
  35. message.warning(data.error[0].message);
  36. }
  37. } else {
  38. this.setState({
  39. uid:data.data.uid,
  40. username: data.data.username, //用户注册名
  41. nickname: data.data.nickname, //用户昵称
  42. identifyName: data.data.identifyName, //注册名称
  43. email: data.data.email,
  44. mobile:data.data.mobile, //手机号码
  45. headPortraitUrl:data.data.headPortraitUrl, //头像地址
  46. type:data.data.type, //用户类型(0-个人,1-企业)
  47. accountData: data.data,
  48. status:data.data.status,//用户状态 0-正常,1-注销 ,2-锁定
  49. authentication:data.data.authentication, //实名认证状态 0-未认证,1-个人实名认
  50. createTime:data.data.createTime?new Date(data.data.createTime).toLocaleString():''
  51. });
  52. }
  53. }.bind(this)
  54. }).always(
  55. function() {
  56. this.setState({
  57. loading: false
  58. });
  59. }.bind(this)
  60. );
  61. }
  62. //修改密码
  63. passFun() {
  64. this.setState({
  65. visible: true,
  66. password: '',
  67. repeatPass: ''
  68. });
  69. }
  70. //企业认证
  71. companyFun() {}
  72. //个人认证
  73. personFun() {}
  74. //修改密码
  75. passSubmit() {
  76. if (!this.state.name) {
  77. message.warning('请填写昵称!');
  78. return;
  79. }
  80. if (!this.state.password) {
  81. message.warning('请填写新密码!');
  82. return;
  83. }
  84. if (this.state.password !== this.state.repeatPass) {
  85. message.warning('两次输入的密码不一致!');
  86. }
  87. this.setState({
  88. loading: true
  89. });
  90. $.ajax({
  91. method: 'POST',
  92. dataType: 'json',
  93. crossDomain: false,
  94. url: globalConfig.context + '/api/user/mobile',
  95. data: {
  96. mobile: this.state.mobile,
  97. mobileCode: this.state.mcode,
  98. password: this.state.password,
  99. name: this.state.name
  100. }
  101. }).done(
  102. function(data) {
  103. if (!data.error.length) {
  104. this.setState({
  105. visible: false
  106. });
  107. message.success('修改成功!');
  108. this.loadData();
  109. } else {
  110. message.warning(data.error[0].message);
  111. }
  112. }.bind(this)
  113. );
  114. }
  115. handleOk() {
  116. this.passSubmit();
  117. }
  118. handleCancel() {
  119. this.setState({
  120. visible: false
  121. });
  122. }
  123. //单个修改
  124. btnFun(item) {
  125. switch (item) {
  126. case 1:
  127. this.setState({ editName: true });
  128. setTimeout(()=>{this.refs.name.focus()},10)
  129. break;
  130. case 2:
  131. this.setState({ editPhoto: true });
  132. setTimeout(()=>{this.refs.photo.focus()},10)
  133. break;
  134. case 3:
  135. this.setState({ editEmail: true });
  136. setTimeout(()=>{this.refs.email.focus()},10)
  137. break;
  138. case 4:
  139. this.setState({ editNickname: true });
  140. setTimeout(()=>{this.refs.nickname.focus()},10)
  141. break;
  142. }
  143. this.enterFun(item);
  144. }
  145. //保存单个修改
  146. saveFun(item) {
  147. $.ajax({
  148. method: 'POST',
  149. dataType: 'json',
  150. crossDomain: false,
  151. url: globalConfig.context + '/api/user/updateUserBase',
  152. data: {
  153. identifyName: this.state.identifyName,
  154. mobile: this.state.mobile,
  155. email: this.state.email,
  156. nickname: this.state.nickname
  157. }
  158. }).done(
  159. function(data) {
  160. if (!data.error.length) {
  161. this.setState({
  162. visible: false
  163. });
  164. message.success('修改成功!');
  165. switch (item) {
  166. case 1:
  167. this.setState({ editName: false });
  168. break;
  169. case 2:
  170. this.setState({ editPhoto: false });
  171. break;
  172. case 3:
  173. this.setState({ editEmail: false });
  174. break;
  175. case 4:
  176. this.setState({ editNickname: false });
  177. break;
  178. }
  179. this.loadData();
  180. document.onkeydown={};
  181. } else {
  182. message.warning(data.error[0].message);
  183. }
  184. }.bind(this)
  185. );
  186. }
  187. //按下键盘回车键时保存
  188. enterFun(item) {
  189. if(item){
  190. document.onkeydown=function(e){ //对整个页面文档监听回车键
  191. var keyNum=window.event ? e.keyCode :e.which;
  192. if(keyNum==13){
  193. this.saveFun(item);
  194. }
  195. }.bind(this)
  196. }
  197. }
  198. componentWillMount(){
  199. this.loadData();
  200. }
  201. render() {
  202. const formItemLayout = {
  203. labelCol: { span: 8 },
  204. wrapperCol: { span: 10 }
  205. };
  206. const formItemLayoutBtn = {
  207. labelCol: { span: 8 },
  208. wrapperCol: { span: 6 }
  209. };
  210. const accountData = this.state.account || [];
  211. return (
  212. <div className="account-wrap">
  213. <span style={{'fontSize':20,marginLeft:30,marginBottom:20,display:'inline-block'}}>账号管理</span>
  214. <div className="clearfix">
  215. <SpinContainer spinning={this.state.loading}>
  216. {/* <Row>
  217. <Col span={8}>
  218. <FormItem className="half-mid" {...formItemLayout} label="注册账号">
  219. <span>{this.state.username}</span>
  220. {/* <Button disabled
  221. size="default"
  222. onClick={this.passFun.bind(this)}
  223. type="primary"
  224. className="Authentication"
  225. >
  226. 修改密码
  227. </Button>
  228. </FormItem>
  229. </Col>
  230. </Row>*/}
  231. {/* <Row>
  232. <Col span={8}>
  233. <FormItem className="half-mid" {...formItemLayout} label="注册名称">
  234. {this.state.editName ? (
  235. <Input
  236. value={this.state.identifyName}
  237. onBlur={(e) => {
  238. this.saveFun(1);
  239. }}
  240. ref="name"
  241. placeholder="请填写注册名称"
  242. onChange={(e) => {
  243. this.setState({ identifyName: e.target.value });
  244. }}
  245. />
  246. ) : (
  247. <span>{this.state.identifyName}</span>
  248. )}
  249. {this.state.editName ? (
  250. ''
  251. ) : (
  252. <Button
  253. className="Authentication"
  254. onClick={(e) => {
  255. this.btnFun(1);
  256. }}
  257. icon="edit"
  258. />
  259. )}
  260. </FormItem>
  261. </Col>
  262. </Row> */}
  263. <Row>
  264. <Col span={8}>
  265. <FormItem className="half-mid" {...formItemLayout} label="注册手机号">
  266. {this.state.editPhoto ? (
  267. <Input
  268. value={this.state.mobile}
  269. onBlur={(e) => {
  270. this.saveFun(2);
  271. }}
  272. ref="photo"
  273. placeholder="请填写注册手机号"
  274. onChange={(e) => {
  275. this.setState({ mobile: e.target.value });
  276. }}
  277. />
  278. ) : (
  279. <span>{this.state.mobile}</span>
  280. )}
  281. {this.state.editPhoto ? (
  282. ''
  283. ) : (
  284. <Button
  285. className="Authentication"
  286. onClick={(e) => {
  287. this.btnFun(2);
  288. }}
  289. icon="edit"
  290. />
  291. )}
  292. </FormItem>
  293. </Col>
  294. {/* <Col span={8}>
  295. <FormItem className="half-mid" {...formItemLayout} label="注册手机号">
  296. <span>{this.state.mobile}</span>
  297. </FormItem>
  298. </Col> */}
  299. <Col span={8}>
  300. <FormItem className="half-mid" {...formItemLayout} label="注册邮箱">
  301. {this.state.editEmail ? (
  302. <Input
  303. value={this.state.email}
  304. onBlur={(e) => {
  305. this.saveFun(3);
  306. }}
  307. ref="email"
  308. placeholder="请填写注册邮箱"
  309. onChange={(e) => {
  310. this.setState({ email: e.target.value });
  311. }}
  312. />
  313. ) : (
  314. <span>{this.state.email}</span>
  315. )}
  316. {this.state.editEmail ? (
  317. ''
  318. ) : (
  319. <Button
  320. className="Authentication"
  321. onClick={(e) => {
  322. this.btnFun(3);
  323. }}
  324. icon="edit"
  325. />
  326. )}
  327. </FormItem>
  328. </Col>
  329. <Col span={8}>
  330. <FormItem className="half-mid" {...formItemLayout} label="账号昵称">
  331. {this.state.editNickname ? (
  332. <Input
  333. value={this.state.nickname}
  334. onBlur={(e) => {
  335. this.saveFun(4);
  336. }}
  337. ref="nickname"
  338. placeholder="请填写账号昵称"
  339. onChange={(e) => {
  340. this.setState({ nickname: e.target.value });
  341. }}
  342. />
  343. ) : (
  344. <span>{this.state.nickname}</span>
  345. )}
  346. {this.state.editNickname ? (
  347. ''
  348. ) : (
  349. <Button
  350. className="Authentication"
  351. onClick={(e) => {
  352. this.btnFun(4);
  353. }}
  354. icon="edit"
  355. />
  356. )}
  357. </FormItem>
  358. </Col>
  359. </Row>
  360. <Row>
  361. <Col span={8}>
  362. <FormItem className="half-mid" {...formItemLayout} label="账号类型">
  363. {this.state.type=='1'&&<span>企业</span>}
  364. {this.state.type=='0'&&<span>个人</span>}
  365. </FormItem>
  366. </Col>
  367. <Col span={8}>
  368. <FormItem className="half-mid" {...formItemLayout} label="账号状态">
  369. <span>{getStatuslist(this.state.status)||'正常'}</span>
  370. </FormItem>
  371. </Col>
  372. <Col span={8}>
  373. <FormItem className="half-mid" {...formItemLayout} label="注册时间">
  374. <span>{this.state.createTime}</span>
  375. </FormItem>
  376. </Col>
  377. </Row>
  378. {/* <Row>
  379. <Col span={8}>
  380. <FormItem className="half-mid" {...formItemLayout} label="企业实名认证">
  381. <span>{accountData.account}</span>
  382. <Button
  383. size="default"
  384. onClick={this.companyFun.bind(this)}
  385. type="primary"
  386. className="Authentication"
  387. >
  388. 立即企业认证
  389. </Button>
  390. </FormItem>
  391. </Col>
  392. <Col span={16}>
  393. <span className="danger">实行企业实名认证后,您将享受到技淘网提供的全方位的科技咨询服务</span>
  394. </Col>
  395. </Row>
  396. <Row>
  397. <Col span={8}>
  398. <FormItem className="half-mid" {...formItemLayout} label="个人实名认证">
  399. <span>{accountData.account}</span>
  400. <Button
  401. size="default"
  402. onClick={this.companyFun.bind(this)}
  403. type="primary"
  404. className="Authentication"
  405. >
  406. 立即个人认证
  407. </Button>
  408. </FormItem>
  409. </Col>
  410. <Col span={16}>
  411. <span className="danger">实行个人实名认证后,您将享受技淘网提供的全方位的知识产权运营服务</span>
  412. </Col>
  413. </Row>
  414. <Row>
  415. <Col span={8}>
  416. <FormItem className="half-mid" {...formItemLayout} label="科技专家认证">
  417. <span>{accountData.account}</span>
  418. <Button
  419. size="default"
  420. onClick={this.companyFun.bind(this)}
  421. type="primary"
  422. className="Authentication"
  423. >
  424. 立即申请专家
  425. </Button>
  426. </FormItem>
  427. </Col>
  428. <Col span={16}>
  429. <span className="danger">实行科技专家认证后,您将成为技淘网的科技服务专家,为其他用户提供科技咨询服务</span>
  430. </Col>
  431. </Row>
  432. */}
  433. </SpinContainer>
  434. </div>
  435. <Modal
  436. title="修改密码"
  437. width="600px"
  438. visible={this.state.visible}
  439. onOk={this.handleOk.bind(this)}
  440. onCancel={this.handleCancel.bind(this)}
  441. >
  442. <div>
  443. <Form layout="horizontal" id="demand-form" onSubmit={this.passSubmit}>
  444. <SpinContainer spinning={this.state.loading}>
  445. <div className="clearfix">
  446. <FormItem
  447. labelCol={{ span: 8 }}
  448. wrapperCol={{ span: 8 }}
  449. className="half-mid"
  450. label="注册账号"
  451. >
  452. <span>{this.state.followTime}</span>
  453. </FormItem>
  454. <FormItem
  455. labelCol={{ span: 8 }}
  456. wrapperCol={{ span: 8 }}
  457. className="half-mid"
  458. label="注册名称"
  459. >
  460. <Input
  461. value={this.state.name}
  462. type="text"
  463. onChange={(e) => {
  464. this.setState({ name: e.target.value });
  465. }}
  466. />
  467. </FormItem>
  468. <FormItem
  469. labelCol={{ span: 8 }}
  470. wrapperCol={{ span: 8 }}
  471. className="half-mid"
  472. label="新密码"
  473. >
  474. <Input
  475. value={this.state.password}
  476. type="password"
  477. placeholder="请输入新密码"
  478. onChange={(e) => {
  479. this.setState({ password: e.target.value });
  480. }}
  481. />
  482. </FormItem>
  483. <FormItem
  484. labelCol={{ span: 8 }}
  485. wrapperCol={{ span: 8 }}
  486. className="half-mid"
  487. label="新密码确认"
  488. >
  489. <Input
  490. value={this.state.repeatPass}
  491. type="password"
  492. placeholder="请再次输入新密码"
  493. onChange={(e) => {
  494. this.setState({ repeatPass: e.target.value });
  495. }}
  496. />
  497. </FormItem>
  498. </div>
  499. </SpinContainer>
  500. </Form>
  501. </div>
  502. </Modal>
  503. </div>
  504. );
  505. }
  506. }
  507. export default Account;