customerList.jsx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. import React from 'react';
  2. import { Icon, Button, Input, Select, Spin, Table, Switch, message, DatePicker, Modal } from 'antd';
  3. import ajax from 'jquery/src/ajax/xhr.js';
  4. import $ from 'jquery/src/ajax';
  5. import moment from 'moment';
  6. import './userList.less';
  7. import OrgDesc from './orgDesc.jsx';
  8. import UserDesc from './userDesc.jsx';
  9. import { auditStatusList } from '../../dataDic.js';
  10. import { getAuditState, getSearchUrl } from '../../tools.js';
  11. const OrgAdd = React.createClass({
  12. getInitialState() {
  13. return {
  14. visible: false,
  15. loading: false
  16. };
  17. },
  18. showModal() {
  19. this.state.mobile = undefined;
  20. this.state.unitName = undefined;
  21. this.setState({
  22. visible: true,
  23. });
  24. },
  25. handleCancel(e) {
  26. this.setState({
  27. visible: false,
  28. });
  29. },
  30. handleOk() {
  31. this.setState({
  32. loading: true
  33. });
  34. $.ajax({
  35. method: "post",
  36. dataType: "json",
  37. crossDomain: false,
  38. url: globalConfig.context + "/api/admin/addNewUser",
  39. data: {
  40. mobile: this.state.mobile,
  41. unitName: this.state.unitName,
  42. type: 1
  43. }
  44. }).done(function (data) {
  45. this.setState({
  46. loading: false
  47. });
  48. if (!data.error.length) {
  49. message.success('新增成功!');
  50. this.setState({
  51. visible: false,
  52. });
  53. this.props.closeDesc(false, true);
  54. } else {
  55. message.warning(data.error[0].message);
  56. };
  57. }.bind(this));
  58. },
  59. render() {
  60. return (
  61. <div className="patent-desc" style={{ float: 'right', marginRight: '20px' }}>
  62. <Button type="primary" onClick={this.showModal}>添加团体用户</Button>
  63. <Modal maskClosable={false} title="新增团体用户" visible={this.state.visible}
  64. onCancel={this.handleCancel}
  65. width='350px'
  66. footer={[
  67. <Button key="submit" type="primary" loading={this.state.loading} onClick={this.handleOk}>提交</Button>,
  68. <Button key="back" onClick={this.handleCancel}>返回</Button>
  69. ]}
  70. className="admin-desc-content">
  71. <div className='orgAdd-input'>
  72. <span>用户手机号码:</span>
  73. <Input
  74. value={this.state.mobile}
  75. onChange={(e) => { this.setState({ mobile: e.target.value }); }} />
  76. </div>
  77. <div className='orgAdd-input'>
  78. <span>公司名称:</span>
  79. <Input
  80. value={this.state.unitName}
  81. onChange={(e) => { this.setState({ unitName: e.target.value }); }} />
  82. </div>
  83. </Modal>
  84. </div>
  85. );
  86. }
  87. });
  88. const UserAdd = React.createClass({
  89. getInitialState() {
  90. return {
  91. visible: false,
  92. loading: false
  93. };
  94. },
  95. showModal() {
  96. this.state.mobile = undefined;
  97. this.state.username = undefined;
  98. this.setState({
  99. visible: true,
  100. });
  101. },
  102. handleCancel(e) {
  103. this.setState({
  104. visible: false,
  105. });
  106. },
  107. handleOk() {
  108. this.setState({
  109. loading: true
  110. });
  111. $.ajax({
  112. method: "post",
  113. dataType: "json",
  114. crossDomain: false,
  115. url: globalConfig.context + "/api/admin/addNewUser",
  116. data: {
  117. mobile: this.state.mobile,
  118. username: this.state.username,
  119. type: 0
  120. }
  121. }).done(function (data) {
  122. this.setState({
  123. loading: false
  124. });
  125. if (!data.error.length) {
  126. message.success('新增成功!');
  127. this.setState({
  128. visible: false,
  129. });
  130. this.props.closeDesc(false, true);
  131. } else {
  132. message.warning(data.error[0].message);
  133. };
  134. }.bind(this));
  135. },
  136. render() {
  137. return (
  138. <div className="patent-desc" style={{ float: 'right', marginRight: '20px' }}>
  139. <Button type="primary" onClick={this.showModal}>添加个人用户</Button>
  140. <Modal maskClosable={false} title="新增个人用户" visible={this.state.visible}
  141. onCancel={this.handleCancel}
  142. width='350px'
  143. footer={[
  144. <Button key="submit" type="primary" loading={this.state.loading} onClick={this.handleOk}>提交</Button>,
  145. <Button key="back" onClick={this.handleCancel}>返回</Button>
  146. ]}
  147. className="admin-desc-content">
  148. <div className='orgAdd-input'>
  149. <span>用户手机号码:</span>
  150. <Input
  151. value={this.state.mobile}
  152. onChange={(e) => { this.setState({ mobile: e.target.value }); }} />
  153. </div>
  154. <div className='orgAdd-input'>
  155. <span>用户名称:</span>
  156. <Input
  157. value={this.state.username}
  158. onChange={(e) => { this.setState({ username: e.target.value }); }} />
  159. </div>
  160. </Modal>
  161. </div>
  162. );
  163. }
  164. });
  165. const CustomerList = React.createClass({
  166. loadData(pageNo) {
  167. this.state.data = [];
  168. this.setState({
  169. loading: true
  170. });
  171. $.ajax({
  172. method: "get",
  173. dataType: "json",
  174. crossDomain: false,
  175. url: globalConfig.context + "/api/admin/customer",
  176. data: {
  177. pageNo: pageNo || 1,
  178. pageSize: this.state.pagination.pageSize,
  179. type: this.state.type,
  180. mobile: this.state.searchLoginId, //登录名
  181. email: this.state.searchEmail,
  182. startCreateTime: this.state.searchTime[0],
  183. endCreateTime: this.state.searchTime[1],
  184. number: this.state.searchAftId, //阿凡提号
  185. auditName: this.state.searchName,
  186. auditStatus: this.state.searchAuditStatus
  187. },
  188. success: function (data) {
  189. if (!data.data) {
  190. if (data.error && data.error.length) {
  191. message.warning(data.error[0].message);
  192. }
  193. } else {
  194. for (let i = 0; i < data.data.list.length; i++) {
  195. let thisdata = data.data.list[i];
  196. this.state.data.push({
  197. key: i,
  198. id: thisdata.id,
  199. type: thisdata.type,
  200. mobile: thisdata.mobile,
  201. email: thisdata.email,
  202. createTime: thisdata.createTime,
  203. aftUsername: thisdata.aftUsername,
  204. number: thisdata.number,
  205. auditStatus: thisdata.type == 0 ? thisdata.userAuditStatus : thisdata.orgAuditStatus,
  206. createTimeFormattedDate: thisdata.createTimeFormattedDate,
  207. adminName: thisdata.adminName,
  208. theName: thisdata.type == 0 ? thisdata.username : thisdata.unitName
  209. });
  210. };
  211. };
  212. this.state.pagination.current = data.data.pageNo;
  213. this.state.pagination.total = data.data.totalCount;
  214. this.setState({
  215. dataSource: this.state.data,
  216. pagination: this.state.pagination
  217. });
  218. }.bind(this),
  219. }).always(function () {
  220. this.setState({
  221. loading: false
  222. });
  223. }.bind(this));
  224. },
  225. getInitialState() {
  226. return {
  227. searchMore: true,
  228. data: [],
  229. loading: false,
  230. type: "1",
  231. searchTime: [],
  232. pagination: {
  233. defaultCurrent: 1,
  234. defaultPageSize: 10,
  235. showQuickJumper: true,
  236. pageSize: 10,
  237. onChange: function (page) {
  238. this.loadData(page);
  239. }.bind(this),
  240. showTotal: function (total) {
  241. return '共' + total + '条数据';
  242. }
  243. },
  244. columns: [
  245. {
  246. title: '阿凡提号',
  247. dataIndex: 'number',
  248. key: 'number',
  249. }, {
  250. title: '登录名',
  251. dataIndex: 'mobile',
  252. key: 'mobile',
  253. }, {
  254. title: '用户名称',
  255. dataIndex: 'aftUsername',
  256. key: 'aftUsername',
  257. }, {
  258. title: '认证状态',
  259. dataIndex: 'auditStatus',
  260. key: 'auditStatus',
  261. render: text => { return getAuditState(text); }
  262. }, {
  263. title: '注册时间',
  264. dataIndex: 'createTimeFormattedDate',
  265. key: 'createTimeFormattedDate',
  266. }, {
  267. title: '认证名称',
  268. dataIndex: 'theName',
  269. key: 'theName',
  270. }, {
  271. title: '联系方式',
  272. dataIndex: 'email',
  273. key: 'email',
  274. }, {
  275. title: '业务员',
  276. dataIndex: 'adminName',
  277. key: 'adminName',
  278. }
  279. ],
  280. dataSource: []
  281. };
  282. },
  283. componentWillMount() {
  284. this.loadData();
  285. if (window.location.search) {
  286. let theArr = getSearchUrl(window.location.search);
  287. if (theArr.length > 1) {
  288. let theObj = {};
  289. theObj.id = theArr[0];
  290. theObj.type = theArr[1];
  291. if (theObj.id != 'null' && theObj.type != 'null') {
  292. this.tableRowClick(theObj);
  293. };
  294. };
  295. };
  296. },
  297. tableRowClick(record, index) {
  298. this.state.RowData = record;
  299. switch (record.type) {
  300. case '0':
  301. this.setState({
  302. userShowDesc: true
  303. });
  304. break;
  305. case '1':
  306. this.setState({
  307. orgShowDesc: true
  308. });
  309. break;
  310. };
  311. },
  312. closeDesc(e, s) {
  313. this.state.userShowDesc = e;
  314. this.state.orgShowDesc = e;
  315. if (s) {
  316. this.loadData();
  317. };
  318. },
  319. search() {
  320. this.loadData();
  321. },
  322. reset() {
  323. this.state.searchAftId = undefined;
  324. this.state.searchLoginId = undefined;
  325. this.state.searchAuditStatus = undefined;
  326. this.state.searchName = undefined;
  327. this.state.searchEmail = undefined;
  328. this.state.searchTime = [];
  329. this.loadData();
  330. },
  331. searchSwitch() {
  332. this.setState({
  333. searchMore: !this.state.searchMore
  334. });
  335. },
  336. searchcreateTime(date, dateString) {
  337. this.state.createTime = dateString;
  338. },
  339. render() {
  340. const { RangePicker } = DatePicker;
  341. return (
  342. <div className="user-content" >
  343. <div className="content-title">
  344. <span>我的客户管理</span>
  345. <OrgAdd closeDesc={this.closeDesc} />
  346. <UserAdd closeDesc={this.closeDesc} />
  347. </div>
  348. <div className="user-search">
  349. <Select placeholder="选择用户类型" style={{ width: 100 }}
  350. value={this.state.type}
  351. onChange={(e) => { this.setState({ type: e }) }}>
  352. <Select.Option value="1" >组织用户</Select.Option>
  353. <Select.Option value="0" >个人用户</Select.Option>
  354. </Select>
  355. <Input placeholder="阿凡提号" value={this.state.searchAftId}
  356. onChange={(e) => { this.setState({ searchAftId: e.target.value }); }} />
  357. <Input placeholder="登录号" value={this.state.searchLoginId}
  358. onChange={(e) => { this.setState({ searchLoginId: e.target.value }); }} />
  359. <Select placeholder="选择认证状态" style={{ width: 140 }}
  360. value={this.state.searchAuditStatus}
  361. onChange={(e) => { this.setState({ searchAuditStatus: e }) }}>
  362. {
  363. auditStatusList.map(function (item, i) {
  364. return <Select.Option key={i} value={item.value} >{item.key}</Select.Option>
  365. })
  366. }
  367. </Select>
  368. <Input placeholder="客户认证名称" value={this.state.searchName}
  369. onChange={(e) => { this.setState({ searchName: e.target.value }); }} />
  370. <Input placeholder="联系方式" value={this.state.searchEmail}
  371. onChange={(e) => { this.setState({ searchEmail: e.target.value }); }} />
  372. <Button type="primary" onClick={this.search}>搜索</Button>
  373. <Button onClick={this.reset}>重置</Button>
  374. <span>更多搜索<Switch defaultChecked={false} onChange={this.searchSwitch} /></span>
  375. <div className="search-more" style={this.state.searchMore ? { display: 'none' } : {}}>
  376. <p>
  377. <span>注册时间:</span>
  378. <RangePicker
  379. allowClear={false}
  380. value={[this.state.searchTime[0] ? moment(this.state.searchTime[0]) : null,
  381. this.state.searchTime[1] ? moment(this.state.searchTime[1]) : null]}
  382. onChange={(data, dataString) => { this.setState({ searchTime: dataString }); }} />
  383. </p>
  384. </div>
  385. </div>
  386. <div className="patent-table">
  387. <Spin spinning={this.state.loading}>
  388. <Table columns={this.state.columns}
  389. dataSource={this.state.dataSource}
  390. pagination={this.state.pagination}
  391. onRowClick={this.tableRowClick} />
  392. </Spin>
  393. </div>
  394. <UserDesc data={this.state.RowData} showDesc={this.state.userShowDesc} closeDesc={this.closeDesc} />
  395. <OrgDesc data={this.state.RowData} showDesc={this.state.orgShowDesc} closeDesc={this.closeDesc} />
  396. </div >
  397. );
  398. }
  399. });
  400. export default CustomerList;