customerList.jsx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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 || !data.data.list) {
  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. managerName: thisdata.managerName,
  205. number: thisdata.number,
  206. auditStatus: thisdata.type == 0 ? thisdata.userAuditStatus : thisdata.orgAuditStatus,
  207. createTimeFormattedDate: thisdata.createTimeFormattedDate,
  208. adminName: thisdata.adminName,
  209. theName: thisdata.type == 0 ? thisdata.username : thisdata.unitName
  210. });
  211. };
  212. this.state.pagination.current = data.data.pageNo;
  213. this.state.pagination.total = data.data.totalCount;
  214. };
  215. this.setState({
  216. dataSource: this.state.data,
  217. pagination: this.state.pagination
  218. });
  219. }.bind(this),
  220. }).always(function () {
  221. this.setState({
  222. loading: false
  223. });
  224. }.bind(this));
  225. },
  226. getInitialState() {
  227. return {
  228. searchMore: true,
  229. data: [],
  230. loading: false,
  231. type: "1",
  232. searchTime: [],
  233. pagination: {
  234. defaultCurrent: 1,
  235. defaultPageSize: 10,
  236. showQuickJumper: true,
  237. pageSize: 10,
  238. onChange: function (page) {
  239. this.loadData(page);
  240. }.bind(this),
  241. showTotal: function (total) {
  242. return '共' + total + '条数据';
  243. }
  244. },
  245. columns: [
  246. {
  247. title: '阿凡提号',
  248. dataIndex: 'number',
  249. key: 'number',
  250. }, {
  251. title: '登录名',
  252. dataIndex: 'mobile',
  253. key: 'mobile',
  254. }, {
  255. title: '用户名称',
  256. dataIndex: 'aftUsername',
  257. key: 'aftUsername',
  258. }, {
  259. title: '认证状态',
  260. dataIndex: 'auditStatus',
  261. key: 'auditStatus',
  262. render: text => { return getAuditState(text); }
  263. }, {
  264. title: '注册时间',
  265. dataIndex: 'createTimeFormattedDate',
  266. key: 'createTimeFormattedDate',
  267. }, {
  268. title: '认证名称',
  269. dataIndex: 'theName',
  270. key: 'theName',
  271. }, {
  272. title: '联系方式',
  273. dataIndex: 'email',
  274. key: 'email',
  275. }, {
  276. title: '业务员',
  277. dataIndex: 'adminName',
  278. key: 'adminName',
  279. }
  280. ],
  281. dataSource: []
  282. };
  283. },
  284. componentWillMount() {
  285. this.loadData();
  286. if (window.location.search) {
  287. let theArr = getSearchUrl(window.location.search);
  288. if (theArr.length > 1) {
  289. let theObj = {};
  290. theObj.id = theArr[0];
  291. theObj.type = theArr[1];
  292. if (theObj.id != 'null' && theObj.type != 'null') {
  293. this.tableRowClick(theObj);
  294. };
  295. };
  296. };
  297. },
  298. tableRowClick(record, index) {
  299. this.state.RowData = record;
  300. switch (record.type) {
  301. case '0':
  302. this.setState({
  303. userShowDesc: true
  304. });
  305. break;
  306. case '1':
  307. this.setState({
  308. orgShowDesc: true
  309. });
  310. break;
  311. };
  312. },
  313. closeDesc(e, s) {
  314. this.state.userShowDesc = e;
  315. this.state.orgShowDesc = e;
  316. if (s) {
  317. this.loadData();
  318. };
  319. },
  320. search() {
  321. this.loadData();
  322. },
  323. reset() {
  324. this.state.searchAftId = undefined;
  325. this.state.searchLoginId = undefined;
  326. this.state.searchAuditStatus = undefined;
  327. this.state.searchName = undefined;
  328. this.state.searchEmail = undefined;
  329. this.state.searchTime = [];
  330. this.loadData();
  331. },
  332. searchSwitch() {
  333. this.setState({
  334. searchMore: !this.state.searchMore
  335. });
  336. },
  337. searchcreateTime(date, dateString) {
  338. this.state.createTime = dateString;
  339. },
  340. render() {
  341. const { RangePicker } = DatePicker;
  342. return (
  343. <div className="user-content" >
  344. <div className="content-title">
  345. <span>我的客户管理</span>
  346. <OrgAdd closeDesc={this.closeDesc} />
  347. <UserAdd closeDesc={this.closeDesc} />
  348. </div>
  349. <div className="user-search">
  350. <Select placeholder="选择用户类型" style={{ width: 100 }}
  351. value={this.state.type}
  352. onChange={(e) => { this.setState({ type: e }) }}>
  353. <Select.Option value="1" >组织用户</Select.Option>
  354. <Select.Option value="0" >个人用户</Select.Option>
  355. </Select>
  356. <Input placeholder="阿凡提号" value={this.state.searchAftId}
  357. onChange={(e) => { this.setState({ searchAftId: e.target.value }); }} />
  358. <Input placeholder="登录号" value={this.state.searchLoginId}
  359. onChange={(e) => { this.setState({ searchLoginId: e.target.value }); }} />
  360. <Select placeholder="选择认证状态" style={{ width: 140 }}
  361. value={this.state.searchAuditStatus}
  362. onChange={(e) => { this.setState({ searchAuditStatus: e }) }}>
  363. {
  364. auditStatusList.map(function (item, i) {
  365. return <Select.Option key={i} value={item.value} >{item.key}</Select.Option>
  366. })
  367. }
  368. </Select>
  369. <Input placeholder="客户认证名称" value={this.state.searchName}
  370. onChange={(e) => { this.setState({ searchName: e.target.value }); }} />
  371. <Input placeholder="联系方式" value={this.state.searchEmail}
  372. onChange={(e) => { this.setState({ searchEmail: e.target.value }); }} />
  373. <Button type="primary" onClick={this.search}>搜索</Button>
  374. <Button onClick={this.reset}>重置</Button>
  375. <span>更多搜索<Switch defaultChecked={false} onChange={this.searchSwitch} /></span>
  376. <div className="search-more" style={this.state.searchMore ? { display: 'none' } : {}}>
  377. <p>
  378. <span>注册时间:</span>
  379. <RangePicker
  380. allowClear={false}
  381. value={[this.state.searchTime[0] ? moment(this.state.searchTime[0]) : null,
  382. this.state.searchTime[1] ? moment(this.state.searchTime[1]) : null]}
  383. onChange={(data, dataString) => { this.setState({ searchTime: dataString }); }} />
  384. </p>
  385. </div>
  386. </div>
  387. <div className="patent-table">
  388. <Spin spinning={this.state.loading}>
  389. <Table columns={this.state.columns}
  390. dataSource={this.state.dataSource}
  391. pagination={this.state.pagination}
  392. onRowClick={this.tableRowClick}
  393. size="middle"
  394. bordered
  395. />
  396. </Spin>
  397. </div>
  398. <UserDesc data={this.state.RowData} showDesc={this.state.userShowDesc} closeDesc={this.closeDesc} />
  399. <OrgDesc data={this.state.RowData} showDesc={this.state.orgShowDesc} closeDesc={this.closeDesc} />
  400. </div >
  401. );
  402. }
  403. });
  404. export default CustomerList;