crmCount.jsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. import React from 'react';
  2. import { Select, Spin, message, Table, Button, DatePicker, Tabs } from 'antd';
  3. import ajax from 'jquery/src/ajax/xhr.js';
  4. import $ from 'jquery';
  5. import './customer.less';
  6. import { post } from '@/dataDic.js';
  7. import moment from 'moment';
  8. import { ChooseList } from "../../../order/orderNew/chooseList";
  9. import { onReplace } from '@/tools.js';
  10. const { TabPane } = Tabs;
  11. const DiurnalStatisticsOne = React.createClass({
  12. loadData(timeTypes, totalArr) {
  13. let total = totalArr;
  14. this.setState({
  15. loading: true
  16. });
  17. $.ajax({
  18. method: "get",
  19. dataType: "json",
  20. crossDomain: false,
  21. url: globalConfig.context + "/api/admin/report/userDataStatistics",
  22. data: {
  23. depId: this.state.superId,//部门机构
  24. },
  25. success: function (data) {
  26. let thedata = data.data;
  27. let theArr = [];
  28. if (!thedata) {
  29. if (data.error && data.error.length) {
  30. message.warning(data.error[0].message);
  31. };
  32. thedata = {};
  33. } else {
  34. thedata.map(function (item, index) {
  35. let nub = index + 1;
  36. theArr.push({
  37. key: index,
  38. theNumber: false,
  39. nub: nub,
  40. depName: item.depName,//部门
  41. name: item.name,//员工姓名
  42. signUser: item.signUser,//签单客户数
  43. fullUser: item.fullUser,//资料完善数
  44. dayFullUser: item.dayFullUser,//今日完善数
  45. dayNewUser: item.dayNewUser, //今日新增数
  46. countUser: item.countUser,//私有客户数
  47. signFullUser: item.signFullUser,//签单客户完善数
  48. })
  49. })
  50. }
  51. if (theArr.length) {
  52. theArr.push(
  53. {
  54. key: 9999999,
  55. theNumber: true,
  56. name: '合计',
  57. signUser: total.signUser,//签单客户数
  58. fullUser: total.fullUser,//资料完善数
  59. dayFullUser: total.dayFullUser,//今日完善数
  60. dayNewUser: total.dayNewUser,//今日新增数
  61. countUser: total.countUser,//私有客户数
  62. signFullUser: total.signFullUser,//签单客户完整数
  63. }
  64. )
  65. }
  66. this.setState({
  67. dataSource: theArr,
  68. })
  69. }.bind(this),
  70. }).always(function () {
  71. this.setState({
  72. loading: false
  73. });
  74. }.bind(this));
  75. },
  76. totalData(timeTypes) {
  77. this.setState({
  78. loading: true
  79. });
  80. $.ajax({
  81. method: "get",
  82. dataType: "json",
  83. crossDomain: false,
  84. url: globalConfig.context + "/api/admin/report/userDataStatisticsCount",
  85. data: {
  86. depId: this.state.superId,//部门机构
  87. },
  88. success: function (data) {
  89. let thedata = data.data;
  90. let theArr = [];
  91. if (!thedata) {
  92. if (data.error && data.error.length) {
  93. message.warning(data.error[0].message);
  94. };
  95. thedata = {};
  96. }
  97. this.loadData(timeTypes, thedata);
  98. this.selectSuperId();
  99. }.bind(this),
  100. }).always(function () {
  101. this.setState({
  102. loading: false
  103. });
  104. }.bind(this));
  105. },
  106. //时间选择
  107. selTime(value, index) {
  108. this.setState({
  109. Dtime: value,
  110. selTime: index
  111. })
  112. },
  113. //获取上级组织
  114. selectSuperId() {
  115. this.state.data = []
  116. $.ajax({
  117. method: "get",
  118. dataType: "json",
  119. crossDomain: false,
  120. url: globalConfig.context + "/api/admin/organization/selectSuperId",
  121. data: {
  122. },
  123. success: function (data) {
  124. let theArr = [];
  125. let theId = [];//用于保存上级组织的ID和名称
  126. let thedata = data.data;
  127. if (!thedata) {
  128. if (data.error && data.error.length) {
  129. message.warning(data.error[0].message);
  130. };
  131. thedata = {};
  132. };
  133. var contactIds = [];
  134. for (var i = 0; i < data.data.length; i++) {
  135. let theData = data.data[i];
  136. theArr.push(
  137. <Select.Option value={theData.id} key={theData.id}>{theData.name}</Select.Option>
  138. );
  139. theId.push(
  140. [theData.id, theData.name]
  141. );
  142. };
  143. this.setState({
  144. SuperArr: thedata,
  145. contactsOption: theArr,
  146. theId: theId,
  147. orderStatusOptions: data.data,
  148. });
  149. }.bind(this),
  150. }).always(function () {
  151. this.setState({
  152. loading: false
  153. });
  154. }.bind(this));
  155. },
  156. //判断浏览器类型
  157. getExplorer() {
  158. var explorer = window.navigator.userAgent;
  159. //ie
  160. if (explorer.indexOf("MSIE") >= 0) {
  161. return 'ie';
  162. }
  163. //firefox
  164. else if (explorer.indexOf("Firefox") >= 0) {
  165. return 'Firefox';
  166. }
  167. //Chrome
  168. else if (explorer.indexOf("Chrome") >= 0) {
  169. return 'Chrome';
  170. }
  171. //Opera
  172. else if (explorer.indexOf("Opera") >= 0) {
  173. return 'Opera';
  174. }
  175. //Safari
  176. else if (explorer.indexOf("Safari") >= 0) {
  177. return 'Safari';
  178. }
  179. },
  180. //导出为exel表格
  181. tabExel() {
  182. var table = document.querySelector('#daochu1');
  183. var idTmr;
  184. var ahtml = ' <a href="#" id="exportExcel" style="display:none" ></a>';//提供给下面自定义文件名的操作
  185. $("#daochu1").after(ahtml);
  186. //debugger;
  187. //整个表格拷贝到EXCEL中
  188. if (this.getExplorer() == 'ie') {
  189. var curTbl = document.getElementById(tableid);
  190. var oXL = new ActiveXObject("Excel.Application");
  191. //创建AX对象excel
  192. var oWB = oXL.Workbooks.Add();
  193. //获取workbook对象
  194. var xlsheet = oWB.Worksheets(1);
  195. //激活当前sheet
  196. var sel = document.body.createTextRange();
  197. sel.moveToElementText(curTbl);
  198. //把表格中的内容移到TextRange中
  199. sel.select();
  200. //全选TextRange中内容
  201. sel.execCommand("Copy");
  202. //复制TextRange中内容
  203. xlsheet.Paste();
  204. //粘贴到活动的EXCEL中
  205. oXL.Visible = true;
  206. //设置excel可见属性
  207. try {
  208. var fname = oXL.Application.GetSaveAsFilename("Excel.xls", "Excel Spreadsheets (*.xls), *.xls");
  209. } catch (e) {
  210. print("Nested catch caught " + e);
  211. } finally {
  212. oWB.SaveAs(fname);
  213. oWB.Close(savechanges = false);
  214. //xls.visible = false;
  215. oXL.Quit();
  216. oXL = null;
  217. //结束excel进程,退出完成
  218. //window.setInterval("Cleanup();",1);
  219. idTmr = window.setInterval("Cleanup();", 1);
  220. }
  221. } else {
  222. this.tableToExcel(table, this.getExplorer());
  223. }
  224. function Cleanup() {
  225. window.clearInterval(idTmr);
  226. CollectGarbage();
  227. }
  228. },
  229. tableToExcel(table, name) {
  230. var worksheet = '表格'
  231. var uri = 'data:application/vnd.ms-excel;base64,',
  232. template = `<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>${worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>`,
  233. base64 = function (s) {
  234. return window.btoa(unescape(encodeURIComponent(s)))
  235. },
  236. format = function (s, c) {
  237. return s.replace(/{(\w+)}/g,
  238. function (m, p) {
  239. return c[p];
  240. })
  241. }
  242. if (!table.nodeType) table = document.getElementById(table);
  243. var ctx = {
  244. worksheet: name || 'Worksheet',
  245. table: table.innerHTML
  246. };
  247. document.getElementById("exportExcel").href = uri
  248. + base64(format(template, ctx));
  249. document.getElementById("exportExcel").download = '客户资料统计' + ".xls";//自定义文件名
  250. document.getElementById("exportExcel").click();
  251. //window.location.href = uri + base64(format(template, ctx))
  252. },
  253. getInitialState() {
  254. return {
  255. releaseDate: [],
  256. selectedRowKeys: [],
  257. selectedRows: [],
  258. loading: false,
  259. visible: false,
  260. showDesc: false,
  261. timeState: false,
  262. weekColor: true,
  263. monthColor: false,
  264. quarterColor: false,
  265. yearColor: false,
  266. Dtime: undefined,
  267. selTime: '',
  268. columns: [
  269. {
  270. title: '序号',
  271. dataIndex: 'nub',
  272. width: 50,
  273. key: 'nub',
  274. fixed: false,
  275. render: (text, record) => {
  276. if (!record.theNumber) {
  277. return text
  278. } else {
  279. return {
  280. children: text,
  281. props: {
  282. colSpan: 0
  283. },
  284. }
  285. }
  286. }
  287. }, {
  288. title: '姓名',
  289. fixed: false,
  290. dataIndex: 'name',
  291. key: 'name',
  292. render: (text, record) => {
  293. if (!record.theNumber) {
  294. return onReplace(text)
  295. } else {
  296. return {
  297. children: onReplace(text),
  298. props: {
  299. colSpan: 3
  300. },
  301. }
  302. }
  303. }
  304. },
  305. {
  306. title: '部门',
  307. dataIndex: 'depName',
  308. key: 'depName',
  309. fixed: false,
  310. width: 300,
  311. render: (text, record) => {
  312. if (!record.theNumber) {
  313. return text //&&text.length>6?<span title={text}>{text.substr(0,6)+'…'}</span>:text
  314. } else {
  315. return {
  316. children: text,
  317. props: {
  318. colSpan: 0
  319. },
  320. }
  321. }
  322. }
  323. }, {
  324. title: '客户总数',
  325. fixed: false,
  326. dataIndex: 'countUser',
  327. key: 'countUser',
  328. render: (text, record) => {
  329. if (!record.theNumber) {
  330. return text
  331. } else {
  332. return {
  333. children: text,
  334. props: {
  335. colSpan: 1
  336. },
  337. }
  338. }
  339. }
  340. },
  341. {
  342. title: '今日新增客户数',
  343. fixed: false,
  344. dataIndex: 'dayNewUser',
  345. key: 'dayNewUser',
  346. sorter: (a, b) => a.dayNewUser - b.dayNewUser,
  347. render: (text, record) => {
  348. if (!record.theNumber) {
  349. return text
  350. } else {
  351. return {
  352. children: text,
  353. props: {
  354. colSpan: 1
  355. },
  356. }
  357. }
  358. }
  359. },
  360. {
  361. title: '完整客户总数',
  362. fixed: false,
  363. dataIndex: 'fullUser',
  364. key: 'fullUser',
  365. sorter: (a, b) => a.fullUser - b.fullUser,
  366. render: (text, record) => {
  367. if (!record.theNumber) {
  368. return text
  369. } else {
  370. return {
  371. children: text,
  372. props: {
  373. colSpan: 1
  374. },
  375. }
  376. }
  377. }
  378. },
  379. {
  380. title: '今日完整客户数',
  381. fixed: false,
  382. dataIndex: 'dayFullUser',
  383. key: 'dayFullUser',
  384. sorter: (a, b) => a.dayFullUser - b.dayFullUser,
  385. render: (text, record) => {
  386. if (!record.theNumber) {
  387. return text
  388. } else {
  389. return {
  390. children: text,
  391. props: {
  392. colSpan: 1
  393. },
  394. }
  395. }
  396. }
  397. },
  398. {
  399. title: '签单客户总数',
  400. fixed: false,
  401. dataIndex: 'signUser',
  402. key: 'signUser',
  403. sorter: (a, b) => a.signUser - b.signUser,
  404. render: (text, record) => {
  405. if (!record.theNumber) {
  406. return text
  407. } else {
  408. return {
  409. children: text,
  410. props: {
  411. colSpan: 1
  412. },
  413. }
  414. }
  415. }
  416. },
  417. {
  418. title: '签单完整客户数',
  419. fixed: false,
  420. dataIndex: 'signFullUser',
  421. key: 'signFullUser',
  422. sorter: (a, b) => a.signFullUser - b.signFullUser,
  423. render: (text, record) => {
  424. if (!record.theNumber) {
  425. return text
  426. } else {
  427. return {
  428. children: text,
  429. props: {
  430. colSpan: 1
  431. },
  432. }
  433. }
  434. }
  435. }
  436. ],
  437. dataSource: [],
  438. };
  439. },
  440. search() {
  441. this.totalData(0)
  442. },
  443. reset() {
  444. this.state.superId = undefined;//部门机构清零
  445. this.totalData(0);
  446. },
  447. week() {
  448. this.state.releaseDate[0] = undefined;//开始时间清零
  449. this.state.releaseDate[1] = undefined;//结束时间清零
  450. this.totalData(0);
  451. this.setState({
  452. weekColor: true,
  453. monthColor: false,
  454. quarterColor: false,
  455. yearColor: false
  456. })
  457. },
  458. month() {
  459. this.state.releaseDate[0] = undefined;//开始时间清零
  460. this.state.releaseDate[1] = undefined;//结束时间清零
  461. this.totalData(1);
  462. this.setState({
  463. weekColor: false,
  464. monthColor: true,
  465. quarterColor: false,
  466. yearColor: false
  467. })
  468. },
  469. quarter() {
  470. this.state.releaseDate[0] = undefined;//开始时间清零
  471. this.state.releaseDate[1] = undefined;//结束时间清零
  472. this.totalData(2);
  473. this.setState({
  474. weekColor: false,
  475. monthColor: false,
  476. quarterColor: true,
  477. yearColor: false
  478. })
  479. },
  480. year() {
  481. this.state.releaseDate[0] = undefined;//开始时间清零
  482. this.state.releaseDate[1] = undefined;//结束时间清零
  483. this.totalData(3);
  484. this.setState({
  485. weekColor: false,
  486. monthColor: false,
  487. quarterColor: false,
  488. yearColor: true
  489. })
  490. },
  491. componentWillMount() {
  492. this.totalData(0);
  493. let times = new Date();
  494. let nowTime = times.getFullYear() + '年' + (times.getMonth() + 1) + '月' + times.getDate() + '日';
  495. this.setState({
  496. Nowtime: nowTime
  497. })
  498. },
  499. changeList(arr) {
  500. const newArr = [];
  501. this.state.columns.forEach(item => {
  502. arr.forEach(val => {
  503. if (val === item.title) {
  504. newArr.push(item);
  505. }
  506. });
  507. });
  508. this.setState({
  509. changeList: newArr
  510. });
  511. },
  512. render() {
  513. const { RangePicker } = DatePicker;
  514. let departmentArr = this.state.departmentArr || [];
  515. return (
  516. <div className='set-content'>
  517. <span style={{ fontWeight: 900, fontSize: 16 }}>客户资料填写统计</span>
  518. <Tabs
  519. defaultActiveKey="1"
  520. className="test">
  521. <TabPane tab="搜索" key="1">
  522. <div className="clearfix" style={{ marginTop: 10 }}>
  523. <Button type="primary" onClick={this.tabExel} style={{ float: 'right' }}>导出到表格</Button>
  524. <span style={{ fontSize: '16px' }}>部门机构 : </span>
  525. <Select placeholder="选择部门"
  526. style={{ width: '200px', marginRight: '10px' }}
  527. value={this.state.superId}
  528. onChange={(e) => { this.setState({ superId: e }) }} notFoundContent="未获取到上级组织列表">
  529. {this.state.contactsOption}
  530. </Select>
  531. <Button type="primary" onClick={this.search} style={{ marginLeft: '10px', marginRight: '10px' }}>搜索</Button>
  532. <Button onClick={this.reset}>重置</Button>
  533. </div>
  534. </TabPane>
  535. <TabPane tab="更改表格显示数据" key="2">
  536. <div style={{ marginLeft: 10 }}>
  537. <ChooseList
  538. columns={this.state.columns}
  539. changeFn={this.changeList}
  540. changeList={this.state.changeList}
  541. top={55}
  542. margin={11}
  543. />
  544. </div>
  545. </TabPane>
  546. </Tabs>
  547. <div id='daochu1'>
  548. <div className="surfaceTitle">
  549. <span style={{ fontWeight: 900, fontSize: 16 }}>客户资料填写统计表</span>
  550. </div>
  551. <div className="patent-table">
  552. <div className="scroll">
  553. <Spin spinning={this.state.loading}>
  554. <Table columns={
  555. this.state.changeList
  556. ? this.state.changeList
  557. : this.state.columns
  558. }
  559. dataSource={this.state.dataSource}
  560. pagination={false}
  561. bordered
  562. size="small"
  563. />
  564. </Spin>
  565. </div>
  566. </div>
  567. </div>
  568. </div>
  569. )
  570. }
  571. });
  572. export default DiurnalStatisticsOne;