timeStatistics.jsx 15 KB

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