1
0

realtimeSalesDetection.js 33 KB

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