customerList.jsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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 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;
  97. this.setState({
  98. visible: true,
  99. });
  100. },
  101. handleCancel(e) {
  102. this.setState({
  103. visible: false,
  104. });
  105. },
  106. handleOk() {
  107. this.setState({
  108. loading: true
  109. });
  110. $.ajax({
  111. method: "post",
  112. dataType: "json",
  113. crossDomain: false,
  114. url: globalConfig.context + "/api/admin/addNewUser",
  115. data: {
  116. mobile: this.state.mobile,
  117. type: 0
  118. }
  119. }).done(function (data) {
  120. this.setState({
  121. loading: false
  122. });
  123. if (!data.error.length) {
  124. message.success('新增成功!');
  125. this.setState({
  126. visible: false,
  127. });
  128. this.props.closeDesc(false, true);
  129. } else {
  130. message.warning(data.error[0].message);
  131. };
  132. }.bind(this));
  133. },
  134. render() {
  135. return (
  136. <div className="patent-desc" style={{ float: 'right', marginRight: '20px' }}>
  137. <Button type="primary" onClick={this.showModal}>添加个人用户</Button>
  138. <Modal title="新增个人用户" visible={this.state.visible}
  139. onCancel={this.handleCancel}
  140. width='350px'
  141. footer={[
  142. <Button key="submit" type="primary" loading={this.state.loading} onClick={this.handleOk}>提交</Button>,
  143. <Button key="back" onClick={this.handleCancel}>返回</Button>
  144. ]}
  145. className="admin-desc-content">
  146. <div className='orgAdd-input'>
  147. <span>用户手机号码:</span>
  148. <Input
  149. value={this.state.mobile}
  150. onChange={(e) => { this.setState({ mobile: e.target.value }); }} />
  151. </div>
  152. </Modal>
  153. </div>
  154. );
  155. }
  156. });
  157. const CustomerList = React.createClass({
  158. loadData(pageNo) {
  159. this.state.data = [];
  160. this.setState({
  161. loading: true
  162. });
  163. $.ajax({
  164. method: "get",
  165. dataType: "json",
  166. crossDomain: false,
  167. url: globalConfig.context + "/api/admin/customer",
  168. data: {
  169. pageNo: pageNo || 1,
  170. pageSize: this.state.pagination.pageSize,
  171. mobile: this.state.searchLoginId, //登录名
  172. email: this.state.searchEmail,
  173. createTime: this.state.searchTime,
  174. number: this.state.searchAftId, //阿凡提号
  175. unitName: this.state.searchUnitName,
  176. auditStatus: this.state.searchAuditStatus
  177. },
  178. success: function (data) {
  179. if (!data.data) {
  180. if (data.error && data.error.length) {
  181. message.warning(data.error[0].message);
  182. }
  183. return;
  184. };
  185. for (let i = 0; i < data.data.length; i++) {
  186. let thisdata = data.data[i];
  187. this.state.data.push({
  188. key: i,
  189. id: thisdata.id,
  190. type: thisdata.type,
  191. mobile: thisdata.mobile,
  192. email: thisdata.email,
  193. createTime: thisdata.createTime,
  194. aftUsername: thisdata.aftUsername,
  195. number: thisdata.number,
  196. auditStatus: thisdata.auditStatus,
  197. createTimeFormattedDate: thisdata.createTimeFormattedDate,
  198. adminName: thisdata.adminName,
  199. unitName: thisdata.unitName
  200. });
  201. };
  202. this.state.pagination.current = data.data.pageNo;
  203. this.state.pagination.total = data.data.totalCount;
  204. this.setState({
  205. dataSource: this.state.data,
  206. pagination: this.state.pagination
  207. });
  208. }.bind(this),
  209. }).always(function () {
  210. this.setState({
  211. loading: false
  212. });
  213. }.bind(this));
  214. },
  215. getInitialState() {
  216. return {
  217. searchMore: true,
  218. data: [],
  219. loading: false,
  220. searchTime: [,],
  221. pagination: {
  222. defaultCurrent: 1,
  223. defaultPageSize: 10,
  224. showQuickJumper: true,
  225. pageSize: 10,
  226. onChange: function (page) {
  227. this.loadData(page);
  228. }.bind(this),
  229. showTotal: function (total) {
  230. return '共' + total + '条数据';
  231. }
  232. },
  233. columns: [
  234. {
  235. title: '阿凡提号',
  236. dataIndex: 'number',
  237. key: 'number',
  238. }, {
  239. title: '登录名',
  240. dataIndex: 'mobile',
  241. key: 'mobile',
  242. }, {
  243. title: '公司名称',
  244. dataIndex: 'unitName',
  245. key: 'unitName',
  246. }, {
  247. title: '认证状态',
  248. dataIndex: 'auditStatus',
  249. key: 'auditStatus',
  250. render: text => { return getAuditState(text); }
  251. }, {
  252. title: '注册时间',
  253. dataIndex: 'createTimeFormattedDate',
  254. key: 'createTimeFormattedDate',
  255. }, {
  256. title: '认证名称',
  257. dataIndex: 'aftUsername',
  258. key: 'aftUsername',
  259. }, {
  260. title: '联系方式',
  261. dataIndex: 'email',
  262. key: 'email',
  263. }, {
  264. title: '业务员',
  265. dataIndex: 'adminName',
  266. key: 'adminName',
  267. }
  268. ],
  269. dataSource: []
  270. };
  271. },
  272. componentWillMount() {
  273. this.loadData();
  274. if (window.location.search) {
  275. let theArr = getSearchUrl(window.location.search);
  276. if (theArr.length > 1) {
  277. let theObj = {};
  278. theObj.id = theArr[0];
  279. theObj.type = theArr[1];
  280. if (theObj.id != 'null' && theObj.type != 'null') {
  281. this.tableRowClick(theObj);
  282. };
  283. };
  284. };
  285. },
  286. tableRowClick(record, index) {
  287. this.state.RowData = record;
  288. switch (record.type) {
  289. case '0':
  290. this.setState({
  291. userShowDesc: true
  292. });
  293. break;
  294. case '1':
  295. this.setState({
  296. orgShowDesc: true
  297. });
  298. break;
  299. };
  300. },
  301. closeDesc(e, s) {
  302. this.state.userShowDesc = e;
  303. this.state.orgShowDesc = e;
  304. if (s) {
  305. this.loadData();
  306. };
  307. },
  308. search() {
  309. this.loadData();
  310. },
  311. reset() {
  312. this.state.searchAftId = undefined;
  313. this.state.searchLoginId = undefined;
  314. this.state.searchAuditStatus = undefined;
  315. this.state.searchUnitName = undefined;
  316. this.state.searchEmail = undefined;
  317. this.state.searchTime = [];
  318. this.loadData();
  319. },
  320. searchSwitch() {
  321. this.setState({
  322. searchMore: !this.state.searchMore
  323. });
  324. },
  325. searchcreateTime(date, dateString) {
  326. this.state.createTime = dateString;
  327. },
  328. render() {
  329. const { RangePicker } = DatePicker;
  330. return (
  331. <div className="user-content" >
  332. <div className="content-title">
  333. <span>我的客户管理</span>
  334. <OrgAdd closeDesc={this.closeDesc} />
  335. <UserAdd closeDesc={this.closeDesc} />
  336. </div>
  337. <div className="user-search">
  338. <Input placeholder="阿凡提号" value={this.state.searchAftId}
  339. onChange={(e) => { this.setState({ searchAftId: e.target.value }); }} />
  340. <Input placeholder="登录号" value={this.state.searchLoginId}
  341. onChange={(e) => { this.setState({ searchLoginId: e.target.value }); }} />
  342. <Select placeholder="选择认证状态" style={{ width: 140 }}
  343. value={this.state.searchAuditStatus}
  344. onChange={(e) => { this.setState({ searchAuditStatus: e }) }}>
  345. {
  346. auditStatusList.map(function (item, i) {
  347. return <Select.Option key={i} value={item.value} >{item.key}</Select.Option>
  348. })
  349. }
  350. </Select>
  351. <Input placeholder="公司名称" value={this.state.searchUnitName}
  352. onChange={(e) => { this.setState({ searchUnitName: e.target.value }); }} />
  353. <Input placeholder="联系方式" value={this.state.searchEmail}
  354. onChange={(e) => { this.setState({ searchEmail: e.target.value }); }} />
  355. <Button type="primary" onClick={this.search}>搜索</Button>
  356. <Button onClick={this.reset}>重置</Button>
  357. <span>更多搜索<Switch defaultChecked={false} onChange={this.searchSwitch} /></span>
  358. <div className="search-more" style={this.state.searchMore ? { display: 'none' } : {}}>
  359. <p>
  360. <span>注册时间:</span>
  361. <RangePicker
  362. allowClear={false}
  363. value={[this.state.searchTime[0] ? moment(this.state.searchTime[0]) : null,
  364. this.state.searchTime[1] ? moment(this.state.searchTime[1]) : null]}
  365. onChange={(data, dataString) => { this.setState({ searchTime: dataString }); }} />
  366. </p>
  367. </div>
  368. </div>
  369. <div className="patent-table">
  370. <Spin spinning={this.state.loading}>
  371. <Table columns={this.state.columns}
  372. dataSource={this.state.dataSource}
  373. pagination={this.state.pagination}
  374. onRowClick={this.tableRowClick} />
  375. </Spin>
  376. </div>
  377. <UserDesc data={this.state.RowData} showDesc={this.state.userShowDesc} closeDesc={this.closeDesc} />
  378. <OrgDesc data={this.state.RowData} showDesc={this.state.orgShowDesc} closeDesc={this.closeDesc} />
  379. </div >
  380. );
  381. }
  382. });
  383. export default CustomerList;