index.jsx 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  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. title: <div style={{ color: 'red' }}>
  267. <div>重点客户</div>
  268. <div>(一个月内预签)</div>
  269. </div>,
  270. dataIndex: "keynoteCount",
  271. key: "keynoteCount",
  272. className: 'tableRowStyle',
  273. width: 120,
  274. },
  275. {
  276. title: <div style={{ color: 'orange' }}>
  277. <div>意向客户</div>
  278. <div>(半年内预签)</div>
  279. </div>,
  280. dataIndex: "intentionCount",
  281. key: "intentionCount",
  282. className: 'tableRowStyle',
  283. width: 120,
  284. },
  285. {
  286. title: <div style={{ color: 'green' }}>
  287. <div>一般客户</div>
  288. <div>(一年以上预签)</div>
  289. </div>,
  290. dataIndex: "generalCount",
  291. key: "generalCount",
  292. className: 'tableRowStyle',
  293. width: 120,
  294. },
  295. ],
  296. contactsOption: null,
  297. loading: false,
  298. ispage: 1,
  299. aid: '',
  300. type: '',
  301. visible: false,
  302. exportPendingLoading: false,
  303. };
  304. this.loadData = this.loadData.bind(this);
  305. this.reset = this.reset.bind(this);
  306. this.selectSuperId = this.selectSuperId.bind(this);
  307. this.changeList = this.changeList.bind(this);
  308. this.exportExec = this.exportExec.bind(this);
  309. }
  310. componentDidMount() {
  311. this.selectSuperId();
  312. }
  313. loadData() {
  314. if (!this.state.superId) {
  315. message.warning('请选择部门后再搜索')
  316. return;
  317. }
  318. this.setState({
  319. loading: true,
  320. });
  321. let api = '/api/admin/customer/selectAllUser';
  322. let data = {};
  323. if (this.state.superId) {
  324. data.depId = this.state.superId;
  325. }
  326. if (this.state.nameSearch) {
  327. data.aName = this.state.nameSearch;
  328. }
  329. if (this.state.releaseDate[0]) {
  330. data.startTime = this.state.releaseDate[0]
  331. }
  332. if (this.state.releaseDate[1]) {
  333. data.endTime = this.state.releaseDate[1]
  334. }
  335. $.ajax({
  336. method: "get",
  337. dataType: "json",
  338. crossDomain: false,
  339. url: globalConfig.context + api,
  340. data: data,
  341. success: function (data) {
  342. let theArr = [];
  343. if (data.error.length !== 0) {
  344. if (data.error && data.error.length) {
  345. message.warning(data.error[0].message);
  346. }
  347. } else {
  348. data.data.children = data.data.list;
  349. data.data.children = data.data.children.concat(data.data.aList);
  350. theArr.push(data.data);
  351. theArr = this.handleTabsInfor(theArr);
  352. this.setState({
  353. ispage: data.data.pageNo,
  354. dataSource: theArr,
  355. });
  356. }
  357. }.bind(this),
  358. }).always(
  359. function () {
  360. this.setState({
  361. loading: false,
  362. });
  363. }.bind(this)
  364. );
  365. };
  366. exportExec() {
  367. message.config({
  368. duration: 20,
  369. });
  370. let loading = message.loading("下载中...");
  371. this.setState({
  372. exportPendingLoading: true,
  373. });
  374. let data = {
  375. depId: this.state.superId,
  376. aName: this.state.nameSearch,
  377. startTime: this.state.releaseDate[0],
  378. endTime: this.state.releaseDate[1],
  379. }
  380. $.ajax({
  381. method: "get",
  382. dataType: "json",
  383. crossDomain: false,
  384. url: '/api/admin/customer/selectAllUser/export',
  385. data,
  386. success: function (data) {
  387. if (data.error.length === 0) {
  388. this.download(data.data);
  389. } else {
  390. message.warning(data.error[0].message);
  391. }
  392. }.bind(this),
  393. }).always(
  394. function () {
  395. loading();
  396. this.setState({
  397. exportPendingLoading: false,
  398. });
  399. }.bind(this)
  400. );
  401. }
  402. download(fileName) {
  403. window.location.href =
  404. globalConfig.context + "/open/download?fileName=" + fileName;
  405. }
  406. //表格数据处理
  407. handleTabsInfor(infor) {
  408. for (let i = 0; i < infor.length; i++) {
  409. if (!infor[i].key) {
  410. infor[i].key = infor[i].id ? infor[i].id : (infor[i].aid ? infor[i].aid : i)
  411. }
  412. if (infor[i].children) {
  413. for (let c = 0; c < infor[i].children.length; c++) {
  414. infor[i].children[c].key = infor[i].children[c].id;
  415. infor[i].children[c].children = infor[i].children[c].list;
  416. if (infor[i].children[c].aName) { infor[i].children[c].name = infor[i].children[c].aName }
  417. if (infor[i].children[c].aList && Array.isArray(infor[i].children[c].aList) && infor[i].children[c].aList.length) {
  418. if (infor[i].children[c].children && Array.isArray(infor[i].children[c].children)) {
  419. for (let t of infor[i].children[c].aList) {
  420. t.key = t.aid;
  421. t.name = t.aName;
  422. }
  423. infor[i].children[c].children = infor[i].children[c].children.concat(infor[i].children[c].aList);
  424. }
  425. }
  426. this.handleTabsInfor(infor[i].children);
  427. }
  428. }
  429. }
  430. return infor;
  431. }
  432. reset() {
  433. this.setState({
  434. nameSearch: '',
  435. releaseDate: [moment(Date.now() - 777600000).format('YYYY-MM-DD'), moment(Date.now()).format('YYYY-MM-DD')],
  436. }, () => {
  437. this.loadData();
  438. });
  439. };
  440. //获取上级组织
  441. selectSuperId() {
  442. this.state.data = []
  443. $.ajax({
  444. method: "get",
  445. dataType: "json",
  446. crossDomain: false,
  447. url: globalConfig.context + "/api/admin/organization/selectSuperId",
  448. data: {},
  449. success: function (data) {
  450. let theArr = [];
  451. let theId = [];//用于保存上级组织的ID和名称
  452. let thedata = data.data;
  453. if (!thedata) {
  454. if (data.error && data.error.length) {
  455. message.warning(data.error[0].message);
  456. };
  457. thedata = {};
  458. };
  459. for (var i = 0; i < data.data.length; i++) {
  460. let theData = data.data[i];
  461. theArr.push(
  462. <Select.Option value={theData.id} key={theData.id}>{theData.name}</Select.Option>
  463. );
  464. theId.push(
  465. [theData.id, theData.name]
  466. );
  467. };
  468. this.setState({
  469. SuperArr: thedata,
  470. contactsOption: theArr,
  471. theId: theId,
  472. orderStatusOptions: data.data,
  473. });
  474. if (!this.state.superId) {
  475. this.setState({
  476. superId: data.data[0].id
  477. }, () => {
  478. this.loadData();
  479. })
  480. }
  481. }.bind(this),
  482. }).always(function () {
  483. this.setState({
  484. loading: false
  485. });
  486. }.bind(this));
  487. }
  488. changeList(arr) {
  489. const newArr = [];
  490. this.state.columns.forEach(item => {
  491. arr.forEach(val => {
  492. if (val === item.title) {
  493. newArr.push(item);
  494. }
  495. });
  496. });
  497. this.setState({
  498. changeList: newArr
  499. });
  500. }
  501. render() {
  502. return (
  503. <div className="user-content">
  504. <div className="content-title">
  505. <span>部门统计</span>
  506. </div>
  507. <Tabs
  508. defaultActiveKey="1"
  509. className="test">
  510. <TabPane tab="搜索" key="1">
  511. <div className="user-search" style={{ display: 'flex', alignItems: 'center' }}>
  512. <div>
  513. <Select
  514. showSearch
  515. optionFilterProp="children"
  516. placeholder="请选择部门"
  517. style={{ width: 200, marginLeft: 10 }}
  518. value={this.state.superId}
  519. onChange={(e) => { this.setState({ superId: e }) }}
  520. notFoundContent="未获取到上级组织列表">
  521. {this.state.contactsOption}
  522. </Select>
  523. </div>
  524. <Input
  525. placeholder="客户名称"
  526. value={this.state.nameSearch}
  527. style={{ width: 150, marginRight: 10, marginLeft: 10 }}
  528. onChange={(e) => {
  529. this.setState({ nameSearch: e.target.value });
  530. }}
  531. />
  532. <div style={{
  533. marginTop: '10px',
  534. }}>
  535. <RangePicker
  536. allowClear={window.adminData.shiroList.indexOf("11") == -1}
  537. disabledDate={(current) => {//“运营管理”角色只能查看部分时间段(暂时10天)的数据
  538. let iskeep = window.adminData.shiroList.indexOf("11") != -1
  539. return iskeep && current && current.valueOf() < Date.now() - 864000000;
  540. }}
  541. value={[
  542. this.state.releaseDate[0]
  543. ? moment(this.state.releaseDate[0])
  544. : null,
  545. this.state.releaseDate[1]
  546. ? moment(this.state.releaseDate[1])
  547. : null,
  548. ]}
  549. onChange={(data, dataString) => {
  550. this.setState({ releaseDate: dataString });
  551. }}
  552. />
  553. </div>
  554. <Button
  555. type="primary"
  556. style={{ marginLeft: "10px", marginRight: 10 }}
  557. onClick={() => {
  558. this.loadData();
  559. }}
  560. >
  561. 搜索
  562. </Button>
  563. <Button onClick={this.reset}>重置</Button>
  564. </div>
  565. </TabPane>
  566. <TabPane tab="更改表格显示数据" key="2">
  567. <div style={{ marginLeft: 10 }}>
  568. <ChooseList
  569. columns={this.state.columns}
  570. changeFn={this.changeList}
  571. changeList={this.state.changeList}
  572. top={55}
  573. margin={11}
  574. />
  575. </div>
  576. </TabPane>
  577. <TabPane tab="导出" key="3">
  578. <div style={{ float: "left" }}>
  579. <Button
  580. type='primary'
  581. loading={this.state.exportPendingLoading}
  582. onClick={this.exportExec}
  583. style={{ margin: 10 }}
  584. >
  585. 导出excel
  586. </Button>
  587. </div>
  588. </TabPane>
  589. </Tabs>
  590. <div className="patent-table">
  591. <Spin spinning={this.state.loading}>
  592. <Table
  593. size="middle"
  594. scroll={{ y: 550 }}
  595. columns={
  596. this.state.changeList
  597. ? this.state.changeList
  598. : this.state.columns
  599. }
  600. dataSource={this.state.dataSource}
  601. pagination={false}
  602. />
  603. </Spin>
  604. </div>
  605. {this.state.customerVisible ? <CustomerDetails
  606. aid={this.state.aid}
  607. type={this.state.type}
  608. aName={this.state.aName}
  609. startTime={this.state.releaseDate[0]}
  610. endTime={this.state.releaseDate[1]}
  611. visible={this.state.customerVisible}
  612. onCancel={() => {
  613. this.setState({
  614. customerVisible: false,
  615. aid: '',
  616. type: '',
  617. })
  618. }}
  619. /> : <div />}
  620. </div>
  621. )
  622. }
  623. }
  624. export default DepartmentStatistics;