timeStatisticsOne.jsx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  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. timeTypes:timeTypes
  14. });
  15. $.ajax({
  16. method: "get",
  17. dataType: "json",
  18. crossDomain: false,
  19. url: globalConfig.context + "/api/admin/report/sales/sometimeMarketingStatistics",
  20. data: {
  21. type:'0',
  22. timeType:this.state.releaseDate[0]?4:timeTypes,
  23. startTime: this.state.releaseDate[0],
  24. endTime: this.state.releaseDate[1],
  25. depId:this.state.superId,//部门机构
  26. },
  27. success: function(data) {
  28. let thedata = data.data;
  29. let theArr = [];
  30. if(!thedata) {
  31. if(data.error && data.error.length) {
  32. message.warning(data.error[0].message);
  33. };
  34. thedata = {};
  35. } else {
  36. thedata.map(function(item, index) {
  37. let nub=index+1;
  38. theArr.push({
  39. key: index,
  40. theNumber:false,
  41. nub:nub,
  42. id: item.id,
  43. name:item.name,//员工姓名
  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. name:'合计',
  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:'0',
  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('#daochu1');
  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. weekColor:true,
  262. monthColor:false,
  263. quarterColor:false,
  264. yearColor:false,
  265. Dtime:undefined,
  266. timeTypes:0,
  267. selTime:'',
  268. columns: [
  269. {
  270. title: '序号',
  271. dataIndex: 'nub',
  272. width:50,
  273. key: 'nub',
  274. fixed:false,
  275. render:(text,record)=>{
  276. if(!record.theNumber){
  277. return text
  278. }else{
  279. return {
  280. children: text,
  281. props: {
  282. colSpan:0
  283. },
  284. }
  285. }
  286. }
  287. },{
  288. title: '姓名',
  289. fixed:false,
  290. dataIndex: 'name',
  291. key: 'name',
  292. render:(text,record)=>{
  293. if(!record.theNumber){
  294. return text
  295. }else{
  296. return {
  297. children: text,
  298. props: {
  299. colSpan:4
  300. },
  301. }
  302. }
  303. }
  304. },
  305. {
  306. title: '部门',
  307. dataIndex: 'departmentName',
  308. key: 'departmentName',
  309. fixed:false,
  310. width:230,
  311. render:(text,record)=>{
  312. if(!record.theNumber){
  313. return text//&&text.length>6?<span title={text}>{text.substr(0,6)+'…'}</span>:text
  314. }else{
  315. return {
  316. children: text,
  317. props: {
  318. colSpan:0
  319. },
  320. }
  321. }
  322. }
  323. },{
  324. title: '职位',
  325. fixed:false,
  326. dataIndex: 'roleName',
  327. key: 'roleName',
  328. render:(text,record)=>{
  329. if(!record.theNumber){
  330. return text
  331. }else{
  332. return {
  333. children: text,
  334. props: {
  335. colSpan:0
  336. },
  337. }
  338. }
  339. }
  340. },
  341. {
  342. title: '营销总量',
  343. fixed:false,
  344. dataIndex: 'countFollowNo',
  345. key: 'countFollowNo',
  346. sorter: (a, b) => a.countFollowNo - b.countFollowNo,
  347. render:(text,record)=>{
  348. if(!record.theNumber){
  349. return text
  350. }else{
  351. return {
  352. children: text,
  353. props: {
  354. colSpan:1
  355. },
  356. }
  357. }
  358. }
  359. },
  360. {
  361. title: '电话量',
  362. fixed:false,
  363. dataIndex: 'countTelNo',
  364. key: 'countTelNo',
  365. sorter: (a, b) => a.countTelNo - b.countTelNo,
  366. render:(text,record)=>{
  367. if(!record.theNumber){
  368. return text
  369. }else{
  370. return {
  371. children: text,
  372. props: {
  373. colSpan:1
  374. },
  375. }
  376. }
  377. }
  378. },
  379. {
  380. title: '外拜量',
  381. fixed:false,
  382. dataIndex: 'countVisitNo',
  383. key: 'countVisitNo',
  384. sorter: (a, b) => a.countVisitNo - b.countVisitNo,
  385. render:(text,record)=>{
  386. if(!record.theNumber){
  387. return text
  388. }else{
  389. return {
  390. children: text,
  391. props: {
  392. colSpan:1
  393. },
  394. }
  395. }
  396. }
  397. },
  398. {
  399. title: '营销日均量',
  400. fixed:false,
  401. dataIndex: 'dayAVG',
  402. key: 'dayAVG',
  403. sorter: (a, b) => a.dayAVG - b.dayAVG,
  404. render:(text,record)=>{
  405. if(!record.theNumber){
  406. return text
  407. }else{
  408. return {
  409. children: text,
  410. props: {
  411. colSpan:1
  412. },
  413. }
  414. }
  415. }
  416. }
  417. ],
  418. dataSource: [],
  419. };
  420. },
  421. search() {
  422. this.totalData(this.state.timeTypes);
  423. },
  424. reset() {
  425. this.state.superId = undefined;//部门机构清零
  426. this.totalData(0);
  427. },
  428. week(){
  429. this.state.releaseDate[0] = undefined;//开始时间清零
  430. this.state.releaseDate[1] = undefined;//结束时间清零
  431. this.totalData(0);
  432. this.setState({
  433. weekColor:true,
  434. monthColor:false,
  435. quarterColor:false,
  436. yearColor:false
  437. })
  438. },
  439. month(){
  440. this.state.releaseDate[0] = undefined;//开始时间清零
  441. this.state.releaseDate[1] = undefined;//结束时间清零
  442. this.totalData(1);
  443. this.setState({
  444. weekColor:false,
  445. monthColor:true,
  446. quarterColor:false,
  447. yearColor:false
  448. })
  449. },
  450. quarter(){
  451. this.state.releaseDate[0] = undefined;//开始时间清零
  452. this.state.releaseDate[1] = undefined;//结束时间清零
  453. this.totalData(2);
  454. this.setState({
  455. weekColor:false,
  456. monthColor:false,
  457. quarterColor:true,
  458. yearColor:false
  459. })
  460. },
  461. year(){
  462. this.state.releaseDate[0] = undefined;//开始时间清零
  463. this.state.releaseDate[1] = undefined;//结束时间清零
  464. this.totalData(3);
  465. this.setState({
  466. weekColor:false,
  467. monthColor:false,
  468. quarterColor:false,
  469. yearColor:true
  470. })
  471. },
  472. componentWillMount() {
  473. this.totalData(0);
  474. let times=new Date();
  475. let nowTime=times.getFullYear()+'年'+(times.getMonth()+1)+'月'+times.getDate()+'日';
  476. this.setState({
  477. Nowtime:nowTime
  478. })
  479. },
  480. render() {
  481. const { RangePicker } = DatePicker;
  482. let departmentArr = this.state.departmentArr || [];
  483. return(
  484. <div className='set-content'>
  485. <p style={{fontSize:'20px',marginBottom:'10px'}}>客户营销统计表(员工)</p>
  486. <div className="clearfix">
  487. <Button type="primary" onClick={this.tabExel} style={{float:'right'}}>导出到表格</Button>
  488. <span style={{fontSize:'16px'}}>部门机构 : </span>
  489. <Select placeholder="选择部门"
  490. style={{ width:'200px',marginRight:'10px' }}
  491. value={this.state.superId}
  492. onChange={(e) => { this.setState({ superId: e }) }} notFoundContent="未获取到上级组织列表">
  493. {this.state.contactsOption}
  494. </Select>
  495. <Button onClick={this.week} style={{marginRight:'5px'}} type={this.state.weekColor?"primary":''}>本周</Button>
  496. <Button onClick={this.month} style={{marginRight:'5px'}} type={this.state.monthColor?"primary":''}>本月</Button>
  497. <Button onClick={this.quarter} style={{marginRight:'5px'}} type={this.state.quarterColor?"primary":''}>本季</Button>
  498. <Button onClick={this.year} style={{marginRight:'5px'}} type={this.state.yearColor?"primary":''}>本年</Button>
  499. <span className="titleTime" style={{marginRight:'5px'}}>起止时间:</span>
  500. <RangePicker
  501. value={[this.state.releaseDate[0] ? moment(this.state.releaseDate[0]) : null,
  502. this.state.releaseDate[1] ? moment(this.state.releaseDate[1]) : null]}
  503. onChange={(data, dataString) => { this.setState({ releaseDate: dataString }); }} />
  504. <Button type="primary" onClick={this.search} style={{marginLeft:'10px',marginRight:'10px'}}>搜索</Button>
  505. <Button onClick={this.reset}>重置</Button>
  506. </div>
  507. <div id='daochu1'>
  508. <div className="surfaceTitle">
  509. <span>客户营销统计表(员工)</span>
  510. </div>
  511. <div className="patent-table">
  512. <div className="scroll">
  513. <Spin spinning={this.state.loading}>
  514. <Table columns={this.state.columns}
  515. dataSource={this.state.dataSource}
  516. bordered
  517. pagination={false}
  518. />
  519. </Spin>
  520. </div>
  521. </div>
  522. </div>
  523. </div>
  524. )
  525. }
  526. });
  527. export default DiurnalStatisticsOne;