crmCount.jsx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  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/src/ajax';
  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. //debugger;
  227. //整个表格拷贝到EXCEL中
  228. if(this.getExplorer() == 'ie') {
  229. var curTbl = document.getElementById(tableid);
  230. var oXL = new ActiveXObject("Excel.Application");
  231. //创建AX对象excel
  232. var oWB = oXL.Workbooks.Add();
  233. //获取workbook对象
  234. var xlsheet = oWB.Worksheets(1);
  235. //激活当前sheet
  236. var sel = document.body.createTextRange();
  237. sel.moveToElementText(curTbl);
  238. //把表格中的内容移到TextRange中
  239. sel.select();
  240. //全选TextRange中内容
  241. sel.execCommand("Copy");
  242. //复制TextRange中内容
  243. xlsheet.Paste();
  244. //粘贴到活动的EXCEL中
  245. oXL.Visible = true;
  246. //设置excel可见属性
  247. try {
  248. var fname = oXL.Application.GetSaveAsFilename("Excel.xls", "Excel Spreadsheets (*.xls), *.xls");
  249. } catch(e) {
  250. print("Nested catch caught " + e);
  251. } finally {
  252. oWB.SaveAs(fname);
  253. oWB.Close(savechanges = false);
  254. //xls.visible = false;
  255. oXL.Quit();
  256. oXL = null;
  257. //结束excel进程,退出完成
  258. //window.setInterval("Cleanup();",1);
  259. idTmr = window.setInterval("Cleanup();", 1);
  260. }
  261. } else {
  262. this.tableToExcel(table,this.getExplorer());
  263. }
  264. function Cleanup() {
  265. window.clearInterval(idTmr);
  266. CollectGarbage();
  267. }
  268. },
  269. tableToExcel(table,name) {
  270. var uri = 'data:application/vnd.ms-excel;base64,',
  271. 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>',
  272. base64 = function(s) {
  273. return window.btoa(unescape(encodeURIComponent(s)))
  274. },
  275. format = function(s, c) {
  276. return s.replace(/{(\w+)}/g,
  277. function(m, p) {
  278. return c[p];
  279. })
  280. }
  281. if(!table.nodeType) table = document.getElementById(table);
  282. var ctx = {
  283. worksheet: name || 'Worksheet',
  284. table: table.innerHTML
  285. };
  286. window.location.href = uri + base64(format(template, ctx))
  287. },
  288. getInitialState() {
  289. return {
  290. releaseDate: [],
  291. selectedRowKeys: [],
  292. selectedRows: [],
  293. loading: false,
  294. visible: false,
  295. showDesc: false,
  296. timeState:false,
  297. weekColor:true,
  298. monthColor:false,
  299. quarterColor:false,
  300. yearColor:false,
  301. Dtime:undefined,
  302. selTime:'',
  303. columns: [
  304. {
  305. title: '序号',
  306. dataIndex: 'nub',
  307. width:50,
  308. key: 'nub',
  309. fixed:false,
  310. render:(text,record)=>{
  311. if(!record.theNumber){
  312. return text
  313. }else{
  314. return {
  315. children: text,
  316. props: {
  317. colSpan:0
  318. },
  319. }
  320. }
  321. }
  322. },{
  323. title: '姓名',
  324. fixed:false,
  325. dataIndex: 'name',
  326. key: 'name',
  327. render:(text,record)=>{
  328. if(!record.theNumber){
  329. return text
  330. }else{
  331. return {
  332. children: text,
  333. props: {
  334. colSpan:3
  335. },
  336. }
  337. }
  338. }
  339. },
  340. {
  341. title: '部门',
  342. dataIndex: 'depName',
  343. key: 'depName',
  344. fixed:false,
  345. width:300,
  346. render:(text,record)=>{
  347. if(!record.theNumber){
  348. return text //&&text.length>6?<span title={text}>{text.substr(0,6)+'…'}</span>:text
  349. }else{
  350. return {
  351. children: text,
  352. props: {
  353. colSpan:0
  354. },
  355. }
  356. }
  357. }
  358. },{
  359. title: '客户总数',
  360. fixed:false,
  361. dataIndex: 'countUser',
  362. key: 'countUser',
  363. render:(text,record)=>{
  364. if(!record.theNumber){
  365. return text
  366. }else{
  367. return {
  368. children: text,
  369. props: {
  370. colSpan:1
  371. },
  372. }
  373. }
  374. }
  375. },
  376. {
  377. title: '今日新增客户数',
  378. fixed:false,
  379. dataIndex: 'dayNewUser',
  380. key: 'dayNewUser',
  381. sorter: (a, b) => a.dayNewUser - b.dayNewUser,
  382. render:(text,record)=>{
  383. if(!record.theNumber){
  384. return text
  385. }else{
  386. return {
  387. children: text,
  388. props: {
  389. colSpan:1
  390. },
  391. }
  392. }
  393. }
  394. },
  395. {
  396. title: '完整客户总数',
  397. fixed:false,
  398. dataIndex: 'fullUser',
  399. key: 'fullUser',
  400. sorter: (a, b) => a.fullUser - b.fullUser,
  401. render:(text,record)=>{
  402. if(!record.theNumber){
  403. return text
  404. }else{
  405. return {
  406. children: text,
  407. props: {
  408. colSpan:1
  409. },
  410. }
  411. }
  412. }
  413. },
  414. {
  415. title: '今日完整客户数',
  416. fixed:false,
  417. dataIndex: 'dayFullUser',
  418. key: 'dayFullUser',
  419. sorter: (a, b) => a.dayFullUser - b.dayFullUser,
  420. render:(text,record)=>{
  421. if(!record.theNumber){
  422. return text
  423. }else{
  424. return {
  425. children: text,
  426. props: {
  427. colSpan:1
  428. },
  429. }
  430. }
  431. }
  432. },
  433. {
  434. title: '签单客户总数',
  435. fixed:false,
  436. dataIndex: 'signUser',
  437. key: 'signUser',
  438. sorter: (a, b) => a.signUser - b.signUser,
  439. render:(text,record)=>{
  440. if(!record.theNumber){
  441. return text
  442. }else{
  443. return {
  444. children: text,
  445. props: {
  446. colSpan:1
  447. },
  448. }
  449. }
  450. }
  451. },
  452. {
  453. title: '签单完整客户数',
  454. fixed:false,
  455. dataIndex: 'signFullUser',
  456. key: 'signFullUser',
  457. sorter: (a, b) => a.signFullUser - b.signFullUser,
  458. render:(text,record)=>{
  459. if(!record.theNumber){
  460. return text
  461. }else{
  462. return {
  463. children: text,
  464. props: {
  465. colSpan:1
  466. },
  467. }
  468. }
  469. }
  470. }
  471. ],
  472. dataSource: [],
  473. };
  474. },
  475. search() {
  476. this.totalData(0)
  477. },
  478. reset() {
  479. this.state.superId = undefined;//部门机构清零
  480. this.totalData(0);
  481. },
  482. week(){
  483. this.state.releaseDate[0] = undefined;//开始时间清零
  484. this.state.releaseDate[1] = undefined;//结束时间清零
  485. this.totalData(0);
  486. this.setState({
  487. weekColor:true,
  488. monthColor:false,
  489. quarterColor:false,
  490. yearColor:false
  491. })
  492. },
  493. month(){
  494. this.state.releaseDate[0] = undefined;//开始时间清零
  495. this.state.releaseDate[1] = undefined;//结束时间清零
  496. this.totalData(1);
  497. this.setState({
  498. weekColor:false,
  499. monthColor:true,
  500. quarterColor:false,
  501. yearColor:false
  502. })
  503. },
  504. quarter(){
  505. this.state.releaseDate[0] = undefined;//开始时间清零
  506. this.state.releaseDate[1] = undefined;//结束时间清零
  507. this.totalData(2);
  508. this.setState({
  509. weekColor:false,
  510. monthColor:false,
  511. quarterColor:true,
  512. yearColor:false
  513. })
  514. },
  515. year(){
  516. this.state.releaseDate[0] = undefined;//开始时间清零
  517. this.state.releaseDate[1] = undefined;//结束时间清零
  518. this.totalData(3);
  519. this.setState({
  520. weekColor:false,
  521. monthColor:false,
  522. quarterColor:false,
  523. yearColor:true
  524. })
  525. },
  526. componentWillMount() {
  527. this.totalData(0);
  528. let times=new Date();
  529. let nowTime=times.getFullYear()+'年'+(times.getMonth()+1)+'月'+times.getDate()+'日';
  530. this.setState({
  531. Nowtime:nowTime
  532. })
  533. },
  534. render() {
  535. const { RangePicker } = DatePicker;
  536. let departmentArr = this.state.departmentArr || [];
  537. return(
  538. <div className='set-content'>
  539. <p style={{fontSize:'20px',marginBottom:'10px'}}>客户资料填写统计</p>
  540. <div className="clearfix">
  541. <Button type="primary" onClick={this.tabExel} style={{float:'right'}}>导出到表格</Button>
  542. <span style={{fontSize:'16px'}}>部门机构 : </span>
  543. <Select placeholder="选择部门"
  544. style={{ width:'200px',marginRight:'10px' }}
  545. value={this.state.superId}
  546. onChange={(e) => { this.setState({ superId: e }) }} notFoundContent="未获取到上级组织列表">
  547. {this.state.contactsOption}
  548. </Select>
  549. <Button type="primary" onClick={this.search} style={{marginLeft:'10px',marginRight:'10px'}}>搜索</Button>
  550. <Button onClick={this.reset}>重置</Button>
  551. </div>
  552. <div id='daochu1'>
  553. <div className="surfaceTitle">
  554. <span>客户资料填写统计表</span>
  555. </div>
  556. <div className="patent-table">
  557. <div className="scroll">
  558. <Spin spinning={this.state.loading}>
  559. <Table columns={this.state.columns}
  560. dataSource={this.state.dataSource}
  561. bordered
  562. pagination={false}
  563. />
  564. </Spin>
  565. </div>
  566. </div>
  567. </div>
  568. </div>
  569. )
  570. }
  571. });
  572. export default DiurnalStatisticsOne;