top10ForProduct.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. $(function () {
  2. });
  3. var myChart;
  4. // 基于准备好的dom,初始化echarts实例
  5. var dChart = echarts.init(document.getElementById('main3'));
  6. // 指定图表的配置项和数据
  7. function dFun(productNameList,salesList) {
  8. dChart.setOption({
  9. title: {
  10. text: '产品销量前10'
  11. },
  12. tooltip: {
  13. trigger: 'axis',
  14. axisPointer: {
  15. type: 'shadow'
  16. }
  17. },
  18. legend: {
  19. data: productNameList
  20. },
  21. grid: {
  22. left: '3%',
  23. right: '4%',
  24. bottom: '3%',
  25. containLabel: true
  26. },
  27. xAxis: {
  28. type: 'value',
  29. name: '数量',
  30. },
  31. yAxis: {
  32. type: 'category',
  33. data: productNameList
  34. },
  35. series: [
  36. {
  37. name: '2011年',
  38. type: 'bar',
  39. data: salesList,
  40. label:seriesLabel
  41. }]
  42. });
  43. }
  44. var seriesLabel = {
  45. normal: {
  46. show: true,
  47. textBorderColor: '#333',
  48. textBorderWidth: 2
  49. }
  50. }
  51. function queryMonthly(){
  52. var month = document.getElementById("month").value;
  53. var week = document.getElementById("week").value;
  54. var param = {
  55. month:month,
  56. week:week
  57. };
  58. console.log(param);
  59. // 折线图
  60. $.ajax({
  61. url: "../monthly/top10ForProduct",
  62. data: param,
  63. contentType:"application/x-www-form-urlencoded",
  64. type: 'POST',
  65. success: function(data) {
  66. console.log(JSON.stringify(data))
  67. dFun(data.productNameList, data.salesPriceList);
  68. },
  69. });
  70. }
  71. let vm = new Vue({
  72. el: '#rrapp',
  73. data: {
  74. date: '',
  75. refreshTime: 10,
  76. type: 'store',
  77. refreshCount:0,
  78. storeId: '',
  79. merchSn: '',
  80. merchName: '',
  81. storeName: '',
  82. salesDate: '',
  83. totalSales: '',
  84. actualSales: '',
  85. preferentialLoss: '',
  86. totalCost: '',
  87. grossProfit: '',
  88. grossProfitRatio: '',
  89. proportion: '',
  90. guestNumber: '',
  91. guestUnitPrice: '',
  92. lastSalesTime: '',
  93. categoryId: '',
  94. categoryName: '',
  95. showList: false,
  96. compareDate: '',//比较日期
  97. storeId2: '',
  98. merchSn2: '',
  99. merchName2: '',
  100. storeName2: '',
  101. salesDate2: '',
  102. totalSales2: '',
  103. actualSales2: '',
  104. preferentialLoss2: '',
  105. totalCost2: '',
  106. grossProfit2: '',
  107. grossProfitRatio2: '',
  108. proportion2: '',
  109. guestNumber2: '',
  110. guestUnitPrice2: '',
  111. lastSalesTime2: '',
  112. intervalId: 0,
  113. isCompare: false,
  114. compare2: '',
  115. temp: {
  116. date: '',
  117. refreshTime: 10,
  118. type: '',
  119. storeId: '',
  120. merchSn: '',
  121. salesDate: '',
  122. categoryId: ''
  123. },
  124. rateList: [
  125. {
  126. id: '0',
  127. name: '含税'
  128. },
  129. {
  130. id: '1',
  131. name: '不含税'
  132. }
  133. ],
  134. projectList: [
  135. {
  136. id: '0',
  137. name: '销售总额'
  138. },
  139. {
  140. id: '1',
  141. name: '客单价'
  142. }
  143. ],
  144. seriesTypeList: [
  145. {
  146. id: 'bar',
  147. name: '垂直柱状图'
  148. },
  149. {
  150. id: 'line',
  151. name: '折线图'
  152. },
  153. {
  154. id: 'pie',
  155. name: '饼图'
  156. }
  157. ],
  158. formatsList: [
  159. {
  160. id: '0',
  161. name: '<全部>'
  162. },
  163. {
  164. id: '1',
  165. name: '<非全部>'
  166. }
  167. ],
  168. salesList: [
  169. {
  170. store: {storeId: '11106', storeName: '前海店'},
  171. totalSales: 43046.18,
  172. actualSales: 35593.46
  173. }
  174. ],
  175. dept: {
  176. deptId: '',
  177. deptName: ''
  178. },
  179. category: {
  180. categoryId: '',
  181. categoryName: ''
  182. },
  183. seriesList: [], //保存饼图数据
  184. seriesList2: [],
  185. xAxisList: { //主要用于保存 启动刷新时的条件和数据
  186. storeId: '',
  187. storeName: '',
  188. merchSn: '',
  189. merchName: '',
  190. totalSales: '',
  191. actualSales: '',
  192. preferentialLoss: '',
  193. totalCost: '',
  194. grossProfit: '',
  195. grossProfitRatio: '',
  196. proportion: '',
  197. guestNumber: '',
  198. guestUnitPrice: '',
  199. lastSalesTime: '',
  200. salesDate: '0',
  201. projectSelect: '0',
  202. type:''
  203. },
  204. dataList: [],
  205. tooltip: {},
  206. today:''
  207. },
  208. created() {
  209. this.rateSelect = this.rateList[0].id;
  210. this.projectSelect = this.projectList[0].id;
  211. this.seriesTypeSelect = this.seriesTypeList[0].id;
  212. this.formatsSelect = this.formatsList[0].id;
  213. },
  214. methods: {
  215. seriesTypeSwitch: function () {
  216. console.log(vm.seriesTypeSelect);
  217. },
  218. showEcharts: function () {
  219. // 基于准备好的dom,初始化echarts实例
  220. myChart = echarts.init(document.getElementById('main'));
  221. myChart.clear();
  222. //加载动画
  223. myChart.showLoading();
  224. //项目下拉框判断 6-19,饼图设置 vm.xAxisList
  225. var temp = '';
  226. if (vm.xAxisList.projectSelect == '0') {
  227. if (vm.xAxisList.type == 'dept') {
  228. temp = '[' + vm.xAxisList.merchSn + ']' + vm.xAxisList.merchName + '/销售总额:' + vm.xAxisList.totalSales + '元(' + vm.xAxisList.salesDate + ')';
  229. } else {
  230. temp = '[' + vm.xAxisList.storeId + ']' + vm.xAxisList.storeName + '/销售总额:' + vm.xAxisList.totalSales + '元(' + vm.xAxisList.salesDate + ')';
  231. }
  232. vm.seriesList2.push(vm.xAxisList.totalSales);
  233. vm.seriesList.push({value: vm.xAxisList.totalSales, name: temp});
  234. } else if (vm.xAxisList.projectSelect == '1') {
  235. if (vm.xAxisList.type == 'dept') {
  236. temp = '[' + vm.xAxisList.merchSn + ']' + vm.xAxisList.merchName + '/客单价:' + vm.xAxisList.guestUnitPrice + '元(' + vm.xAxisList.salesDate + ')';
  237. } else {
  238. temp = '[' + vm.xAxisList.storeId + ']' + vm.xAxisList.storeName + '/客单价:' + vm.xAxisList.guestUnitPrice + '元(' + vm.xAxisList.salesDate + ')';
  239. }
  240. vm.seriesList2.push(vm.xAxisList.guestUnitPrice);
  241. vm.seriesList.push({value: vm.xAxisList.guestUnitPrice, name: temp});
  242. }
  243. vm.dataList = [temp];
  244. if (vm.seriesTypeSelect == "pie") {
  245. vm.seriesList2 = vm.seriesList.concat();
  246. }
  247. // console.log('vm.seriesList2');
  248. // console.log(vm.seriesList2);
  249. // 指定图表的配置项和数据
  250. //销售量
  251. var option = {
  252. title: {
  253. // textAlign: 'right',
  254. text: 'Monthly Customers & Avg Basket',
  255. x: 'center',
  256. textStyle: {
  257. //文字颜色
  258. color: '#17233d',
  259. //字体风格,'normal','italic','oblique'
  260. fontStyle: 'normal',
  261. //字体粗细 'normal','bold','bolder','lighter',100 | 200 | 300 | 400...
  262. fontWeight: 'bold',
  263. //字体系列
  264. fontFamily: 'sans-serif',
  265. //字体大小
  266. fontSize: 28
  267. }
  268. },
  269. tooltip: {
  270. formatter: function (params) {
  271. return params.name;
  272. }
  273. },
  274. legend: {
  275. data: ['/销售总额']
  276. },
  277. xAxis: {
  278. data: vm.dataList,
  279. axisLabel: {
  280. interval: 0
  281. }
  282. },
  283. yAxis: {},
  284. series: [{
  285. barMaxWidth: '20%',
  286. barWidth: '50%',
  287. radius: '55%',
  288. roseType: 'angle',
  289. type: vm.seriesTypeSelect,
  290. color: ['#dd6b66', '#759aa0'],
  291. data: vm.seriesList2
  292. }]
  293. };
  294. //隐藏
  295. myChart.hideLoading();
  296. // 使用刚指定的配置项和数据显示图表。
  297. myChart.setOption(option);
  298. },
  299. tooltipFormatter: function () {
  300. if (vm.type == 'dept') {
  301. return '[' + vm.merchSn + ']' + vm.merchName + '/销售总额:' + vm.totalSales + '元(' + vm.salesDate + ')';
  302. }
  303. return '[' + vm.storeId + ']' + vm.storeName + '/销售总额:' + vm.totalSales + '元(' + vm.salesDate + ')';
  304. },
  305. showTable: function (postParam) {
  306. console.log(postParam);
  307. $("#jqGrid").jqGrid('setGridParam', {
  308. postData: postParam
  309. }).trigger("reloadGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "scroll"});
  310. },
  311. switchProjectView: function () {
  312. console.log(vm.projectSelect);
  313. }
  314. }
  315. });