index.jsx 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. import React, { Component } from 'react';
  2. import {
  3. Button, DatePicker,
  4. Input,
  5. message,
  6. Select,
  7. Spin,
  8. Table, Tabs,
  9. } from "antd";
  10. import './index.less';
  11. import $ from "jquery/src/ajax";
  12. import CustomerDetails from './customerDetails';
  13. import moment from "moment";
  14. import { ChooseList } from "../../../order/orderNew/chooseList";
  15. const { RangePicker } = DatePicker;
  16. const { TabPane } = Tabs;
  17. class DepartmentStatistics extends Component {
  18. constructor(props) {
  19. super(props);
  20. this.state = {
  21. superId: undefined,
  22. nameSearch: '',
  23. releaseDate: [moment(Date.now() - 777600000).format('YYYY-MM-DD'), moment(Date.now()).format('YYYY-MM-DD')],
  24. columns: [
  25. {
  26. title: "部门",
  27. dataIndex: "name",
  28. key: "name",
  29. width: '25%',
  30. },
  31. {
  32. title: "私有数",
  33. dataIndex: "userCount",
  34. key: "userCount",
  35. className: 'tableRowStyle',
  36. width: 120,
  37. render: (text, record) => {
  38. return (
  39. <div
  40. className={record.aid ? 'receiveCount' : ''}
  41. onClick={(e) => {
  42. if (record.aid) {
  43. e.stopPropagation();
  44. this.setState({
  45. customerVisible: true,
  46. aid: record.aid,
  47. aName: record.aName,
  48. type: 0,
  49. })
  50. }
  51. }}>
  52. {text}
  53. </div>
  54. );
  55. },
  56. },
  57. {
  58. title: "私有领取数",
  59. dataIndex: "receiveCount",
  60. key: "receiveCount",
  61. className: 'tableRowStyle',
  62. width: 120,
  63. render: (text, record) => {
  64. return (
  65. <div
  66. className={record.aid ? 'receiveCount' : ''}
  67. onClick={(e) => {
  68. if (record.aid) {
  69. e.stopPropagation();
  70. this.setState({
  71. customerVisible: true,
  72. aName: record.aName,
  73. aid: record.aid,
  74. type: 7,
  75. })
  76. }
  77. }}>
  78. {text}
  79. </div>
  80. );
  81. },
  82. },
  83. {
  84. title: "私有新增数",
  85. dataIndex: "newCount",
  86. key: "newCount",
  87. className: 'tableRowStyle',
  88. width: 120,
  89. render: (text, record) => {
  90. return (
  91. <div
  92. className={record.aid ? 'receiveCount' : ''}
  93. onClick={(e) => {
  94. if (record.aid) {
  95. e.stopPropagation();
  96. this.setState({
  97. customerVisible: true,
  98. aName: record.aName,
  99. aid: record.aid,
  100. type: 3,
  101. })
  102. }
  103. }}>
  104. {text}
  105. </div>
  106. );
  107. },
  108. },
  109. {
  110. title: "私有转交数",
  111. dataIndex: "transferCount",
  112. key: "transferCount",
  113. className: 'tableRowStyle',
  114. width: 120,
  115. render: (text, record) => {
  116. return (
  117. <div
  118. className={record.aid ? 'receiveCount' : ''}
  119. onClick={(e) => {
  120. if (record.aid) {
  121. e.stopPropagation();
  122. this.setState({
  123. customerVisible: true,
  124. aName: record.aName,
  125. aid: record.aid,
  126. type: 8,
  127. })
  128. }
  129. }}>
  130. {text}
  131. </div>
  132. );
  133. },
  134. },
  135. {
  136. title: "外联数",
  137. dataIndex: "channelCount",
  138. key: "channelCount",
  139. className: 'tableRowStyle',
  140. width: 120,
  141. render: (text, record) => {
  142. return (
  143. <div
  144. className={record.aid ? 'receiveCount' : ''}
  145. onClick={(e) => {
  146. if (record.aid) {
  147. e.stopPropagation();
  148. this.setState({
  149. customerVisible: true,
  150. aid: record.aid,
  151. aName: record.aName,
  152. type: 1,
  153. })
  154. }
  155. }}>
  156. {text}
  157. </div>
  158. );
  159. },
  160. },
  161. {
  162. title: "签单数",
  163. dataIndex: "signCount",
  164. key: "signCount",
  165. className: 'tableRowStyle',
  166. width: 120,
  167. render: (text, record) => {
  168. return (
  169. <div
  170. className={record.aid ? 'receiveCount' : ''}
  171. onClick={(e) => {
  172. if (record.aid) {
  173. e.stopPropagation();
  174. this.setState({
  175. customerVisible: true,
  176. aName: record.aName,
  177. aid: record.aid,
  178. type: 2,
  179. })
  180. }
  181. }}>
  182. {text}
  183. </div>
  184. );
  185. },
  186. },
  187. {
  188. title: "外联新增数",
  189. dataIndex: "channelNewCount",
  190. key: "channelNewCount",
  191. className: 'tableRowStyle',
  192. width: 120,
  193. render: (text, record) => {
  194. return (
  195. <div
  196. className={record.aid ? 'receiveCount' : ''}
  197. onClick={(e) => {
  198. if (record.aid) {
  199. e.stopPropagation();
  200. this.setState({
  201. customerVisible: true,
  202. aName: record.aName,
  203. aid: record.aid,
  204. type: 4,
  205. })
  206. }
  207. }}>
  208. {text}
  209. </div>
  210. );
  211. },
  212. },
  213. {
  214. title: "私有面谈数",
  215. dataIndex: "completeCount",
  216. key: "completeCount",
  217. className: 'tableRowStyle',
  218. width: 120,
  219. render: (text, record) => {
  220. return (
  221. <div
  222. className={record.aid ? 'receiveCount' : ''}
  223. onClick={(e) => {
  224. if (record.aid) {
  225. e.stopPropagation();
  226. this.setState({
  227. customerVisible: true,
  228. aName: record.aName,
  229. aid: record.aid,
  230. type: 5,
  231. })
  232. }
  233. }}>
  234. {text}
  235. </div>
  236. );
  237. },
  238. },
  239. {
  240. title: "外联面谈数",
  241. dataIndex: "channelCompleteCount",
  242. key: "channelCompleteCount",
  243. className: 'tableRowStyle',
  244. width: 120,
  245. render: (text, record) => {
  246. return (
  247. <div
  248. className={record.aid ? 'receiveCount' : ''}
  249. onClick={(e) => {
  250. if (record.aid) {
  251. e.stopPropagation();
  252. this.setState({
  253. customerVisible: true,
  254. aName: record.aName,
  255. aid: record.aid,
  256. type: 6,
  257. })
  258. }
  259. }}>
  260. {text}
  261. </div>
  262. );
  263. },
  264. },
  265. ],
  266. contactsOption: null,
  267. loading: false,
  268. ispage: 1,
  269. aid: '',
  270. type: '',
  271. visible: false,
  272. };
  273. this.loadData = this.loadData.bind(this);
  274. this.reset = this.reset.bind(this);
  275. this.selectSuperId = this.selectSuperId.bind(this);
  276. this.changeList = this.changeList.bind(this);
  277. }
  278. componentDidMount() {
  279. this.selectSuperId();
  280. }
  281. loadData() {
  282. if (!this.state.superId) {
  283. message.warning('请选择部门后再搜索')
  284. return;
  285. }
  286. this.setState({
  287. loading: true,
  288. });
  289. let api = '/api/admin/customer/selectAllUser';
  290. let data = {};
  291. if (this.state.superId) {
  292. data.depId = this.state.superId;
  293. }
  294. if (this.state.nameSearch) {
  295. data.aName = this.state.nameSearch;
  296. }
  297. if (this.state.releaseDate[0]) {
  298. data.startTime = this.state.releaseDate[0]
  299. }
  300. if (this.state.releaseDate[1]) {
  301. data.endTime = this.state.releaseDate[1]
  302. }
  303. $.ajax({
  304. method: "get",
  305. dataType: "json",
  306. crossDomain: false,
  307. url: globalConfig.context + api,
  308. data: data,
  309. success: function (data) {
  310. let theArr = [];
  311. if (data.error.length !== 0) {
  312. if (data.error && data.error.length) {
  313. message.warning(data.error[0].message);
  314. }
  315. } else {
  316. data.data.children = data.data.list;
  317. data.data.children = data.data.children.concat(data.data.aList);
  318. theArr.push(data.data);
  319. theArr = this.handleTabsInfor(theArr);
  320. this.setState({
  321. ispage: data.data.pageNo,
  322. dataSource: theArr,
  323. });
  324. }
  325. }.bind(this),
  326. }).always(
  327. function () {
  328. this.setState({
  329. loading: false,
  330. });
  331. }.bind(this)
  332. );
  333. };
  334. //表格数据处理
  335. handleTabsInfor(infor) {
  336. for (let i = 0; i < infor.length; i++) {
  337. if (!infor[i].key) {
  338. infor[i].key = infor[i].id ? infor[i].id : (infor[i].aid ? infor[i].aid : i)
  339. }
  340. if (infor[i].children) {
  341. for (let c = 0; c < infor[i].children.length; c++) {
  342. infor[i].children[c].key = infor[i].children[c].id;
  343. infor[i].children[c].children = infor[i].children[c].list;
  344. if (infor[i].children[c].aName) { infor[i].children[c].name = infor[i].children[c].aName }
  345. if (infor[i].children[c].aList && Array.isArray(infor[i].children[c].aList) && infor[i].children[c].aList.length) {
  346. if (infor[i].children[c].children && Array.isArray(infor[i].children[c].children)) {
  347. for (let t of infor[i].children[c].aList) {
  348. t.key = t.aid;
  349. t.name = t.aName;
  350. }
  351. infor[i].children[c].children = infor[i].children[c].children.concat(infor[i].children[c].aList);
  352. }
  353. }
  354. this.handleTabsInfor(infor[i].children);
  355. }
  356. }
  357. }
  358. return infor;
  359. }
  360. reset() {
  361. this.setState({
  362. nameSearch: '',
  363. releaseDate: [moment(Date.now() - 777600000).format('YYYY-MM-DD'), moment(Date.now()).format('YYYY-MM-DD')],
  364. }, () => {
  365. this.loadData();
  366. });
  367. };
  368. //获取上级组织
  369. selectSuperId() {
  370. this.state.data = []
  371. $.ajax({
  372. method: "get",
  373. dataType: "json",
  374. crossDomain: false,
  375. url: globalConfig.context + "/api/admin/organization/selectSuperId",
  376. data: {},
  377. success: function (data) {
  378. let theArr = [];
  379. let theId = [];//用于保存上级组织的ID和名称
  380. let thedata = data.data;
  381. if (!thedata) {
  382. if (data.error && data.error.length) {
  383. message.warning(data.error[0].message);
  384. };
  385. thedata = {};
  386. };
  387. for (var i = 0; i < data.data.length; i++) {
  388. let theData = data.data[i];
  389. theArr.push(
  390. <Select.Option value={theData.id} key={theData.id}>{theData.name}</Select.Option>
  391. );
  392. theId.push(
  393. [theData.id, theData.name]
  394. );
  395. };
  396. this.setState({
  397. SuperArr: thedata,
  398. contactsOption: theArr,
  399. theId: theId,
  400. orderStatusOptions: data.data,
  401. });
  402. if (!this.state.superId) {
  403. this.setState({
  404. superId: data.data[0].id
  405. }, () => {
  406. this.loadData();
  407. })
  408. }
  409. }.bind(this),
  410. }).always(function () {
  411. this.setState({
  412. loading: false
  413. });
  414. }.bind(this));
  415. }
  416. changeList(arr) {
  417. const newArr = [];
  418. this.state.columns.forEach(item => {
  419. arr.forEach(val => {
  420. if (val === item.title) {
  421. newArr.push(item);
  422. }
  423. });
  424. });
  425. this.setState({
  426. changeList: newArr
  427. });
  428. }
  429. render() {
  430. return (
  431. <div className="user-content">
  432. <div className="content-title">
  433. <span>部门统计</span>
  434. </div>
  435. <Tabs
  436. defaultActiveKey="1"
  437. className="test">
  438. <TabPane tab="搜索" key="1">
  439. <div className="user-search" style={{ display: 'flex', alignItems: 'center' }}>
  440. <div>
  441. <Select
  442. showSearch
  443. optionFilterProp="children"
  444. placeholder="请选择部门"
  445. style={{ width: 200, marginLeft: 10 }}
  446. value={this.state.superId}
  447. onChange={(e) => { this.setState({ superId: e }) }}
  448. notFoundContent="未获取到上级组织列表">
  449. {this.state.contactsOption}
  450. </Select>
  451. </div>
  452. <Input
  453. placeholder="客户名称"
  454. value={this.state.nameSearch}
  455. style={{ width: 150, marginRight: 10, marginLeft: 10 }}
  456. onChange={(e) => {
  457. this.setState({ nameSearch: e.target.value });
  458. }}
  459. />
  460. <div style={{
  461. marginTop: '10px',
  462. }}>
  463. <RangePicker
  464. allowClear={window.adminData.shiroList.indexOf("11") == -1}
  465. disabledDate={(current) => {//“运营管理”角色只能查看部分时间段(暂时10天)的数据
  466. let iskeep = window.adminData.shiroList.indexOf("11") != -1
  467. return iskeep && current && current.valueOf() < Date.now() - 864000000;
  468. }}
  469. value={[
  470. this.state.releaseDate[0]
  471. ? moment(this.state.releaseDate[0])
  472. : null,
  473. this.state.releaseDate[1]
  474. ? moment(this.state.releaseDate[1])
  475. : null,
  476. ]}
  477. onChange={(data, dataString) => {
  478. this.setState({ releaseDate: dataString });
  479. }}
  480. />
  481. </div>
  482. <Button
  483. type="primary"
  484. style={{ marginLeft: "10px", marginRight: 10 }}
  485. onClick={() => {
  486. this.loadData();
  487. }}
  488. >
  489. 搜索
  490. </Button>
  491. <Button onClick={this.reset}>重置</Button>
  492. </div>
  493. </TabPane>
  494. <TabPane tab="更改表格显示数据" key="2">
  495. <div style={{ marginLeft: 10 }}>
  496. <ChooseList
  497. columns={this.state.columns}
  498. changeFn={this.changeList}
  499. changeList={this.state.changeList}
  500. top={55}
  501. margin={11}
  502. />
  503. </div>
  504. </TabPane>
  505. </Tabs>
  506. <div className="patent-table">
  507. <Spin spinning={this.state.loading}>
  508. <Table
  509. size="middle"
  510. scroll={{ y: 550 }}
  511. columns={
  512. this.state.changeList
  513. ? this.state.changeList
  514. : this.state.columns
  515. }
  516. dataSource={this.state.dataSource}
  517. pagination={false}
  518. />
  519. </Spin>
  520. </div>
  521. {this.state.customerVisible ? <CustomerDetails
  522. aid={this.state.aid}
  523. type={this.state.type}
  524. aName={this.state.aName}
  525. startTime={this.state.releaseDate[0]}
  526. endTime={this.state.releaseDate[1]}
  527. visible={this.state.customerVisible}
  528. onCancel={() => {
  529. this.setState({
  530. customerVisible: false,
  531. aid: '',
  532. type: '',
  533. })
  534. }}
  535. /> : <div />}
  536. </div>
  537. )
  538. }
  539. }
  540. export default DepartmentStatistics;