crmCount.jsx 16 KB

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