timeStatistics.jsx 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. import React from 'react';
  2. import { Select, Spin, Input, Table, Button ,DatePicker, Form , Tabs , Switch,message} from 'antd';
  3. import ajax from 'jquery/src/ajax/xhr.js';
  4. import $ from 'jquery/src/ajax';
  5. import './report.less';
  6. import DiurnalStatisticsOne from './timeStatisticsOne.jsx';
  7. import { post } from '../../../dataDic.js';
  8. import moment from 'moment';
  9. import {ChooseList} from "../../order/orderNew/chooseList";
  10. const TabPane = Tabs.TabPane;
  11. const DiurnalStatistics = React.createClass({
  12. loadData(timeTypes,totalArr) {
  13. let total=totalArr;
  14. this.setState({
  15. loading: true,
  16. timeTypes:timeTypes
  17. });
  18. $.ajax({
  19. method: "get",
  20. dataType: "json",
  21. crossDomain: false,
  22. url: globalConfig.context + "/api/admin/report/sales/sometimeMarketingStatistics",
  23. data: {
  24. type:'1',
  25. timeType:this.state.releaseDate[0]?4:timeTypes,
  26. startTime: this.state.releaseDate[0],
  27. endTime: this.state.releaseDate[1],
  28. depId:this.state.superId,//部门机构
  29. },
  30. success: function(data) {
  31. let thedata = data.data;
  32. let theArr = [];
  33. if(!thedata) {
  34. if(data.error && data.error.length) {
  35. message.warning(data.error[0].message);
  36. };
  37. thedata = {};
  38. } else {
  39. thedata.map(function(item, index) {
  40. let nub=index+1;
  41. theArr.push({
  42. key: index,
  43. theNumber:false,
  44. nub:nub,
  45. id: item.id,
  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. departmentName:'合计',
  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:'1',
  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('#daochu');
  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. {
  291. title: '部门',
  292. dataIndex: 'departmentName',
  293. key: 'departmentName',
  294. width:230,
  295. fixed:false,
  296. render:(text,record)=>{
  297. if(!record.theNumber){
  298. return text//&&text.length>6?<span title={text}>{text.substr(0,6)+'…'}</span>:text
  299. }else{
  300. return {
  301. children: text,
  302. props: {
  303. colSpan:3
  304. },
  305. }
  306. }
  307. }
  308. }, {
  309. title: '总经理',
  310. fixed:false,
  311. dataIndex: 'departmentManagerName',
  312. key: 'departmentManagerName',
  313. render:(text,record)=>{
  314. if(!record.theNumber){
  315. return text
  316. }else{
  317. return {
  318. children: text,
  319. props: {
  320. colSpan:0
  321. },
  322. }
  323. }
  324. }
  325. },
  326. {
  327. title: '营销总量',
  328. fixed:false,
  329. dataIndex: 'countFollowNo',
  330. key: 'countFollowNo',
  331. sorter: (a, b) => a.countFollowNo - b.countFollowNo,
  332. render:(text,record)=>{
  333. if(!record.theNumber){
  334. return text
  335. }else{
  336. return {
  337. children: text,
  338. props: {
  339. colSpan:1
  340. },
  341. }
  342. }
  343. }
  344. },
  345. {
  346. title: '电话量',
  347. fixed:false,
  348. dataIndex: 'countTelNo',
  349. key: 'countTelNo',
  350. sorter: (a, b) => a.countTelNo - b.countTelNo,
  351. render:(text,record)=>{
  352. if(!record.theNumber){
  353. return text
  354. }else{
  355. return {
  356. children: text,
  357. props: {
  358. colSpan:1
  359. },
  360. }
  361. }
  362. }
  363. },
  364. {
  365. title: '外拜量',
  366. fixed:false,
  367. dataIndex: 'countVisitNo',
  368. key: 'countVisitNo',
  369. sorter: (a, b) => a.countVisitNo - b.countVisitNo,
  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: 'dayAVG',
  387. key: 'dayAVG',
  388. sorter: (a, b) => a.dayAVG - b.dayAVG,
  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. dataSource: [],
  404. };
  405. },
  406. search() {
  407. this.totalData(this.state.timeTypes);
  408. },
  409. reset() {
  410. this.state.superId = undefined;//部门机构清零
  411. this.totalData(0)
  412. this.setState({
  413. order:"false"
  414. })
  415. },
  416. week(){
  417. this.state.releaseDate[0] = undefined;//开始时间清零
  418. this.state.releaseDate[1] = undefined;//结束时间清零
  419. this.totalData(0);
  420. this.setState({
  421. weekColor:true,
  422. monthColor:false,
  423. quarterColor:false,
  424. yearColor:false
  425. })
  426. },
  427. month(){
  428. this.state.releaseDate[0] = undefined;//开始时间清零
  429. this.state.releaseDate[1] = undefined;//结束时间清零
  430. this.totalData(1);
  431. this.setState({
  432. weekColor:false,
  433. monthColor:true,
  434. quarterColor:false,
  435. yearColor:false
  436. })
  437. },
  438. quarter(){
  439. this.state.releaseDate[0] = undefined;//开始时间清零
  440. this.state.releaseDate[1] = undefined;//结束时间清零
  441. this.totalData(2);
  442. this.setState({
  443. weekColor:false,
  444. monthColor:false,
  445. quarterColor:true,
  446. yearColor:false
  447. })
  448. },
  449. year(){
  450. this.state.releaseDate[0] = undefined;//开始时间清零
  451. this.state.releaseDate[1] = undefined;//结束时间清零
  452. this.totalData(3);
  453. this.setState({
  454. weekColor:false,
  455. monthColor:false,
  456. quarterColor:false,
  457. yearColor:true
  458. })
  459. },
  460. //重构排序
  461. tabChange(pagination,filter,sorter){
  462. // console.log(pagination)
  463. // console.log(sorter)
  464. },
  465. componentWillMount() {
  466. //this.loadData();
  467. this.totalData(0);
  468. let times=new Date();
  469. let nowTime=times.getFullYear()+'年'+(times.getMonth()+1)+'月'+times.getDate()+'日';
  470. this.setState({
  471. Nowtime:nowTime
  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. render() {
  488. const { RangePicker } = DatePicker;
  489. let departmentArr = this.state.departmentArr || [];
  490. return(
  491. <div className='set-content'>
  492. <p style={{fontSize:'20px',marginBottom:'10px'}}>客户营销统计表(部门)</p>
  493. <Tabs defaultActiveKey="1" className="test">
  494. <TabPane tab="搜索" key="1">
  495. <div className="clearfix" style={{paddingTop:'11px'}}>
  496. <Button type="primary" onClick={this.tabExel} style={{ float:'right' }}>导出到表格</Button>
  497. <span style={{fontSize:'16px'}}>部门机构 : </span>
  498. <Select placeholder="选择部门"
  499. style={{ width:'200px',marginRight:'10px' }}
  500. value={this.state.superId}
  501. onChange={(e) => { this.setState({ superId: e }) }} notFoundContent="未获取到上级组织列表">
  502. {this.state.contactsOption}
  503. </Select>
  504. <Button onClick={this.week} style={{marginRight:'5px'}} type={this.state.weekColor?"primary":''}>本周</Button>
  505. <Button onClick={this.month} style={{marginRight:'5px'}} type={this.state.monthColor?"primary":''}>本月</Button>
  506. <Button onClick={this.quarter} style={{marginRight:'5px'}} type={this.state.quarterColor?"primary":''}>本季</Button>
  507. <Button onClick={this.year} style={{marginRight:'5px'}} type={this.state.yearColor?"primary":''}>本年</Button>
  508. <span className="titleTime" style={{marginRight:'5px'}}>起止时间:</span>
  509. <RangePicker
  510. value={[this.state.releaseDate[0] ? moment(this.state.releaseDate[0]) : null,
  511. this.state.releaseDate[1] ? moment(this.state.releaseDate[1]) : null]}
  512. onChange={(data, dataString) => { this.setState({ releaseDate: dataString }); }} />
  513. <Button type="primary" onClick={this.search} style={{marginLeft:'10px',marginRight:'10px'}}>搜索</Button>
  514. <Button onClick={this.reset}>重置</Button>
  515. </div>
  516. </TabPane>
  517. <TabPane tab="更改表格显示数据" key="2">
  518. <div style={{ marginLeft: 10 }}>
  519. <ChooseList
  520. columns={this.state.columns}
  521. changeFn={this.changeList}
  522. changeList={this.state.changeList}
  523. top={55}
  524. margin={11}
  525. />
  526. </div>
  527. </TabPane>
  528. </Tabs>
  529. <div id='daochu'>
  530. <div className="patent-table" id='daochu'>
  531. <div className="scroll">
  532. <Spin spinning={this.state.loading}>
  533. <Table size="middle" columns={
  534. this.state.changeList
  535. ? this.state.changeList
  536. : this.state.columns
  537. }
  538. dataSource={this.state.dataSource}
  539. //scroll={{ x: 600,y:500}}
  540. bordered
  541. onChange={this.tabChange}
  542. pagination={false}
  543. />
  544. </Spin>
  545. </div>
  546. </div>
  547. </div>
  548. </div>
  549. )
  550. }
  551. });
  552. const Tablees=Form.create()(React.createClass({
  553. //详情tab切换数据处理
  554. callbacks(e) {
  555. this.setState({
  556. callnubs: e,
  557. })
  558. if(e == '1') {
  559. }
  560. if(e == '2') {
  561. }
  562. },
  563. getInitialState() {
  564. return {
  565. callnubs: "1",
  566. }
  567. },
  568. render() {
  569. return(
  570. <div className="clearfix" style={{marginTop:'0px',marginLeft:'10px'}}>
  571. <Tabs onChange={this.callbacks} type="card" activeKey={this.state.callnubs} style={{paddingLeft:'15px',paddingRight:'15px',marginRight:'20px'}}>
  572. <TabPane tab="客户营销统计表(部门)" key="1" >
  573. <DiurnalStatistics />
  574. </TabPane>
  575. <TabPane tab="客户营销统计表(员工)" key="2">
  576. <DiurnalStatisticsOne />
  577. </TabPane>
  578. </Tabs>
  579. </div>
  580. );
  581. }
  582. }));
  583. export default Tablees;