diurnalStatisticsOne.jsx 15 KB

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