1
0

realtimeSalesDetection.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  1. $(function () {
  2. vm.showEcharts();
  3. var date = new Date();
  4. var year = date.getFullYear();
  5. var month = ('0'+ (date.getMonth() + 1)).slice(-2);
  6. var day = ('0' + date.getDate()).slice(-2);
  7. var time = year +'-'+ month +'-'+ day;
  8. console.log('time');
  9. console.log(time);
  10. // document.getElementById('salesDate').value = time;
  11. //限制不能选择今天之后的日期(加du上属性max)
  12. document.getElementById('salesDate').setAttribute('max', time);
  13. var dateTime = date.setDate(date.getDate()-1);
  14. date=new Date(dateTime);
  15. day = ('0' + date.getDate()).slice(-2);
  16. var time3 = year +'-'+ month +'-'+ day;
  17. document.getElementById('compareDate').setAttribute('max', time3);
  18. $("#jqGrid").jqGrid({
  19. url: '../realtimeSalesDetection/query',
  20. datatype: "json",
  21. colModel: [
  22. {label: '门店编码', name: 'storeId', index: 'storeId', width: 80},
  23. {label: '门店名称', name: 'storeName', index: 'storeName', width: 120},
  24. {label: '商户编码', name: 'merchSn', index: 'storeId', width: 220},
  25. {label: '商户名称', name: 'merchName', index: 'storeName', width: 120},
  26. {label: '销售总额', name: 'totalSales', index: 'totalSales', align: 'right', width: 80},
  27. {label: '实际销售额(税前)', name: 'actualSales', index: 'actualSales', align: 'right', width: 80},
  28. // {label: '占比 %', name: 'proportion', index: 'proportion', align: 'right', width: 60},
  29. {label: '优惠损失', name: 'preferentialLoss', index: 'preferentialLoss', align: 'right', width: 80},
  30. {label: '成本总额', name: 'totalCost', index: 'totalCost', align: 'right', width: 80},
  31. {label: '毛利', name: 'grossProfit', index: 'grossProfit', align: 'right', width: 80},
  32. {label: '毛利率', name: 'grossProfitRatio', index: 'grossProfitRatio', align: 'right', width: 60},
  33. {label: '来客数', name: 'guestNumber', index: 'guestNumber', align: 'right', width: 100},
  34. {label: '客单价', name: 'guestUnitPrice', index: 'guestUnitPrice', align: 'right', width: 80},
  35. {
  36. label: '最后销售时间',
  37. name: 'lastSalesTime',
  38. index: 'lastSalesTime',
  39. align: 'center',
  40. width: 180,
  41. formatter: function (value) {
  42. return transDate(value, 'yyyy-MM-dd hh:mm:ss');
  43. }
  44. }
  45. // {label: '说明', name: 'guestUnitPrice', index: 'guestUnitPrice',align: 'right',width: 80}
  46. ],
  47. viewrecords: true,
  48. height: 200,
  49. rowNum: 10,
  50. rowList: [10, 30, 50],
  51. rownumbers: true,
  52. rownumWidth: 25,
  53. autowidth: true,
  54. shrinkToFit: false,
  55. autoScroll: true, //开启水平滚动条
  56. width: 1800,
  57. multiselect: true,
  58. pager: "#jqGridPager",
  59. jsonReader: {
  60. root: "page.list",
  61. page: "page.currPage",
  62. total: "page.totalPage",
  63. records: "page.totalCount"
  64. },
  65. prmNames: {
  66. page: "page",
  67. rows: "limit",
  68. order: "order"
  69. },
  70. gridComplete: function () {
  71. $("#jqGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "scroll"});
  72. }
  73. });
  74. });
  75. var myChart;
  76. let vm = new Vue({
  77. el: '#rrapp',
  78. data: {
  79. date: '',
  80. refreshTime: 10,
  81. type: 'store',
  82. refreshCount:0,
  83. storeId: '',
  84. merchSn: '',
  85. merchName: '',
  86. storeName: '',
  87. salesDate: '',
  88. totalSales: '',
  89. actualSales: '',
  90. preferentialLoss: '',
  91. totalCost: '',
  92. grossProfit: '',
  93. grossProfitRatio: '',
  94. proportion: '',
  95. guestNumber: '',
  96. guestUnitPrice: '',
  97. lastSalesTime: '',
  98. categoryId: '',
  99. categoryName: '',
  100. showList: false,
  101. compareDate: '',//比较日期
  102. storeId2: '',
  103. merchSn2: '',
  104. merchName2: '',
  105. storeName2: '',
  106. salesDate2: '',
  107. totalSales2: '',
  108. actualSales2: '',
  109. preferentialLoss2: '',
  110. totalCost2: '',
  111. grossProfit2: '',
  112. grossProfitRatio2: '',
  113. proportion2: '',
  114. guestNumber2: '',
  115. guestUnitPrice2: '',
  116. lastSalesTime2: '',
  117. intervalId: 0,
  118. isCompare: false,
  119. compare2: '',
  120. temp: {
  121. date: '',
  122. refreshTime: 10,
  123. type: '',
  124. storeId: '',
  125. merchSn: '',
  126. salesDate: '',
  127. categoryId: ''
  128. },
  129. rateList: [
  130. {
  131. id: '0',
  132. name: '含税'
  133. },
  134. {
  135. id: '1',
  136. name: '不含税'
  137. }
  138. ],
  139. projectList: [
  140. {
  141. id: '0',
  142. name: '销售总额'
  143. },
  144. {
  145. id: '1',
  146. name: '客单价'
  147. }
  148. ],
  149. seriesTypeList: [
  150. {
  151. id: 'bar',
  152. name: '垂直柱状图'
  153. },
  154. {
  155. id: 'line',
  156. name: '折线图'
  157. },
  158. {
  159. id: 'pie',
  160. name: '饼图'
  161. }
  162. ],
  163. formatsList: [
  164. {
  165. id: '0',
  166. name: '<全部>'
  167. },
  168. {
  169. id: '1',
  170. name: '<非全部>'
  171. }
  172. ],
  173. salesList: [
  174. {
  175. store: {storeId: '11106', storeName: '前海店'},
  176. totalSales: 43046.18,
  177. actualSales: 35593.46
  178. }
  179. ],
  180. dept: {
  181. deptId: '',
  182. deptName: ''
  183. },
  184. category: {
  185. categoryId: '',
  186. categoryName: ''
  187. },
  188. seriesList: [], //保存饼图数据
  189. seriesList2: [],
  190. xAxisList: { //主要用于保存 启动刷新时的条件和数据
  191. storeId: '',
  192. storeName: '',
  193. merchSn: '',
  194. merchName: '',
  195. totalSales: '',
  196. actualSales: '',
  197. preferentialLoss: '',
  198. totalCost: '',
  199. grossProfit: '',
  200. grossProfitRatio: '',
  201. proportion: '',
  202. guestNumber: '',
  203. guestUnitPrice: '',
  204. lastSalesTime: '',
  205. salesDate: '0',
  206. projectSelect: '0',
  207. type:''
  208. },
  209. dataList: [],
  210. tooltip: {},
  211. today:''
  212. },
  213. created() {
  214. this.rateSelect = this.rateList[0].id;
  215. this.projectSelect = this.projectList[0].id;
  216. this.seriesTypeSelect = this.seriesTypeList[0].id;
  217. this.formatsSelect = this.formatsList[0].id;
  218. },
  219. methods: {
  220. addParam: function (postParam, dateType) { //添加请求参数, dateType: 0刷新,1比较
  221. // var currentDate = new Date();
  222. // currentDate = currentDate.getFullYear()+'-'+(currentDate.getMonth()+1)+'-'+currentDate.getDate();
  223. postParam = {};
  224. if (!(Math.floor(vm.refreshTime) == vm.refreshTime && vm.refreshTime % 1 === 0 && vm.refreshTime >= 10)) {
  225. alert("刷新间隔请输入10秒以上的整数!");
  226. return false;
  227. }
  228. if (vm.type == "store") {
  229. // vm.storeId = '10'; //测试
  230. if (vm.storeId == '' || vm.storeId == null) {
  231. alert("请在输入框中输入门店编号!");
  232. return false;
  233. }
  234. postParam.storeId = vm.storeId;
  235. } else if (vm.type == "dept") {
  236. if (vm.merchSn == '' || vm.merchSn == null) {
  237. alert("请在输入框中输入部门编号!");
  238. return false;
  239. }
  240. postParam.merchSn = vm.merchSn;
  241. } else if (vm.type == "category") {
  242. if (vm.storeId == '' || vm.storeId == null) {
  243. alert("请在输入框中输入门店编号和品类编号!");
  244. return false;
  245. }
  246. if (vm.categoryId == '' || vm.categoryId == null) {
  247. alert("请在输入框中输入品类编号!");
  248. return false;
  249. }
  250. postParam.storeId = vm.storeId;
  251. postParam.categoryId = vm.categoryId;
  252. } else {
  253. alert("请选中查询条件(门店、部门、品类,选中一个)" + vm.type);
  254. return false;
  255. }
  256. //判断是刷新还是比较
  257. if (dateType == 0) {
  258. var sDate = vm.salesDate.replace(/(^\s+|\s+$)/g, '');//去两边空格;
  259. if (sDate != '') {
  260. postParam.salesDate = vm.salesDate;
  261. }
  262. } else if (dateType == 1) {
  263. var sDate = vm.compareDate.replace(/(^\s+|\s+$)/g, '');//去两边空格;
  264. if (sDate != '') {
  265. postParam.compareDate = vm.compareDate;
  266. }
  267. }
  268. // console.log('postParam');
  269. // console.log(postParam);
  270. return postParam;
  271. },
  272. refreshButton: function () {
  273. //启动刷新 设置数据标识,程序自动刷新不会设置
  274. vm.xAxisList.salesDate='';
  275. var postParam = {};
  276. postParam = vm.addParam(postParam, 0);
  277. var start = vm.refresh(postParam);
  278. console.log("start" + start);
  279. if (!start) {
  280. return;
  281. //当天日期开启定时器刷新
  282. }
  283. var currentDate = new Date();
  284. var month = currentDate.getMonth() + 1;
  285. var day = currentDate.getDate();
  286. if ((day + '').length == 1 && day < 10) {
  287. day = "0" + day;
  288. }
  289. currentDate = currentDate.getFullYear() + '-' + (month > 10 ? month : "0" + month) + '-' + day;
  290. vm.today = currentDate;
  291. console.log(vm.salesDate);
  292. console.log(currentDate);
  293. if (vm.salesDate == currentDate) {
  294. if(vm.intervalId == 0){
  295. alert("启动定时器刷新");
  296. }
  297. // vm.xAxisList.salesDate = currentDate;
  298. vm.temp = postParam;
  299. console.log(vm.temp);
  300. vm.saveFlushTime();
  301. } else {
  302. console.log("关闭定时器刷新");
  303. vm.clearFlushTime();
  304. }
  305. },
  306. refresh: function (postParam) {
  307. console.log('postParam')
  308. console.log(postParam)
  309. // postParam = vm.addParam(postParam, 0);
  310. if (!postParam) {
  311. return false;
  312. }
  313. vm.showList = true;
  314. $.ajax({
  315. url: '../realtimeSalesDetection/query',
  316. type: "POST",
  317. data: postParam,
  318. dataType: 'json',
  319. success: function (r) {
  320. //查询显示表格数据
  321. vm.showTable(postParam);
  322. r = r.page.list[0];
  323. console.log(r);
  324. if(vm.intervalId > 0){
  325. vm.refreshCount += 1; //增加刷新次数
  326. }
  327. if (r.lastSalesTime == null) {
  328. //设置第一个系列数据为''
  329. if (vm.seriesList2.length > 0) {
  330. //统计图有数据删除清空第一条
  331. vm.seriesList2[0] = '';
  332. if (vm.dataList.length > 0) {
  333. vm.dataList[0] = '[]/销售总额:元()';
  334. console.log(vm.dataList);
  335. }
  336. myChart.setOption({
  337. xAxis: {
  338. data: vm.dataList
  339. },
  340. series: [{
  341. type: vm.seriesTypeSelect,
  342. color: ['#dd6b66', '#759aa0'],
  343. data: vm.seriesList2
  344. }]
  345. });
  346. }
  347. //自动刷新不是第一次不显示提示框
  348. if(vm.xAxisList.salesDate != ''&& vm.xAxisList.salesDate == vm.today && vm.intervalId > 0){
  349. return false;
  350. }
  351. if(vm.today == vm.salesDate){
  352. vm.xAxisList.salesDate = vm.salesDate;
  353. }
  354. if (vm.type == 'dept') {
  355. alert("该部门" + vm.salesDate + "无销售记录");
  356. return false;
  357. }
  358. alert("该门店" + vm.salesDate + "无销售记录");
  359. return false;
  360. }
  361. vm.storeId = r.storeId;
  362. vm.storeName = r.storeName;
  363. vm.merchSn = r.merchSn;
  364. vm.merchName = r.merchName;
  365. vm.totalSales = r.totalSales;
  366. vm.actualSales = r.actualSales;
  367. vm.preferentialLoss = r.preferentialLoss;
  368. vm.totalCost = r.totalCost;
  369. vm.grossProfit = r.grossProfit;
  370. vm.grossProfitRatio = r.grossProfitRatio;
  371. vm.proportion = r.proportion;
  372. vm.guestNumber = r.guestNumber;
  373. vm.guestUnitPrice = r.guestUnitPrice;
  374. vm.lastSalesTime = r.lastSalesTime;
  375. vm.xAxisList.totalSales = r.totalSales;
  376. vm.xAxisList.actualSales = r.actualSales;
  377. vm.xAxisList.preferentialLoss = r.preferentialLoss;
  378. vm.xAxisList.totalCost = r.totalCost;
  379. vm.xAxisList.grossProfit = r.grossProfit;
  380. vm.xAxisList.grossProfitRatio = r.grossProfitRatio;
  381. vm.xAxisList.proportion = r.proportion;
  382. vm.xAxisList.guestNumber = r.guestNumber;
  383. vm.xAxisList.guestUnitPrice = r.guestUnitPrice;
  384. vm.xAxisList.lastSalesTime = r.lastSalesTime;
  385. if(vm.xAxisList.salesDate == ''){ //手动刷新会重置vm.xAxisList.salesDate为 ''
  386. vm.xAxisList.storeId = r.storeId;
  387. vm.xAxisList.storeName = r.storeName;
  388. vm.xAxisList.merchSn = r.merchSn;
  389. vm.xAxisList.merchName = r.merchName;
  390. vm.xAxisList.totalSales = r.totalSales;
  391. vm.xAxisList.actualSales = r.actualSales;
  392. vm.xAxisList.preferentialLoss = r.preferentialLoss;
  393. vm.xAxisList.totalCost = r.totalCost;
  394. vm.xAxisList.grossProfit = r.grossProfit;
  395. vm.xAxisList.grossProfitRatio = r.grossProfitRatio;
  396. vm.xAxisList.proportion = r.proportion;
  397. vm.xAxisList.guestNumber = r.guestNumber;
  398. vm.xAxisList.guestUnitPrice = r.guestUnitPrice;
  399. vm.xAxisList.lastSalesTime = r.lastSalesTime;
  400. vm.xAxisList.salesDate = vm.salesDate;
  401. vm.xAxisList.projectSelect = vm.projectSelect;
  402. vm.xAxisList.type = vm.type;
  403. }
  404. vm.seriesList = [];
  405. vm.seriesList2 = []; //清空 系列 数据
  406. vm.showEcharts();
  407. if(vm.isCompare){ //有比较记录再调用刷新一次数据渲染至画布上
  408. vm.compare('1');
  409. }
  410. }
  411. });
  412. return true;
  413. },
  414. compare: function (c) {
  415. if(c == '1'){ //程序调用
  416. if(vm.compare2 == ''){
  417. return;
  418. }
  419. vm.compareDate = vm.compare2;
  420. console.log("compare")
  421. if (vm.seriesList2.length > 1) {
  422. //删除并替换
  423. if (vm.projectSelect == '0') {
  424. vm.seriesList2.splice(1, 1, vm.totalSales2);
  425. if (vm.xAxisList.type == 'dept') {
  426. vm.dataList.splice(1, 1, '[' + vm.merchSn + ']' + vm.merchName2 + '/销售总额:' + vm.totalSales2 + '元(' + vm.salesDate2 + ')');
  427. } else {
  428. vm.dataList.splice(1, 1, '[' + vm.storeId + ']' + vm.storeName2 + '/销售总额:' + vm.totalSales2 + '元(' + vm.salesDate2 + ')');
  429. }
  430. // pie 设置
  431. vm.seriesList.splice(1, 1, {value: vm.totalSales2, name: vm.dataList[1]});
  432. } else if (vm.projectSelect == '1') {
  433. vm.seriesList2.splice(1, 1, vm.guestUnitPrice);
  434. if (vm.xAxisList.type == 'dept') {
  435. vm.dataList.splice(1, 1, '[' + vm.merchSn + ']' + vm.merchName2 + '/客单价:' + vm.guestUnitPrice2 + '元(' + vm.salesDate2 + ')');
  436. } else {
  437. vm.dataList.splice(1, 1, '[' + vm.storeId + ']' + vm.storeName2 + '/客单价:' + vm.guestUnitPrice2 + '元(' + vm.salesDate2 + ')');
  438. }
  439. // pie 设置
  440. vm.seriesList.splice(1, 1, {value: vm.guestUnitPrice2, name: vm.dataList[1]});
  441. }
  442. console.log("compare seriesList")
  443. console.log(vm.seriesList)
  444. }
  445. else {
  446. if (vm.projectSelect == '0') {
  447. vm.seriesList2.push(vm.totalSales2);
  448. if (vm.xAxisList.type == 'dept') {
  449. vm.dataList.push('[' + vm.merchSn + ']' + vm.merchName2 + '/销售总额:' + vm.totalSales2 + '元(' + vm.salesDate2 + ')');
  450. } else {
  451. vm.dataList.push('[' + vm.storeId + ']' + vm.storeName2 + '/销售总额:' + vm.totalSales2 + '元(' + vm.salesDate2 + ')');
  452. }
  453. // pie 设置
  454. vm.seriesList.push({value: vm.totalSales2, name: vm.dataList[1]});
  455. } else if (vm.projectSelect == '1') {
  456. vm.seriesList2.push(vm.guestUnitPrice2);
  457. if (vm.xAxisList.type== 'dept') {
  458. vm.dataList.push('[' + vm.merchSn + ']' + vm.merchName2 + '/客单价:' + vm.guestUnitPrice2 + '元(' + vm.salesDate2 + ')');
  459. } else {
  460. vm.dataList.push('[' + vm.storeId + ']' + vm.storeName2 + '/客单价:' + vm.guestUnitPrice2 + '元(' + vm.salesDate2 + ')');
  461. }
  462. // pie 设置
  463. vm.seriesList.push({value: vm.guestUnitPrice2, name: vm.dataList[1]});
  464. }
  465. }
  466. if (vm.seriesTypeSelect == "pie") {
  467. vm.seriesList2 = vm.seriesList.concat();
  468. console.log("compare pie")
  469. console.log(vm.seriesList2)
  470. }
  471. myChart.setOption({
  472. xAxis: {
  473. data: vm.dataList
  474. },
  475. series: [{
  476. type: vm.seriesTypeSelect,
  477. color: ['#dd6b66', '#759aa0'],
  478. data: vm.seriesList2
  479. }]
  480. });
  481. return;
  482. }else{ //手动比较
  483. vm.refreshButton();
  484. vm.isCompare = true;
  485. vm.compare2 = vm.compareDate;
  486. }
  487. // vm.switchProjectView();
  488. var postParam = {};
  489. postParam = vm.addParam(postParam, 1);
  490. if (!postParam) {
  491. return;
  492. }
  493. $.ajax({
  494. url: '../realtimeSalesDetection/query',
  495. type: "POST",
  496. data: postParam,
  497. dataType: 'json',
  498. success: function (r) {
  499. console.log(r);
  500. r = r.page.list[0];
  501. console.log(r);
  502. if (r.lastSalesTime == null) {
  503. vm.compare2 = '';
  504. console.log(vm.seriesList2.length)
  505. console.log('vm.seriesList2.length')
  506. console.log(vm.seriesList2)
  507. if (vm.seriesList2.length > 1) {
  508. //统计图有两条数据删除一条
  509. vm.seriesList2.pop();
  510. console.log(vm.seriesList2)
  511. if (vm.dataList.length > 1) {
  512. vm.dataList.pop();
  513. console.log('vm.dataList')
  514. console.log(vm.dataList)
  515. }
  516. myChart.setOption({
  517. xAxis: {
  518. data: vm.dataList
  519. },
  520. series: [{
  521. type: vm.seriesTypeSelect,
  522. color: ['#dd6b66', '#759aa0'],
  523. data: vm.seriesList2
  524. }]
  525. });
  526. }
  527. if (vm.type == 'dept') {
  528. alert("该部门" + vm.compareDate + "无销售记录");
  529. return;
  530. }
  531. alert("该门店" + vm.compareDate + "无销售记录");
  532. return;
  533. }
  534. vm.storeId2 = r.storeId;
  535. vm.merchSn2 = r.merchSn;
  536. vm.merchName2 = r.merchName;
  537. vm.storeName2 = r.storeName;
  538. vm.salesDate2 = vm.compareDate;
  539. vm.totalSales2 = r.totalSales;
  540. vm.actualSales2 = r.actualSales;
  541. vm.preferentialLoss2 = r.preferentialLoss;
  542. vm.totalCost2 = r.totalCost;
  543. vm.grossProfit2 = r.grossProfit;
  544. vm.grossProfitRatio2 = r.grossProfitRatio;
  545. vm.proportion2 = r.proportion;
  546. vm.guestNumber2 = r.guestNumber;
  547. vm.guestUnitPrice2 = r.guestUnitPrice;
  548. vm.lastSalesTime2 = r.lastSalesTime;
  549. if (vm.seriesList2.length > 1) {
  550. //删除并替换
  551. if (vm.projectSelect == '0') {
  552. vm.seriesList2.splice(1, 1, vm.totalSales2);
  553. if (vm.xAxisList.type== 'dept') {
  554. vm.dataList.splice(1, 1, '[' + vm.merchSn + ']' + vm.merchName2 + '/销售总额:' + vm.totalSales2 + '元(' + vm.salesDate2 + ')');
  555. } else {
  556. vm.dataList.splice(1, 1, '[' + vm.storeId + ']' + vm.storeName2 + '/销售总额:' + vm.totalSales2 + '元(' + vm.salesDate2 + ')');
  557. }
  558. // pie 设置
  559. vm.seriesList.splice(1, 1, {value: vm.totalSales2, name: vm.dataList[1]});
  560. } else if (vm.projectSelect == '1') {
  561. vm.seriesList2.splice(1, 1, vm.guestUnitPrice);
  562. if (vm.xAxisList.type== 'dept') {
  563. vm.dataList.splice(1, 1, '[' + vm.merchSn + ']' + vm.merchName2 + '/客单价:' + vm.guestUnitPrice2 + '元(' + vm.salesDate2 + ')');
  564. } else {
  565. vm.dataList.splice(1, 1, '[' + vm.storeId + ']' + vm.storeName2 + '/客单价:' + vm.guestUnitPrice2 + '元(' + vm.salesDate2 + ')');
  566. }
  567. // pie 设置
  568. vm.seriesList.splice(1, 1, {value: vm.guestUnitPrice2, name: vm.dataList[1]});
  569. }
  570. } else {
  571. if (vm.projectSelect == '0') {
  572. vm.seriesList2.push(vm.totalSales2);
  573. if (vm.xAxisList.type== 'dept') {
  574. vm.dataList.push('[' + vm.merchSn + ']' + vm.merchName2 + '/销售总额:' + vm.totalSales2 + '元(' + vm.salesDate2 + ')');
  575. } else {
  576. vm.dataList.push('[' + vm.storeId + ']' + vm.storeName2 + '/销售总额:' + vm.totalSales2 + '元(' + vm.salesDate2 + ')');
  577. }
  578. // pie 设置
  579. vm.seriesList.push({value: vm.totalSales2, name: vm.dataList[1]});
  580. } else if (vm.projectSelect == '1') {
  581. vm.seriesList2.push(vm.guestUnitPrice2);
  582. if (vm.xAxisList.type== 'dept') {
  583. vm.dataList.push('[' + vm.merchSn + ']' + vm.merchName2 + '/客单价:' + vm.guestUnitPrice2 + '元(' + vm.salesDate2 + ')');
  584. } else {
  585. vm.dataList.push('[' + vm.storeId + ']' + vm.storeName2 + '/客单价:' + vm.guestUnitPrice2 + '元(' + vm.salesDate2 + ')');
  586. }
  587. // pie 设置
  588. vm.seriesList.push({value: vm.guestUnitPrice2, name: vm.dataList[1]});
  589. }
  590. }
  591. if (vm.seriesTypeSelect == "pie") {
  592. vm.seriesList2 = vm.seriesList.concat();
  593. // console.log("ppp")
  594. }
  595. // console.log("seriesList2")
  596. // console.log(vm.seriesList2)
  597. myChart.setOption({
  598. xAxis: {
  599. data: vm.dataList
  600. },
  601. series: [{
  602. type: vm.seriesTypeSelect,
  603. color: ['#dd6b66', '#759aa0'],
  604. data: vm.seriesList2
  605. }]
  606. });
  607. }
  608. });
  609. },
  610. saveFlushTime: function (postParam) {
  611. console.log('typeof vm.refreshTime');
  612. console.log(typeof vm.refreshTime);
  613. console.log(vm.temp);
  614. window.clearInterval(vm.intervalId);
  615. vm.intervalId = window.setInterval('vm.refresh(vm.temp)', vm.refreshTime * 1000)
  616. },
  617. clearFlushTime: function () {
  618. window.clearInterval(vm.intervalId);
  619. if(vm.intervalId > 0){
  620. alert("停止刷新");
  621. }
  622. vm.intervalId = 0;
  623. vm.refreshCount=0;
  624. },
  625. seriesTypeSwitch: function () {
  626. console.log(vm.seriesTypeSelect);
  627. },
  628. showEcharts: function () {
  629. // 基于准备好的dom,初始化echarts实例
  630. myChart = echarts.init(document.getElementById('main'));
  631. myChart.clear();
  632. //加载动画
  633. myChart.showLoading();
  634. //项目下拉框判断 6-19,饼图设置 vm.xAxisList
  635. var temp = '';
  636. if (vm.xAxisList.projectSelect == '0') {
  637. if (vm.xAxisList.type == 'dept') {
  638. temp = '[' + vm.xAxisList.merchSn + ']' + vm.xAxisList.merchName + '/销售总额:' + vm.xAxisList.totalSales + '元(' + vm.xAxisList.salesDate + ')';
  639. } else {
  640. temp = '[' + vm.xAxisList.storeId + ']' + vm.xAxisList.storeName + '/销售总额:' + vm.xAxisList.totalSales + '元(' + vm.xAxisList.salesDate + ')';
  641. }
  642. vm.seriesList2.push(vm.xAxisList.totalSales);
  643. vm.seriesList.push({value: vm.xAxisList.totalSales, name: temp});
  644. } else if (vm.xAxisList.projectSelect == '1') {
  645. if (vm.xAxisList.type == 'dept') {
  646. temp = '[' + vm.xAxisList.merchSn + ']' + vm.xAxisList.merchName + '/客单价:' + vm.xAxisList.guestUnitPrice + '元(' + vm.xAxisList.salesDate + ')';
  647. } else {
  648. temp = '[' + vm.xAxisList.storeId + ']' + vm.xAxisList.storeName + '/客单价:' + vm.xAxisList.guestUnitPrice + '元(' + vm.xAxisList.salesDate + ')';
  649. }
  650. vm.seriesList2.push(vm.xAxisList.guestUnitPrice);
  651. vm.seriesList.push({value: vm.xAxisList.guestUnitPrice, name: temp});
  652. }
  653. // if (vm.projectSelect == '0') {
  654. // if (vm.xAxisList.type== 'dept') {
  655. // temp = '[' + vm.merchSn + ']' + vm.merchName + '/销售总额:' + vm.totalSales + '元(' + vm.salesDate + ')';
  656. // } else {
  657. // temp = '[' + vm.storeId + ']' + vm.storeName + '/销售总额:' + vm.totalSales + '元(' + vm.salesDate + ')';
  658. // }
  659. // vm.seriesList2.push(vm.totalSales);
  660. // vm.seriesList.push({value: vm.totalSales, name: temp});
  661. //
  662. // } else if (vm.projectSelect == '1') {
  663. // if (vm.xAxisList.type== 'dept') {
  664. // temp = '[' + vm.merchSn + ']' + vm.merchName + '/客单价:' + vm.guestUnitPrice + '元(' + vm.salesDate + ')';
  665. // } else {
  666. // temp = '[' + vm.storeId + ']' + vm.storeName + '/客单价:' + vm.guestUnitPrice + '元(' + vm.salesDate + ')';
  667. // }
  668. // vm.seriesList2.push(vm.guestUnitPrice);
  669. // vm.seriesList.push({value: vm.guestUnitPrice, name: temp});
  670. //
  671. // }
  672. vm.dataList = [temp];
  673. if (vm.seriesTypeSelect == "pie") {
  674. vm.seriesList2 = vm.seriesList.concat();
  675. }
  676. // console.log('vm.seriesList2');
  677. // console.log(vm.seriesList2);
  678. // 指定图表的配置项和数据
  679. //销售量
  680. var option = {
  681. title: {
  682. // textAlign: 'right',
  683. text: '实时销售统计图',
  684. x: 'center',
  685. textStyle: {
  686. //文字颜色
  687. color: '#17233d',
  688. //字体风格,'normal','italic','oblique'
  689. fontStyle: 'normal',
  690. //字体粗细 'normal','bold','bolder','lighter',100 | 200 | 300 | 400...
  691. fontWeight: 'bold',
  692. //字体系列
  693. fontFamily: 'sans-serif',
  694. //字体大小
  695. fontSize: 28
  696. }
  697. },
  698. tooltip: {
  699. formatter: function (params) {
  700. return params.name;
  701. }
  702. },
  703. legend: {
  704. data: ['/销售总额']
  705. },
  706. xAxis: {
  707. data: vm.dataList,
  708. axisLabel: {
  709. interval: 0
  710. }
  711. },
  712. yAxis: {},
  713. series: [{
  714. barMaxWidth: '20%',
  715. barWidth: '50%',
  716. radius: '55%',
  717. roseType: 'angle',
  718. type: vm.seriesTypeSelect,
  719. color: ['#dd6b66', '#759aa0'],
  720. data: vm.seriesList2
  721. }]
  722. };
  723. //隐藏
  724. myChart.hideLoading();
  725. // 使用刚指定的配置项和数据显示图表。
  726. myChart.setOption(option);
  727. },
  728. tooltipFormatter: function () {
  729. if (vm.type == 'dept') {
  730. return '[' + vm.merchSn + ']' + vm.merchName + '/销售总额:' + vm.totalSales + '元(' + vm.salesDate + ')';
  731. }
  732. return '[' + vm.storeId + ']' + vm.storeName + '/销售总额:' + vm.totalSales + '元(' + vm.salesDate + ')';
  733. },
  734. showTable: function (postParam) {
  735. console.log(postParam);
  736. $("#jqGrid").jqGrid('setGridParam', {
  737. postData: postParam
  738. }).trigger("reloadGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "scroll"});
  739. },
  740. switchProjectView: function () {
  741. console.log(vm.projectSelect);
  742. }
  743. }
  744. });