timeStatisticsOne.jsx 14 KB

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