timeStatistics.jsx 16 KB

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