timeStatisticsOne.jsx 15 KB

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