timeStatisticsOne.jsx 14 KB

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