customerList.jsx 15 KB

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