timeStatistics.jsx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  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. Dtime:undefined,
  262. selTime:'',
  263. columns: [
  264. {
  265. title: '序号',
  266. dataIndex: 'nub',
  267. width:50,
  268. key: 'nub',
  269. fixed:false,
  270. render:(text,record)=>{
  271. if(!record.theNumber){
  272. return text
  273. }else{
  274. return {
  275. children: text,
  276. props: {
  277. colSpan:0
  278. },
  279. }
  280. }
  281. }
  282. },
  283. {
  284. title: '部门',
  285. dataIndex: 'departmentName',
  286. key: 'departmentName',
  287. width:200,
  288. fixed:false,
  289. render:(text,record)=>{
  290. if(!record.theNumber){
  291. return text&&text.length>6?<span title={text}>{text.substr(0,6)+'…'}</span>:text
  292. }else{
  293. return {
  294. children: text,
  295. props: {
  296. colSpan:3
  297. },
  298. }
  299. }
  300. }
  301. }, {
  302. title: '总经理',
  303. fixed:false,
  304. dataIndex: 'departmentManagerName',
  305. key: 'departmentManagerName',
  306. render:(text,record)=>{
  307. if(!record.theNumber){
  308. return text
  309. }else{
  310. return {
  311. children: text,
  312. props: {
  313. colSpan:0
  314. },
  315. }
  316. }
  317. }
  318. },
  319. {
  320. title: '营销总量',
  321. fixed:false,
  322. dataIndex: 'countFollowNo',
  323. key: 'countFollowNo',
  324. sorter: (a, b) => a.countFollowNo - b.countFollowNo,
  325. render:(text,record)=>{
  326. if(!record.theNumber){
  327. return text
  328. }else{
  329. return {
  330. children: text,
  331. props: {
  332. colSpan:1
  333. },
  334. }
  335. }
  336. }
  337. },
  338. {
  339. title: '电话量',
  340. fixed:false,
  341. dataIndex: 'countTelNo',
  342. key: 'countTelNo',
  343. sorter: (a, b) => a.countTelNo - b.countTelNo,
  344. render:(text,record)=>{
  345. if(!record.theNumber){
  346. return text
  347. }else{
  348. return {
  349. children: text,
  350. props: {
  351. colSpan:1
  352. },
  353. }
  354. }
  355. }
  356. },
  357. {
  358. title: '外拜量',
  359. fixed:false,
  360. dataIndex: 'countVisitNo',
  361. key: 'countVisitNo',
  362. sorter: (a, b) => a.countVisitNo - b.countVisitNo,
  363. render:(text,record)=>{
  364. if(!record.theNumber){
  365. return text
  366. }else{
  367. return {
  368. children: text,
  369. props: {
  370. colSpan:1
  371. },
  372. }
  373. }
  374. }
  375. },
  376. {
  377. title: '营销日均量',
  378. fixed:false,
  379. dataIndex: 'dayAVG',
  380. key: 'dayAVG',
  381. sorter: (a, b) => a.dayAVG - b.dayAVG,
  382. render:(text,record)=>{
  383. if(!record.theNumber){
  384. return text
  385. }else{
  386. return {
  387. children: text,
  388. props: {
  389. colSpan:1
  390. },
  391. }
  392. }
  393. }
  394. }
  395. ],
  396. dataSource: [],
  397. };
  398. },
  399. search() {
  400. this.totalData(0)
  401. },
  402. reset() {
  403. this.state.superId = undefined;//部门机构清零
  404. this.totalData(0)
  405. this.setState({
  406. order:"false"
  407. })
  408. },
  409. week(){
  410. this.state.releaseDate[0] = undefined;//开始时间清零
  411. this.state.releaseDate[1] = undefined;//结束时间清零
  412. this.totalData(0);
  413. },
  414. month(){
  415. this.state.releaseDate[0] = undefined;//开始时间清零
  416. this.state.releaseDate[1] = undefined;//结束时间清零
  417. this.totalData(1);
  418. },
  419. quarter(){
  420. this.state.releaseDate[0] = undefined;//开始时间清零
  421. this.state.releaseDate[1] = undefined;//结束时间清零
  422. this.totalData(2);
  423. },
  424. year(){
  425. this.state.releaseDate[0] = undefined;//开始时间清零
  426. this.state.releaseDate[1] = undefined;//结束时间清零
  427. this.totalData(3);
  428. },
  429. //重构排序
  430. tabChange(pagination,filter,sorter){
  431. console.log(pagination)
  432. console.log(sorter)
  433. },
  434. componentWillMount() {
  435. //this.loadData();
  436. this.totalData(0);
  437. let times=new Date();
  438. let nowTime=times.getFullYear()+'年'+(times.getMonth()+1)+'月'+times.getDate()+'日';
  439. this.setState({
  440. Nowtime:nowTime
  441. })
  442. },
  443. render() {
  444. const { RangePicker } = DatePicker;
  445. let departmentArr = this.state.departmentArr || [];
  446. return(
  447. <div className='set-content'>
  448. <p style={{fontSize:'20px',marginBottom:'10px'}}>客户营销统计表(部门)</p>
  449. <div className="clearfix">
  450. <Button type="primary" onClick={this.tabExel} style={{ float:'right' }}>导出到表格</Button>
  451. <span style={{fontSize:'16px'}}>部门机构 : </span>
  452. <Select placeholder="选择部门"
  453. style={{ width:'200px',marginRight:'10px' }}
  454. value={this.state.superId}
  455. onChange={(e) => { this.setState({ superId: e }) }} notFoundContent="未获取到上级组织列表">
  456. {this.state.contactsOption}
  457. </Select>
  458. <Button onClick={this.week} style={{marginRight:'5px'}}>本周</Button>
  459. <Button onClick={this.month} style={{marginRight:'5px'}}>本月</Button>
  460. <Button onClick={this.quarter} style={{marginRight:'5px'}}>本季</Button>
  461. <Button onClick={this.year} style={{marginRight:'5px'}}>本年</Button>
  462. <span className="titleTime" style={{marginRight:'5px'}}>起止时间:</span>
  463. <RangePicker
  464. value={[this.state.releaseDate[0] ? moment(this.state.releaseDate[0]) : null,
  465. this.state.releaseDate[1] ? moment(this.state.releaseDate[1]) : null]}
  466. onChange={(data, dataString) => { this.setState({ releaseDate: dataString }); }} />
  467. <Button type="primary" onClick={this.search} style={{marginLeft:'10px',marginRight:'10px'}}>搜索</Button>
  468. <Button onClick={this.reset}>重置</Button>
  469. </div>
  470. <div id='daochu'>
  471. <div className="surfaceTitle">
  472. <span className="nowtime">{this.state.timeState?this.state.txtTime:this.state.Nowtime}</span>
  473. <span>客户营销统计表(部门)</span>
  474. </div>
  475. <div className="patent-table" id='daochu'>
  476. <div className="scroll">
  477. <Spin spinning={this.state.loading}>
  478. <Table columns={this.state.columns}
  479. dataSource={this.state.dataSource}
  480. //scroll={{ x: 600,y:500}}
  481. bordered
  482. onChange={this.tabChange}
  483. pagination={false}
  484. />
  485. </Spin>
  486. </div>
  487. </div>
  488. </div>
  489. </div>
  490. )
  491. }
  492. });
  493. const Tablees=Form.create()(React.createClass({
  494. //详情tab切换数据处理
  495. callbacks(e) {
  496. this.setState({
  497. callnubs: e,
  498. })
  499. if(e == '1') {
  500. }
  501. if(e == '2') {
  502. }
  503. },
  504. getInitialState() {
  505. return {
  506. callnubs: "1",
  507. }
  508. },
  509. render() {
  510. return(
  511. <div className="clearfix" style={{marginTop:'0px',marginLeft:'10px'}}>
  512. <Tabs onChange={this.callbacks} type="card" activeKey={this.state.callnubs} style={{paddingLeft:'15px',paddingRight:'15px',marginRight:'20px'}}>
  513. <TabPane tab="客户营销统计表(部门)" key="1" >
  514. <DiurnalStatistics />
  515. </TabPane>
  516. <TabPane tab="客户营销统计表(员工)" key="2">
  517. <DiurnalStatisticsOne />
  518. </TabPane>
  519. </Tabs>
  520. </div>
  521. );
  522. }
  523. }));
  524. export default Tablees;