timeStatisticsOne.jsx 15 KB

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