timeStatistics.jsx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  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. startDate: this.state.releaseDate[0],
  25. endDate: 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. 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. 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. startDate: this.state.releaseDate[0],
  92. endDate: 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: "post",
  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. console.log(table);
  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. console.log(table.nodeType);
  248. if(!table.nodeType) table = document.getElementById(table);
  249. console.log(table);
  250. var ctx = {
  251. worksheet: name || 'Worksheet',
  252. table: table.innerHTML
  253. };
  254. window.location.href = uri + base64(format(template, ctx))
  255. },
  256. getInitialState() {
  257. return {
  258. releaseDate: [],
  259. selectedRowKeys: [],
  260. selectedRows: [],
  261. loading: false,
  262. visible: false,
  263. showDesc: false,
  264. timeState: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:200,
  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()
  405. },
  406. reset() {
  407. this.state.superId = undefined;//部门机构清零
  408. this.totalData()
  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. },
  418. month(){
  419. this.state.releaseDate[0] = undefined;//开始时间清零
  420. this.state.releaseDate[1] = undefined;//结束时间清零
  421. this.totalData(1);
  422. },
  423. quarter(){
  424. this.state.releaseDate[0] = undefined;//开始时间清零
  425. this.state.releaseDate[1] = undefined;//结束时间清零
  426. this.totalData(2);
  427. },
  428. year(){
  429. this.state.releaseDate[0] = undefined;//开始时间清零
  430. this.state.releaseDate[1] = undefined;//结束时间清零
  431. this.totalData(3);
  432. },
  433. //重构排序
  434. tabChange(pagination,filter,sorter){
  435. console.log(pagination)
  436. console.log(sorter)
  437. },
  438. componentWillMount() {
  439. //this.loadData();
  440. this.totalData(0);
  441. let times=new Date();
  442. let nowTime=times.getFullYear()+'年'+(times.getMonth()+1)+'月'+times.getDate()+'日';
  443. this.setState({
  444. Nowtime:nowTime
  445. })
  446. },
  447. render() {
  448. const { RangePicker } = DatePicker;
  449. let departmentArr = this.state.departmentArr || [];
  450. return(
  451. <div className='set-content'>
  452. <p style={{fontSize:'20px',marginBottom:'10px'}}>客户营销统计表(部门)</p>
  453. <div className="clearfix">
  454. <Button type="primary" onClick={this.tabExel} style={{ float:'right' }}>导出到表格</Button>
  455. <span style={{fontSize:'16px'}}>部门机构 : </span>
  456. <Select placeholder="选择部门"
  457. style={{ width:'200px',marginRight:'10px' }}
  458. value={this.state.superId}
  459. onChange={(e) => { this.setState({ superId: e }) }} notFoundContent="未获取到上级组织列表">
  460. {this.state.contactsOption}
  461. </Select>
  462. <Button onClick={this.week} style={{marginRight:'5px'}}>本周</Button>
  463. <Button onClick={this.month} style={{marginRight:'5px'}}>本月</Button>
  464. <Button onClick={this.quarter} style={{marginRight:'5px'}}>本季</Button>
  465. <Button onClick={this.year} style={{marginRight:'5px'}}>本年</Button>
  466. <span className="titleTime" style={{marginRight:'5px'}}>起止时间:</span>
  467. <RangePicker
  468. value={[this.state.releaseDate[0] ? moment(this.state.releaseDate[0]) : null,
  469. this.state.releaseDate[1] ? moment(this.state.releaseDate[1]) : null]}
  470. onChange={(data, dataString) => { this.setState({ releaseDate: dataString }); }} />
  471. <Button type="primary" onClick={this.search} style={{marginLeft:'10px',marginRight:'10px'}}>搜索</Button>
  472. <Button onClick={this.reset}>重置</Button>
  473. </div>
  474. <div id='daochu'>
  475. <div className="surfaceTitle">
  476. <span className="nowtime">{this.state.timeState?this.state.txtTime:this.state.Nowtime}</span>
  477. <span>客户营销统计表(部门)</span>
  478. </div>
  479. <div className="patent-table" id='daochu'>
  480. <div className="scroll">
  481. <Spin spinning={this.state.loading}>
  482. <Table columns={this.state.columns}
  483. dataSource={this.state.dataSource}
  484. //scroll={{ x: 600,y:500}}
  485. bordered
  486. onChange={this.tabChange}
  487. pagination={false}
  488. />
  489. </Spin>
  490. </div>
  491. </div>
  492. </div>
  493. </div>
  494. )
  495. }
  496. });
  497. const Tablees=Form.create()(React.createClass({
  498. //详情tab切换数据处理
  499. callbacks(e) {
  500. this.setState({
  501. callnubs: e,
  502. })
  503. if(e == '1') {
  504. }
  505. if(e == '2') {
  506. }
  507. },
  508. getInitialState() {
  509. return {
  510. callnubs: "1",
  511. }
  512. },
  513. render() {
  514. return(
  515. <div className="clearfix" style={{marginTop:'0px',marginLeft:'10px'}}>
  516. <Tabs onChange={this.callbacks} type="card" activeKey={this.state.callnubs} style={{paddingLeft:'15px',paddingRight:'15px',marginRight:'20px'}}>
  517. <TabPane tab="客户营销统计表(部门)" key="1" >
  518. <DiurnalStatistics />
  519. </TabPane>
  520. <TabPane tab="客户营销统计表(员工)" key="2">
  521. <DiurnalStatisticsOne />
  522. </TabPane>
  523. </Tabs>
  524. </div>
  525. );
  526. }
  527. }));
  528. export default Tablees;