timeStatistics.jsx 15 KB

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