index.jsx 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. import React, { Component } from "react";
  2. import {
  3. Button,
  4. Modal,
  5. Form,
  6. DatePicker,
  7. message,
  8. Spin,
  9. Select,
  10. Tabs,
  11. Table,
  12. } from "antd";
  13. import $ from "jquery/src/ajax";
  14. import { ShowModal, getPercentage } from "@/tools";
  15. import { salesList } from "@/dataDic.js";
  16. import moment from "moment";
  17. import { provinceSelect, getProvince } from "../../../NewDicProvinceList";
  18. import { ChooseList } from "../../../manageCenter/order/orderNew/chooseList";
  19. import OrderList from "./order"; //客户订单列表
  20. import './index.less';
  21. import ShowModalDiv from "@/showModal.jsx";
  22. import ReactEcharts from 'echarts-for-react/lib/core';
  23. const echarts = require('echarts');
  24. const { TabPane } = Tabs;
  25. const FormItem = Form.Item;
  26. const Option = Select.Option;
  27. const { RangePicker } = DatePicker;
  28. class Source extends Component {
  29. constructor(props) {
  30. super(props);
  31. this.state = {
  32. cellData: {},
  33. searchValues: {},
  34. params: {},
  35. onelist: [
  36. {
  37. value: "0",
  38. label: "按签单金额",
  39. },
  40. {
  41. value: "1",
  42. label: "按签单数",
  43. },
  44. ],
  45. pagination: {
  46. defaultCurrent: 1,
  47. defaultPageSize: 10,
  48. showQuickJumper: true,
  49. pageSize: 10,
  50. onChange: function (page) {
  51. this.loadData(page);
  52. }.bind(this),
  53. showTotal: function (total) {
  54. return "共" + total + "条数据";
  55. },
  56. },
  57. contactsOption: [],
  58. loading: false,
  59. changeList: undefined,
  60. dataSource: [],
  61. visible: false,
  62. columns: [
  63. {
  64. title: "序号",
  65. dataIndex: "key",
  66. key: "key",
  67. width: 45,
  68. render: (text, record, index) =>
  69. <span >
  70. {index + 1}
  71. </span>
  72. },
  73. {
  74. title: "省份",
  75. dataIndex: "province",
  76. key: "province",
  77. onCellClick: (r) => {
  78. let cellData = {};
  79. cellData["province"] = r.province
  80. this.setState({
  81. visible: true,
  82. datas: cellData,
  83. })
  84. },
  85. render: (text, record) =>
  86. <span >
  87. {getProvince(text)}
  88. </span>
  89. },
  90. {
  91. title: "签单数(个)",
  92. dataIndex: "counts",
  93. key: "counts",
  94. width: '9%',
  95. onCellClick: (r) => {
  96. let cellData = {};
  97. cellData["province"] = r.province
  98. this.setState({
  99. visible: true,
  100. datas: cellData,
  101. })
  102. },
  103. },
  104. {
  105. title: "签单金额(万元)",
  106. dataIndex: "totalAmount",
  107. key: "totalAmount",
  108. width: '9%',
  109. onCellClick: (r) => {
  110. let cellData = {};
  111. cellData["province"] = r.province
  112. this.setState({
  113. visible: true,
  114. datas: cellData,
  115. })
  116. },
  117. },
  118. {
  119. title: "电话新开发/占比",
  120. dataIndex: "dhxkfl",
  121. key: "dhxkfl",
  122. width: '9%',
  123. onCellClick: (r) => {
  124. let cellData = {};
  125. cellData["province"] = r.province
  126. cellData["salesType"] = 0
  127. this.setState({
  128. visible: true,
  129. datas: cellData,
  130. })
  131. },
  132. render: (text, record) =>
  133. <span >
  134. {record.dhxkf + "/" + getPercentage(text)}
  135. </span>
  136. },
  137. {
  138. title: "电话自带资源/占比",
  139. dataIndex: "dhzdzyl",
  140. key: "dhzdzyl",
  141. width: '9%',
  142. onCellClick: (r) => {
  143. let cellData = {};
  144. cellData["province"] = r.province
  145. cellData["salesType"] = 1
  146. this.setState({
  147. visible: true,
  148. datas: cellData,
  149. })
  150. },
  151. render: (text, record) =>
  152. <span >
  153. {record.dhzdzy + "/" + getPercentage(text)}
  154. </span>
  155. },
  156. {
  157. title: "网络/占比",
  158. dataIndex: "wll",
  159. key: "wll",
  160. width: '9%',
  161. onCellClick: (r) => {
  162. let cellData = {};
  163. cellData["province"] = r.province
  164. cellData["salesType"] = 2
  165. this.setState({
  166. visible: true,
  167. datas: cellData,
  168. })
  169. },
  170. render: (text, record) =>
  171. <span >
  172. {record.wl + "/" + getPercentage(text)}
  173. </span>
  174. },
  175. {
  176. title: "渠道/占比",
  177. dataIndex: "qdl",
  178. key: "qdl",
  179. width: '9%',
  180. onCellClick: (r) => {
  181. let cellData = {};
  182. cellData["province"] = r.province
  183. cellData["salesType"] = 3
  184. this.setState({
  185. visible: true,
  186. datas: cellData,
  187. })
  188. },
  189. render: (text, record) =>
  190. <span >
  191. {record.qd + "/" + getPercentage(text)}
  192. </span>
  193. },
  194. {
  195. title: "高新复购/占比",
  196. dataIndex: "gxfgl",
  197. key: "gxfgl",
  198. width: '9%',
  199. onCellClick: (r) => {
  200. let cellData = {};
  201. cellData["province"] = r.province
  202. cellData["salesType"] = 6
  203. this.setState({
  204. visible: true,
  205. datas: cellData,
  206. })
  207. },
  208. render: (text, record) =>
  209. <span >
  210. {record.gxfg + "/" + getPercentage(text)}
  211. </span>
  212. },
  213. {
  214. title: "其他复购/占比",
  215. dataIndex: "qtfgl",
  216. key: "qtfgl",
  217. width: '9%',
  218. onCellClick: (r) => {
  219. let cellData = {};
  220. cellData["province"] = r.province
  221. cellData["salesType"] = 7
  222. this.setState({
  223. visible: true,
  224. datas: cellData,
  225. })
  226. },
  227. render: (text, record) =>
  228. <span >
  229. {record.qtfg + "/" + getPercentage(text)}
  230. </span>
  231. },
  232. {
  233. title: "转介绍/占比",
  234. dataIndex: "zjsl",
  235. key: "zjsl",
  236. width: '9%',
  237. onCellClick: (r) => {
  238. let cellData = {};
  239. cellData["province"] = r.province
  240. cellData["salesType"] = 4
  241. this.setState({
  242. visible: true,
  243. datas: cellData,
  244. })
  245. },
  246. render: (text, record) =>
  247. <span >
  248. {record.zjs + "/" + getPercentage(text)}
  249. </span>
  250. },
  251. {
  252. title: "其他/占比",
  253. dataIndex: "qtl",
  254. key: "qtl",
  255. width: '9%',
  256. onCellClick: (r) => {
  257. let cellData = {};
  258. cellData["province"] = r.province
  259. cellData["salesType"] = 5
  260. this.setState({
  261. visible: true,
  262. datas: cellData,
  263. })
  264. },
  265. render: (text, record) =>
  266. <span >
  267. {record.qt + "/" + getPercentage(text)}
  268. </span>
  269. },
  270. ],
  271. };
  272. }
  273. changeList(arr) {
  274. const newArr = [];
  275. this.state.columns.forEach((item) => {
  276. arr.forEach((val) => {
  277. if (val === item.title) {
  278. newArr.push(item);
  279. }
  280. });
  281. });
  282. this.setState({
  283. changeList: newArr,
  284. });
  285. }
  286. // 重置
  287. resetAll() {
  288. this.setState(
  289. {
  290. searchValues: JSON.parse(JSON.stringify({})),
  291. params: JSON.parse(JSON.stringify({})),
  292. selectedRowKeys: [],
  293. },
  294. () => {
  295. this.loadData();
  296. }
  297. );
  298. }
  299. // 搜索
  300. submit() {
  301. this.setState({
  302. params: this.state.searchValues
  303. })
  304. this.loadData()
  305. }
  306. // 列表接口
  307. loadData(pageNo) {
  308. const { searchValues, pagination } = this.state;
  309. this.setState({
  310. loading: true,
  311. });
  312. let datas = Object.assign(searchValues, {
  313. pageNo: pageNo || 1,
  314. pageSize: pagination.pageSize,
  315. });
  316. $.ajax({
  317. method: "get",
  318. dataType: "json",
  319. crossDomain: false,
  320. url: globalConfig.context + "/api/admin/statistis/orderSalesSource",
  321. data: datas,
  322. success: function (data) {
  323. ShowModal(this);
  324. this.setState({
  325. loading: false,
  326. });
  327. if (data.error && data.error.length === 0) {
  328. if (data.data.list) {
  329. pagination.current = data.data.pageNo;
  330. pagination.total = data.data.totalCount;
  331. if (data.data && data.data.list && !data.data.list.length) {
  332. pagination.current = 0;
  333. pagination.total = 0;
  334. }
  335. this.setState({
  336. dataSource: data.data.list,
  337. pagination: this.state.pagination,
  338. pageNo: data.data.pageNo,
  339. });
  340. } else {
  341. this.setState({
  342. dataSource: data.data,
  343. pagination: false,
  344. });
  345. }
  346. } else {
  347. message.warning(data.error[0].message);
  348. }
  349. }.bind(this),
  350. }).always(
  351. function () {
  352. this.setState({
  353. loading: false,
  354. });
  355. }.bind(this)
  356. );
  357. }
  358. // 获取上级组织
  359. selectSuperId() {
  360. this.setState({
  361. departmentLoading: true,
  362. });
  363. $.ajax({
  364. method: "get",
  365. dataType: "json",
  366. crossDomain: false,
  367. url: globalConfig.context + "/api/admin/organization/selectSuperId",
  368. data: {},
  369. success: function (data) {
  370. let theArr = [];
  371. if (data.error && data.error.length === 0) {
  372. for (let i = 0; i < data.data.length; i++) {
  373. let theData = data.data[i];
  374. theArr.push({
  375. value: theData.id,
  376. label: theData.name,
  377. });
  378. }
  379. this.setState({
  380. contactsOption: theArr,
  381. });
  382. } else {
  383. message.warning(data.error[0].message);
  384. }
  385. }.bind(this),
  386. }).always(
  387. function () {
  388. this.setState({
  389. departmentLoading: false,
  390. });
  391. }.bind(this)
  392. );
  393. }
  394. // 导出excel
  395. exportExec() {
  396. message.config({
  397. duration: 20,
  398. });
  399. let loading = message.loading("下载中...");
  400. this.setState({
  401. exportPendingLoading: true,
  402. });
  403. let data = {};
  404. let obj1 = JSON.parse(JSON.stringify(this.state.searchValues));
  405. data = Object.assign(data, obj1);
  406. $.ajax({
  407. method: "get",
  408. dataType: "json",
  409. crossDomain: false,
  410. url: "/api/admin/statistis/orderSalesSource/export",
  411. data,
  412. success: function (data) {
  413. if (data.error.length === 0) {
  414. this.download(data.data);
  415. } else {
  416. message.warning(data.error[0].message);
  417. }
  418. }.bind(this),
  419. }).always(
  420. function () {
  421. loading();
  422. this.setState({
  423. exportPendingLoading: false,
  424. });
  425. }.bind(this)
  426. );
  427. }
  428. // 下载
  429. download(fileName) {
  430. window.location.href =
  431. globalConfig.context + "/open/download?fileName=" + fileName;
  432. }
  433. getBarChartOption(data) {
  434. const wz = data.counts - data.qt - data.zjs - data.qtfg - data.gxfg - data.qd - data.wl - data.dhzdzy - data.dhxkf;
  435. return {
  436. title: {
  437. text: '湖南',
  438. subtext: '签单金额(万元): ' + data.totalAmount,
  439. left: 'center',
  440. padding: 20,
  441. },
  442. tooltip: {
  443. trigger: 'item',
  444. formatter: '{a} <br/>{b}/占比 : {c} ({d}%)',
  445. },
  446. legend: {
  447. orient: 'vertical',
  448. left: 'left',
  449. },
  450. series: [
  451. {
  452. name: '签单数: ' + data.counts,
  453. type: 'pie',
  454. radius: '60%',
  455. avoidLabelOverlap: true,
  456. data: [
  457. { value: data.dhxkf, name: '电话新开发' },
  458. { value: data.dhzdzy, name: '电话自带资源' },
  459. { value: data.wl, name: '网络' },
  460. { value: data.qd, name: '渠道' },
  461. { value: data.gxfg, name: '高新复购' },
  462. { value: data.qtfg, name: '其他复购' },
  463. { value: data.zjs, name: '转介绍' },
  464. { value: data.qt, name: '其他' },
  465. { value: wz, name: '未知' },
  466. ],
  467. emphasis: {
  468. itemStyle: {
  469. shadowBlur: 10,
  470. shadowOffsetX: 0,
  471. shadowColor: 'rgba(0, 0, 0, 0.5)',
  472. }
  473. }
  474. }
  475. ]
  476. }
  477. }
  478. componentWillMount() {
  479. this.selectSuperId();
  480. this.loadData();
  481. }
  482. render() {
  483. const { searchValues, onelist, columns, changeList, contactsOption, visible, datas, params } = this.state;
  484. return (
  485. <div className="user-content">
  486. <ShowModalDiv ShowModal={this.state.showModal} />
  487. <div className="content-title" style={{ marginBottom: 10 }}>
  488. <span style={{ fontWeight: 900, fontSize: 16, }}>销售来源统计表 &nbsp;<spn style={{ color: "rgb(49,49,255)" }}>注:可通过签单数、签单金额查询统计</spn></span>
  489. </div>
  490. <Tabs defaultActiveKey="1" onChange={() => { }}>
  491. <TabPane tab="搜索" key="1">
  492. <div style={{ paddingTop: 10 }}>
  493. <Form layout="inline">
  494. <FormItem>
  495. <Select
  496. placeholder={"请选择部门"}
  497. style={{ width: 200 }}
  498. value={searchValues["depId"]
  499. ? searchValues["depId"]
  500. : undefined}
  501. onChange={(e) => {
  502. searchValues["depId"] = e;
  503. this.setState({
  504. searchValues: searchValues,
  505. });
  506. }}
  507. >
  508. {contactsOption.map((cit, index) => (
  509. <Option key={cit.value}>{cit.label}</Option>
  510. ))}
  511. </Select>
  512. </FormItem>
  513. <FormItem>
  514. <Select
  515. placeholder={"请选择省份"}
  516. style={{ width: 150 }}
  517. value={searchValues["province"]
  518. ? searchValues["province"]
  519. : undefined}
  520. onChange={(e) => {
  521. searchValues["province"] = e;
  522. this.setState({
  523. searchValues: searchValues,
  524. });
  525. }}
  526. >
  527. {provinceSelect().map((cit, cin) => (
  528. <Option key={cit.value}>{cit.label}</Option>
  529. ))}
  530. </Select>
  531. </FormItem>
  532. <FormItem>
  533. <Select
  534. placeholder={"请选择"}
  535. style={{ width: 150 }}
  536. value={searchValues["sort"]
  537. ? searchValues["sort"]
  538. : undefined}
  539. onChange={(e) => {
  540. searchValues["sort"] = e
  541. this.setState({
  542. searchValues: searchValues,
  543. });
  544. }}
  545. >
  546. {onelist.map((it, ins) => (
  547. <Option key={it.value}>{it.label}</Option>
  548. ))}
  549. </Select>
  550. </FormItem>
  551. <FormItem>
  552. <RangePicker
  553. value={[
  554. searchValues["startDate"]
  555. ? moment(searchValues["startDate"])
  556. : null,
  557. searchValues["endDate"] ? moment(searchValues["endDate"]) : null,
  558. ]}
  559. onChange={(data, dataString) => {
  560. searchValues["startDate"] = dataString[0],
  561. searchValues["endDate"] = dataString[1],
  562. this.setState({
  563. searchValues: searchValues,
  564. });
  565. }}
  566. />
  567. </FormItem>
  568. <Button
  569. type="primary"
  570. onClick={() => { this.submit() }}
  571. style={{ marginRight: "10px" }}
  572. >
  573. 搜索
  574. </Button>
  575. <Button
  576. onClick={() => { this.resetAll() }}
  577. style={{ marginRight: "10px" }}
  578. >
  579. 重置
  580. </Button>
  581. </Form>
  582. </div>
  583. </TabPane>
  584. <TabPane tab="更改表格显示数据" key="2">
  585. <div style={{ marginLeft: 10 }}>
  586. <ChooseList
  587. columns={columns}
  588. changeFn={this.changeList.bind(this)}
  589. changeList={changeList}
  590. top={55}
  591. margin={11}
  592. />
  593. </div>
  594. </TabPane>
  595. <TabPane tab="导出" key="3">
  596. <div
  597. style={{
  598. marginLeft: 10,
  599. padding: "10px 0",
  600. display: "flex",
  601. }}
  602. >
  603. <Button
  604. type="primary"
  605. onClick={() => { this.exportExec() }}
  606. style={{ marginLeft: "10px" }}
  607. >
  608. 导出excel
  609. </Button>
  610. </div>
  611. </TabPane>
  612. </Tabs>
  613. <div className="patent-table">
  614. <Spin spinning={this.state.loading}>
  615. <Table
  616. bordered
  617. size="middle"
  618. columns={changeList ? changeList : columns}
  619. dataSource={this.state.dataSource}
  620. pagination={this.state.pagination}
  621. />
  622. </Spin>
  623. {
  624. // this.state.dataSource.length > 0 &&
  625. false &&
  626. <ReactEcharts
  627. style={{ height: "500px" }}
  628. option={this.getBarChartOption(this.state.dataSource[0])}
  629. echarts={echarts}
  630. />
  631. }
  632. </div>
  633. {
  634. visible &&
  635. <Modal
  636. visible={visible}
  637. title={
  638. <div>
  639. <span style={{ marginRight: 20 }}>客户订单列表</span>
  640. {!!salesList[datas["salesType"]] && <span style={{ color: "red", marginRight: 20 }}>销售类型:{salesList[datas["salesType"]]}</span>}
  641. <span style={{ color: "red" }}>省份:{getProvince(datas["province"])}</span>
  642. </div>}
  643. width="90%"
  644. footer={null}
  645. onCancel={() => {
  646. this.setState({
  647. visible: false,
  648. datas: {},
  649. });
  650. }}
  651. >
  652. <OrderList
  653. data={Object.assign(datas, params)}
  654. />
  655. </Modal>
  656. }
  657. </div>
  658. );
  659. }
  660. }
  661. export default Source;