realtimeSalesDetection.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. $(function () {
  2. vm.showEcharts();
  3. console.log(1);
  4. $("#jqGrid").jqGrid({
  5. url:'../realtimeSalesDetection/query',
  6. datatype: "json",
  7. colModel: [
  8. {label: '门店编码', name: 'storeId', index: 'storeId', width: 80},
  9. {label: '门店名称', name: 'storeName', index: 'storeName', width: 120},
  10. {label: '商户编码', name: 'merchSn', index: 'storeId', width: 220},
  11. {label: '商户名称', name: 'merchName', index: 'storeName', width: 120},
  12. {label: '售价总额', name: 'totalSales', index: 'totalSales',align: 'right',width: 80},
  13. {label: '实际销售额', name: 'actualSales', index: 'actualSales',align: 'right',width: 80},
  14. {label: '占比 %', name: 'proportion', index: 'proportion',align: 'right',width: 60},
  15. {label: '优惠损失', name: 'preferentialLoss', index: 'preferentialLoss',align: 'right',width: 80},
  16. {label: '成本总额', name: 'totalCost', index: 'totalCost',align: 'right',width: 80},
  17. {label: '毛利', name: 'grossProfit', index: 'grossProfit',align: 'right',width: 80},
  18. {label: '毛利率', name: 'grossProfitRatio', index: 'grossProfitRatio',align: 'right',width: 60},
  19. {label: '来客数', name: 'guestNumber', index: 'guestNumber',align: 'right',width: 100},
  20. {label: '客单价', name: 'guestUnitPrice', index: 'guestUnitPrice',align: 'right',width: 80},
  21. {label: '最后销售时间', name: 'lastSalesTime', index: 'lastSalesTime', align: 'center',width: 180,formatter: function (value) {
  22. return transDate(value,'yyyy-MM-dd hh:mm:ss');
  23. }}
  24. // {label: '说明', name: 'guestUnitPrice', index: 'guestUnitPrice',align: 'right',width: 80}
  25. ],
  26. viewrecords: true,
  27. height: 200,
  28. rowNum: 10,
  29. rowList: [10, 30, 50],
  30. rownumbers: true,
  31. rownumWidth: 25,
  32. autowidth: true,
  33. shrinkToFit: false,
  34. autoScroll: true, //开启水平滚动条
  35. width: 1500,
  36. multiselect: true,
  37. pager: "#jqGridPager",
  38. jsonReader: {
  39. root: "page.list",
  40. page: "page.currPage",
  41. total: "page.totalPage",
  42. records: "page.totalCount"
  43. },
  44. prmNames: {
  45. page: "page",
  46. rows: "limit",
  47. order: "order"
  48. },
  49. gridComplete: function () {
  50. $("#jqGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "scroll"});
  51. }
  52. });
  53. });
  54. var myChart ;
  55. let vm = new Vue({
  56. el: '#rrapp',
  57. data: {
  58. date: '',
  59. refreshTime: 10,
  60. type: 'store',
  61. storeId: '',
  62. merchSn: '',
  63. merchName: '',
  64. storeName: '',
  65. salesDate: '',
  66. totalSales: '',
  67. actualSales: '',
  68. preferentialLoss: '',
  69. totalCost: '',
  70. grossProfit: '',
  71. grossProfitRatio: '',
  72. proportion: '',
  73. guestNumber: '',
  74. guestUnitPrice: '',
  75. lastSalesTime: '',
  76. categoryId: '',
  77. categoryName: '',
  78. showList:false ,
  79. compareDate: '',//比较日期
  80. storeId2: '',
  81. merchSn2: '',
  82. merchName2: '',
  83. storeName2: '',
  84. salesDate2: '',
  85. totalSales2: '',
  86. actualSales2: '',
  87. preferentialLoss2: '',
  88. totalCost2: '',
  89. grossProfit2: '',
  90. grossProfitRatio2: '',
  91. proportion2: '',
  92. guestNumber2: '',
  93. guestUnitPrice2: '',
  94. lastSalesTime2: '',
  95. intervalId:0,
  96. rateList: [
  97. {
  98. id: '0',
  99. name: '含税'
  100. },
  101. {
  102. id: '1',
  103. name: '不含税'
  104. }
  105. ],
  106. projectList: [
  107. {
  108. id: '0',
  109. name: '售价总额'
  110. },
  111. {
  112. id: '1',
  113. name: '客单价'
  114. }
  115. ],
  116. seriesTypeList: [
  117. {
  118. id: 'bar',
  119. name: '垂直柱状图'
  120. },
  121. {
  122. id: 'line',
  123. name: '折线图'
  124. },
  125. {
  126. id: 'pie',
  127. name: '饼图'
  128. }
  129. ],
  130. formatsList: [
  131. {
  132. id: '0',
  133. name: '<全部>'
  134. },
  135. {
  136. id: '1',
  137. name: '<非全部>'
  138. }
  139. ],
  140. salesList: [
  141. {
  142. store: {storeId: '11106', storeName: '前海店'},
  143. totalSales: 43046.18,
  144. actualSales: 35593.46
  145. }
  146. ],
  147. dept: {
  148. deptId:'',
  149. deptName:''
  150. },
  151. category: {
  152. categoryId:'',
  153. categoryName: ''
  154. },
  155. seriesList:[], //保存饼图数据
  156. seriesList2:[],
  157. xAxisList:[],
  158. dataList: [],
  159. tooltip:{}
  160. },
  161. created() {
  162. this.rateSelect = this.rateList[0].id;
  163. this.projectSelect = this.projectList[0].id;
  164. this.seriesTypeSelect = this.seriesTypeList[0].id;
  165. this.formatsSelect = this.formatsList[0].id;
  166. },
  167. methods: {
  168. addParam:function(postParam,dateType){ //添加请求参数, dateType: 0刷新,1比较
  169. // var currentDate = new Date();
  170. // currentDate = currentDate.getFullYear()+'-'+(currentDate.getMonth()+1)+'-'+currentDate.getDate();
  171. postParam={};
  172. if(vm.type=="store"){
  173. // vm.storeId = '10'; //测试
  174. if(vm.storeId==''||vm.storeId==null){
  175. alert("请在输入框中输入门店编号!");
  176. return false;
  177. }
  178. postParam.storeId = vm.storeId;
  179. }else if(vm.type=="dept"){
  180. if(vm.merchSn==''||vm.merchSn==null){
  181. alert("请在输入框中输入部门编号!");
  182. return false;
  183. }
  184. postParam.merchSn = vm.merchSn;
  185. }else if(vm.type=="category"){
  186. if(vm.storeId==''||vm.storeId==null){
  187. alert("请在输入框中输入门店编号和品类编号!");
  188. return false;
  189. }
  190. if(vm.categoryId==''||vm.categoryId==null){
  191. alert("请在输入框中输入品类编号!");
  192. return false;
  193. }
  194. postParam.storeId = vm.storeId;
  195. postParam.categoryId = vm.categoryId;
  196. }else{
  197. alert("请选中查询条件(门店、部门、品类,选中一个)"+vm.type);
  198. return false;
  199. }
  200. //判断是刷新还是比较
  201. if(dateType==0){
  202. var sDate=vm.salesDate.replace(/(^\s+|\s+$)/g,'');//去两边空格;
  203. if(sDate!=''){
  204. postParam.salesDate = vm.salesDate;
  205. }
  206. }else if(dateType==1){
  207. var sDate=vm.compareDate.replace(/(^\s+|\s+$)/g,'');//去两边空格;
  208. if(sDate!=''){
  209. postParam.compareDate = vm.compareDate;
  210. }
  211. }
  212. // console.log('postParam');
  213. // console.log(postParam);
  214. return postParam;
  215. },
  216. refresh: function () {
  217. var postParam={};
  218. postParam = vm.addParam(postParam,0);
  219. if(!postParam){
  220. return;
  221. }
  222. vm.showList = true;
  223. $.ajax({
  224. url:'../realtimeSalesDetection/query',
  225. type:"POST",
  226. data:postParam,
  227. dataType:'json',
  228. success:function(r){
  229. //查询显示表格数据
  230. vm.showTable(postParam);
  231. r = r.page.list[0];
  232. console.log(r);
  233. if(r.lastSalesTime == null){
  234. if(vm.type == 'dept'){
  235. alert("该部门"+vm.salesDate+"无销售记录");
  236. return;
  237. }
  238. alert("该门店"+vm.salesDate+"无销售记录");
  239. return;
  240. }
  241. vm.storeId = r.storeId;
  242. vm.storeName = r.storeName;
  243. vm.merchSn = r.merchSn;
  244. vm.merchName = r.merchName;
  245. vm.totalSales = r.totalSales;
  246. vm.actualSales = r.actualSales;
  247. vm.preferentialLoss = r.preferentialLoss;
  248. vm.totalCost = r.totalCost;
  249. vm.grossProfit = r.grossProfit;
  250. vm.grossProfitRatio = r.grossProfitRatio;
  251. vm.proportion = r.proportion;
  252. vm.guestNumber = r.guestNumber;
  253. vm.guestUnitPrice = r.guestUnitPrice;
  254. vm.lastSalesTime = r.lastSalesTime;
  255. vm.seriesList=[];
  256. vm.seriesList2 =[]; //清空 系列 数据
  257. vm.showEcharts();
  258. }
  259. });
  260. },
  261. compare: function () {
  262. if(vm.seriesList2.length <1){
  263. alert("请先刷新一条数据再比较!");
  264. return;
  265. }
  266. vm.switchProjectView();
  267. var postParam={};
  268. postParam = vm.addParam(postParam,1);
  269. if(!postParam){
  270. return;
  271. }
  272. $.ajax({
  273. url:'../realtimeSalesDetection/query',
  274. type:"POST",
  275. data:postParam,
  276. dataType:'json',
  277. success:function(r){
  278. console.log(r);
  279. r = r.page.list[0];
  280. console.log(r);
  281. if(r.lastSalesTime == null){
  282. if(vm.type == 'dept'){
  283. alert("该部门"+vm.compareDate+"无销售记录");
  284. return;
  285. }
  286. alert("该门店"+vm.compareDate+"无销售记录");
  287. return;
  288. }
  289. vm.storeId2 = r.storeId;
  290. vm.merchSn2 = r.merchSn;
  291. vm.merchName2 = r.merchName;
  292. vm.storeName2 = r.storeName;
  293. vm.salesDate2 = vm.compareDate;
  294. vm.totalSales2 = r.totalSales;
  295. vm.actualSales2 = r.actualSales;
  296. vm.preferentialLoss2 = r.preferentialLoss;
  297. vm.totalCost2 = r.totalCost;
  298. vm.grossProfit2 = r.grossProfit;
  299. vm.grossProfitRatio2 = r.grossProfitRatio;
  300. vm.proportion2 = r.proportion;
  301. vm.guestNumber2 = r.guestNumber;
  302. vm.guestUnitPrice2 = r.guestUnitPrice;
  303. vm.lastSalesTime2 = r.lastSalesTime;
  304. if(vm.seriesList2.length > 1){
  305. //删除并替换
  306. if(vm.projectSelect=='0'){
  307. vm.seriesList2.splice(1,1,vm.totalSales2);
  308. if(vm.type == 'dept'){
  309. vm.dataList.splice(1,1,'['+vm.merchSn+']'+vm.merchName2+'/售价总额:'+vm.totalSales2+'('+vm.salesDate2+')');
  310. }else{
  311. vm.dataList.splice(1,1,'['+vm.storeId+']'+vm.storeName2+'/售价总额:'+vm.totalSales2+'('+vm.salesDate2+')');
  312. }
  313. // pie 设置
  314. vm.seriesList.splice(1,1,{value:vm.totalSales2,name:vm.dataList[1]});
  315. }else if(vm.projectSelect=='1'){
  316. vm.seriesList2.splice(1,1,vm.guestUnitPrice);
  317. if(vm.type == 'dept'){
  318. vm.dataList.splice(1,1,'['+vm.merchSn+']'+vm.merchName2+'/客单价:'+vm.guestUnitPrice2+'('+vm.salesDate2+')');
  319. }else{
  320. vm.dataList.splice(1,1,'['+vm.storeId+']'+vm.storeName2+'/客单价:'+vm.guestUnitPrice2+'('+vm.salesDate2+')');
  321. }
  322. // pie 设置
  323. vm.seriesList.splice(1,1,{value:vm.guestUnitPrice2,name:vm.dataList[1]});
  324. }
  325. }else{
  326. if(vm.projectSelect=='0'){
  327. vm.seriesList2.push(vm.totalSales2);
  328. if(vm.type == 'dept'){
  329. vm.dataList.push('['+vm.merchSn+']'+vm.merchName2+'/售价总额:'+vm.totalSales2+'('+vm.salesDate2+')');
  330. }else{
  331. vm.dataList.push('['+vm.storeId+']'+vm.storeName2+'/售价总额:'+vm.totalSales2+'('+vm.salesDate2+')');
  332. }
  333. // pie 设置
  334. vm.seriesList.push({value:vm.totalSales2,name:vm.dataList[1]});
  335. }else if(vm.projectSelect=='1'){
  336. vm.seriesList2.push(vm.guestUnitPrice2);
  337. if(vm.type == 'dept'){
  338. vm.dataList.push('['+vm.merchSn+']'+vm.merchName2+'/客单价:'+vm.guestUnitPrice2+'('+vm.salesDate2+')');
  339. }else{
  340. vm.dataList.push('['+vm.storeId+']'+vm.storeName2+'/客单价:'+vm.guestUnitPrice2+'('+vm.salesDate2+')');
  341. }
  342. // pie 设置
  343. vm.seriesList.push({value:vm.guestUnitPrice2,name:vm.dataList[1]});
  344. }
  345. }
  346. if(vm.seriesTypeSelect == "pie"){
  347. vm.seriesList2 = vm.seriesList.concat();
  348. }
  349. myChart.setOption({
  350. xAxis: {
  351. data: vm.dataList
  352. },
  353. series:[{
  354. type: vm.seriesTypeSelect,
  355. color: ['#dd6b66','#759aa0'],
  356. data: vm.seriesList2
  357. }]
  358. });
  359. }
  360. });
  361. },
  362. saveFlushTime:function(){
  363. console.log(typeof vm.refreshTime);
  364. vm.intervalId = window.setInterval('vm.refresh()',vm.refreshTime*1000)
  365. },
  366. clearFlushTime:function(){
  367. window.clearInterval(vm.intervalId);
  368. vm.intervalId = 0;
  369. },
  370. seriesTypeSwitch: function(){
  371. console.log(vm.seriesTypeSelect);
  372. },
  373. showEcharts: function () {
  374. // 基于准备好的dom,初始化echarts实例
  375. myChart = echarts.init(document.getElementById('main'));
  376. myChart.clear();
  377. //加载动画
  378. myChart.showLoading();
  379. //项目下拉框判断 6-19,饼图设置
  380. var temp ='';
  381. if(vm.projectSelect=='0'){
  382. if(vm.type == 'dept'){
  383. temp = '['+vm.merchSn+']'+vm.merchName+'/售价总额:'+vm.totalSales+'('+vm.salesDate+')';
  384. }else{
  385. temp = '['+vm.storeId+']'+vm.storeName+'/售价总额:'+vm.totalSales+'('+vm.salesDate+')';
  386. }
  387. vm.seriesList2.push(vm.totalSales);
  388. vm.seriesList.push({value:vm.totalSales,name:temp});
  389. }else if(vm.projectSelect=='1'){
  390. if(vm.type == 'dept'){
  391. temp = '['+vm.merchSn+']'+vm.merchName+'/客单价:'+vm.guestUnitPrice+'('+vm.salesDate+')';
  392. }else{
  393. temp = '['+vm.storeId+']'+vm.storeName+'/客单价:'+vm.guestUnitPrice+'('+vm.salesDate+')';
  394. }
  395. vm.seriesList2.push(vm.guestUnitPrice);
  396. vm.seriesList.push({value:vm.guestUnitPrice,name:temp});
  397. }
  398. vm.dataList = [temp];
  399. if(vm.seriesTypeSelect == "pie"){
  400. vm.seriesList2 = vm.seriesList.concat();
  401. }
  402. // console.log('vm.seriesList2');
  403. // console.log(vm.seriesList2);
  404. // 指定图表的配置项和数据
  405. //销售量
  406. var option = {
  407. title: {
  408. // textAlign: 'right',
  409. text: '实时销售统计图',
  410. x:'center',
  411. textStyle:{
  412. //文字颜色
  413. color:'#17233d',
  414. //字体风格,'normal','italic','oblique'
  415. fontStyle:'normal',
  416. //字体粗细 'normal','bold','bolder','lighter',100 | 200 | 300 | 400...
  417. fontWeight:'bold',
  418. //字体系列
  419. fontFamily:'sans-serif',
  420. //字体大小
  421. fontSize:28
  422. }
  423. },
  424. tooltip: {
  425. formatter: function (params) {
  426. return params.name;
  427. }
  428. },
  429. legend: {
  430. data:['/售价总额']
  431. },
  432. xAxis: {
  433. data: vm.dataList,
  434. axisLabel: {
  435. interval:0
  436. }
  437. },
  438. yAxis: {},
  439. series:[{
  440. barMaxWidth: '20%' ,
  441. barWidth: '50%' ,
  442. radius: '55%',
  443. roseType: 'angle',
  444. type: vm.seriesTypeSelect,
  445. color: ['#dd6b66','#759aa0'],
  446. data: vm.seriesList2
  447. }]
  448. };
  449. //隐藏
  450. myChart.hideLoading();
  451. // 使用刚指定的配置项和数据显示图表。
  452. myChart.setOption(option);
  453. },
  454. tooltipFormatter: function(){
  455. if(vm.type=='dept'){
  456. return '['+vm.merchSn+']'+vm.merchName+'/售价总额:'+vm.totalSales+'('+vm.salesDate+')';
  457. }
  458. return '['+vm.storeId+']'+vm.storeName+'/售价总额:'+vm.totalSales+'('+vm.salesDate+')';
  459. },
  460. showTable: function (postParam) {
  461. console.log(postParam);
  462. $("#jqGrid").jqGrid('setGridParam', {
  463. postData: postParam
  464. }).trigger("reloadGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "scroll"});
  465. },
  466. switchProjectView: function () {
  467. console.log(vm.projectSelect);
  468. }
  469. }
  470. });