monthlyCustomers.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. $(function () {
  2. var data = {
  3. "echatX": [
  4. "2019-07-02",
  5. "2019-07-03",
  6. "2019-07-04",
  7. "2019-07-05",
  8. "2019-07-06",
  9. "2019-07-07",
  10. "2019-07-08",
  11. "2019-07-09",
  12. "2019-07-10",
  13. "2019-07-11",
  14. "2019-07-12",
  15. "2019-07-13",
  16. "2019-07-14",
  17. "2019-07-15"
  18. ],
  19. "echatY": [
  20. 501,210,123,333,445,157,151,369,101,101,350,435,153,100
  21. ],
  22. "echatY2": [
  23. 80,40,13,36,57,77,41,39,61,31,60,73,33,50
  24. ],
  25. "echatY3": [
  26. 5091,2210,1233,3133,4415,1517,1511,3619,1101,1011,3510,4315,1513,1100
  27. ],
  28. "echatY4": [
  29. 501,210,123,333,445,157,151,369,101,101,350,435,153,100
  30. ],
  31. "peopleTotal":15,"peopleOnline":4,"peopleOutline":12,"ranges":[]
  32. };
  33. dFun(data.echatX, data.echatY, data.echatY2,data.echatY3,data.echatY4);
  34. });
  35. var myChart;
  36. // 基于准备好的dom,初始化echarts实例
  37. var dChart = echarts.init(document.getElementById('main3'));
  38. // 指定图表的配置项和数据
  39. function dFun(dateList, totalNumberList, totalSalesList,taotalCustomersList,avgBasketSaleList) {
  40. dChart.setOption({
  41. // title: {
  42. // left: 'left',
  43. // text: '概率',
  44. // show: false
  45. // },
  46. tooltip: {
  47. trigger: 'axis',
  48. // formatter: '{a}:{c}',
  49. axisPointer: {
  50. type: 'shadow',
  51. crossStyle: {
  52. color: '#999'
  53. }
  54. }
  55. },
  56. grid: {
  57. show: false,
  58. left: '3%',
  59. right: '4%',
  60. bottom: '10%'
  61. },
  62. // legend: {
  63. // show: true,
  64. // selectedMode: 'single', // 设置显示单一图例的图形,点击可切换
  65. // bottom: 10,
  66. // left: 50,
  67. // textStyle: {
  68. // color: '#666',
  69. // fontSize: 12
  70. // },
  71. // itemGap: 20,
  72. // inactiveColor: '#ccc'
  73. // },
  74. xAxis: {
  75. // splitLine: {     show: false   },
  76. type: 'category',
  77. data: dateList,
  78. axisPointer: {
  79. type: 'shadow'
  80. },
  81. // 改变x轴颜色
  82. axisLine: {
  83. lineStyle: {
  84. color: '#00a2e2',
  85. width: 1, // 这里是为了突出显示加上的
  86. }
  87. },
  88. axisTick: {
  89. show: true,
  90. interval: 0
  91. },
  92. },
  93. // 设置两个y轴,左边显示数量,右边显示概率
  94. yAxis: [{
  95. splitLine: {     show: false   },
  96. type: 'value',
  97. name: '',
  98. // max: 10000,
  99. // min: 0,
  100. // show: true,
  101. // interval: 1000,
  102. // 改变y轴颜色
  103. axisLine: {
  104. lineStyle: {
  105. color: '#00a2e2',
  106. width: 1, // 这里是为了突出显示加上的
  107. }
  108. },
  109. }, // 右边显示概率
  110. {
  111. splitLine: {     show: false   },
  112. type: 'value',
  113. name: '客单价',
  114. // min: 0,
  115. // max: 100,
  116. // interval: 10,
  117. // 改变y轴颜色
  118. axisLine: {
  119. lineStyle: {
  120. color: '#00a2e2',
  121. width: 1, // 这里是为了突出显示加上的
  122. }
  123. }
  124. }],
  125. // 每个设备分数量、概率2个指标,只要让他们的name一致,即可通过,legeng进行统一的切换
  126. series: [{
  127. name: 'Units Sold',
  128. type: 'bar',
  129. symbol: 'circle', // 折线点设置为实心点
  130. symbolSize: 4, // 折线点的大小
  131. data: totalNumberList,
  132. barWidth: '20%',
  133. },{
  134. name: 'Sales',
  135. type: 'bar',
  136. symbol: 'circle', // 折线点设置为实心点
  137. symbolSize: 4, // 折线点的大小
  138. data: totalSalesList,
  139. barWidth: '20%',
  140. },{
  141. name: 'Customers',
  142. type: 'bar',
  143. symbol: 'circle', // 折线点设置为实心点
  144. symbolSize: 4, // 折线点的大小
  145. data: taotalCustomersList,
  146. barWidth: '20%',
  147. },
  148. {
  149. //折线
  150. name: 'Average Basket Sale',
  151. type: 'line',
  152. symbol: 'circle', // 折线点设置为实心点
  153. symbolSize: 6, // 折线点的大小
  154. yAxisIndex: 1, // 这里要设置哪个y轴,默认是最左边的是0,然后1,2顺序来。
  155. data: avgBasketSaleList,
  156. symbolSize: 10,
  157. itemStyle: {
  158. normal: {
  159. color: "#DDA0DD"
  160. }
  161. }
  162. },
  163. ]
  164. });
  165. }
  166. function queryMonthly(){
  167. var startMonth = document.getElementById("startMonth").value;
  168. var endMonth = document.getElementById("endMonth").value;
  169. var param = {
  170. startMonth:startMonth,
  171. endMonth:endMonth
  172. };
  173. console.log(param);
  174. // 折线图
  175. $.ajax({
  176. url: "../monthly/customersQuery",
  177. data: param,
  178. contentType:"application/x-www-form-urlencoded",
  179. type: 'POST',
  180. success: function(data) {
  181. console.log(JSON.stringify(data))
  182. dFun(data.dateList, data.totalNumberList, data.totalSalesList,data.taotalCustomersList,data.avgBasketSaleList);
  183. },
  184. });
  185. }
  186. let vm = new Vue({
  187. el: '#rrapp',
  188. data: {
  189. date: '',
  190. refreshTime: 10,
  191. type: 'store',
  192. refreshCount:0,
  193. storeId: '',
  194. merchSn: '',
  195. merchName: '',
  196. storeName: '',
  197. salesDate: '',
  198. totalSales: '',
  199. actualSales: '',
  200. preferentialLoss: '',
  201. totalCost: '',
  202. grossProfit: '',
  203. grossProfitRatio: '',
  204. proportion: '',
  205. guestNumber: '',
  206. guestUnitPrice: '',
  207. lastSalesTime: '',
  208. categoryId: '',
  209. categoryName: '',
  210. showList: false,
  211. compareDate: '',//比较日期
  212. storeId2: '',
  213. merchSn2: '',
  214. merchName2: '',
  215. storeName2: '',
  216. salesDate2: '',
  217. totalSales2: '',
  218. actualSales2: '',
  219. preferentialLoss2: '',
  220. totalCost2: '',
  221. grossProfit2: '',
  222. grossProfitRatio2: '',
  223. proportion2: '',
  224. guestNumber2: '',
  225. guestUnitPrice2: '',
  226. lastSalesTime2: '',
  227. intervalId: 0,
  228. isCompare: false,
  229. compare2: '',
  230. temp: {
  231. date: '',
  232. refreshTime: 10,
  233. type: '',
  234. storeId: '',
  235. merchSn: '',
  236. salesDate: '',
  237. categoryId: ''
  238. },
  239. rateList: [
  240. {
  241. id: '0',
  242. name: '含税'
  243. },
  244. {
  245. id: '1',
  246. name: '不含税'
  247. }
  248. ],
  249. projectList: [
  250. {
  251. id: '0',
  252. name: '销售总额'
  253. },
  254. {
  255. id: '1',
  256. name: '客单价'
  257. }
  258. ],
  259. seriesTypeList: [
  260. {
  261. id: 'bar',
  262. name: '垂直柱状图'
  263. },
  264. {
  265. id: 'line',
  266. name: '折线图'
  267. },
  268. {
  269. id: 'pie',
  270. name: '饼图'
  271. }
  272. ],
  273. formatsList: [
  274. {
  275. id: '0',
  276. name: '<全部>'
  277. },
  278. {
  279. id: '1',
  280. name: '<非全部>'
  281. }
  282. ],
  283. salesList: [
  284. {
  285. store: {storeId: '11106', storeName: '前海店'},
  286. totalSales: 43046.18,
  287. actualSales: 35593.46
  288. }
  289. ],
  290. dept: {
  291. deptId: '',
  292. deptName: ''
  293. },
  294. category: {
  295. categoryId: '',
  296. categoryName: ''
  297. },
  298. seriesList: [], //保存饼图数据
  299. seriesList2: [],
  300. xAxisList: { //主要用于保存 启动刷新时的条件和数据
  301. storeId: '',
  302. storeName: '',
  303. merchSn: '',
  304. merchName: '',
  305. totalSales: '',
  306. actualSales: '',
  307. preferentialLoss: '',
  308. totalCost: '',
  309. grossProfit: '',
  310. grossProfitRatio: '',
  311. proportion: '',
  312. guestNumber: '',
  313. guestUnitPrice: '',
  314. lastSalesTime: '',
  315. salesDate: '0',
  316. projectSelect: '0',
  317. type:''
  318. },
  319. dataList: [],
  320. tooltip: {},
  321. today:''
  322. },
  323. created() {
  324. this.rateSelect = this.rateList[0].id;
  325. this.projectSelect = this.projectList[0].id;
  326. this.seriesTypeSelect = this.seriesTypeList[0].id;
  327. this.formatsSelect = this.formatsList[0].id;
  328. },
  329. methods: {
  330. seriesTypeSwitch: function () {
  331. console.log(vm.seriesTypeSelect);
  332. },
  333. showEcharts: function () {
  334. // 基于准备好的dom,初始化echarts实例
  335. myChart = echarts.init(document.getElementById('main'));
  336. myChart.clear();
  337. //加载动画
  338. myChart.showLoading();
  339. //项目下拉框判断 6-19,饼图设置 vm.xAxisList
  340. var temp = '';
  341. if (vm.xAxisList.projectSelect == '0') {
  342. if (vm.xAxisList.type == 'dept') {
  343. temp = '[' + vm.xAxisList.merchSn + ']' + vm.xAxisList.merchName + '/销售总额:' + vm.xAxisList.totalSales + '元(' + vm.xAxisList.salesDate + ')';
  344. } else {
  345. temp = '[' + vm.xAxisList.storeId + ']' + vm.xAxisList.storeName + '/销售总额:' + vm.xAxisList.totalSales + '元(' + vm.xAxisList.salesDate + ')';
  346. }
  347. vm.seriesList2.push(vm.xAxisList.totalSales);
  348. vm.seriesList.push({value: vm.xAxisList.totalSales, name: temp});
  349. } else if (vm.xAxisList.projectSelect == '1') {
  350. if (vm.xAxisList.type == 'dept') {
  351. temp = '[' + vm.xAxisList.merchSn + ']' + vm.xAxisList.merchName + '/客单价:' + vm.xAxisList.guestUnitPrice + '元(' + vm.xAxisList.salesDate + ')';
  352. } else {
  353. temp = '[' + vm.xAxisList.storeId + ']' + vm.xAxisList.storeName + '/客单价:' + vm.xAxisList.guestUnitPrice + '元(' + vm.xAxisList.salesDate + ')';
  354. }
  355. vm.seriesList2.push(vm.xAxisList.guestUnitPrice);
  356. vm.seriesList.push({value: vm.xAxisList.guestUnitPrice, name: temp});
  357. }
  358. vm.dataList = [temp];
  359. if (vm.seriesTypeSelect == "pie") {
  360. vm.seriesList2 = vm.seriesList.concat();
  361. }
  362. // console.log('vm.seriesList2');
  363. // console.log(vm.seriesList2);
  364. // 指定图表的配置项和数据
  365. //销售量
  366. var option = {
  367. title: {
  368. // textAlign: 'right',
  369. text: 'Monthly Customers & Avg Basket',
  370. x: 'center',
  371. textStyle: {
  372. //文字颜色
  373. color: '#17233d',
  374. //字体风格,'normal','italic','oblique'
  375. fontStyle: 'normal',
  376. //字体粗细 'normal','bold','bolder','lighter',100 | 200 | 300 | 400...
  377. fontWeight: 'bold',
  378. //字体系列
  379. fontFamily: 'sans-serif',
  380. //字体大小
  381. fontSize: 28
  382. }
  383. },
  384. tooltip: {
  385. formatter: function (params) {
  386. return params.name;
  387. }
  388. },
  389. legend: {
  390. data: ['/销售总额']
  391. },
  392. xAxis: {
  393. data: vm.dataList,
  394. axisLabel: {
  395. interval: 0
  396. }
  397. },
  398. yAxis: {},
  399. series: [{
  400. barMaxWidth: '20%',
  401. barWidth: '50%',
  402. radius: '55%',
  403. roseType: 'angle',
  404. type: vm.seriesTypeSelect,
  405. color: ['#dd6b66', '#759aa0'],
  406. data: vm.seriesList2
  407. }]
  408. };
  409. //隐藏
  410. myChart.hideLoading();
  411. // 使用刚指定的配置项和数据显示图表。
  412. myChart.setOption(option);
  413. },
  414. tooltipFormatter: function () {
  415. if (vm.type == 'dept') {
  416. return '[' + vm.merchSn + ']' + vm.merchName + '/销售总额:' + vm.totalSales + '元(' + vm.salesDate + ')';
  417. }
  418. return '[' + vm.storeId + ']' + vm.storeName + '/销售总额:' + vm.totalSales + '元(' + vm.salesDate + ')';
  419. },
  420. showTable: function (postParam) {
  421. console.log(postParam);
  422. $("#jqGrid").jqGrid('setGridParam', {
  423. postData: postParam
  424. }).trigger("reloadGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "scroll"});
  425. },
  426. switchProjectView: function () {
  427. console.log(vm.projectSelect);
  428. }
  429. }
  430. });