mainStatistics.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. <template>
  2. <view>
  3. <view class="qiun-title-bar">
  4. <view class="qiun-title-dot-light">今日收入总额: {{dayTotalMoney}}</view>
  5. <view class="qiun-title-dot-light">本周收入总额: {{weekTotalMoney}}</view>
  6. <view class="qiun-title-dot-light">本月收入总额: {{monthTotalMoney}}</view>
  7. <view class="qiun-title-dot-light">本年度收入总额: {{yearTotalMoney}}</view>
  8. </view>
  9. <view class="qiun-columns">
  10. <view class="qiun-bg-white qiun-title-bar qiun-common-mt">
  11. <view class="qiun-title-dot-light">今日销售情况</view>
  12. <view style="text-align: center;position: relative;">
  13. <image @click="pre('day')" class="preImg" src="/static/img/leftTriangle.png"></image>
  14. <span>{{startDate1}}</span>
  15. <image @click="next('day')" class="nextImg" src="/static/img/rightTriangle.png"></image>
  16. </view>
  17. </view>
  18. <view class="qiun-charts" style="background-color: #E5FDC3;">
  19. <canvas canvas-id="canvaColumn1" id="canvaColumn1" class="charts" disable-scroll=true @touchstart="touchLine1" @touchmove="moveLine1"
  20. @touchend="touchEndLine1" style="background-color: #E5FDC3;"></canvas>
  21. </view>
  22. </view>
  23. <view class="qiun-columns">
  24. <view class="qiun-bg-white qiun-title-bar qiun-common-mt">
  25. <view class="qiun-title-dot-light">本周销售情况</view>
  26. <view style="text-align: center;position: relative;">
  27. <image @click="pre('week')" class="preImg" src="/static/img/leftTriangle.png"></image>
  28. <span>{{startDate2}} 至 {{endDate2}}</span>
  29. <image @click="next('week')" class="nextImg" src="/static/img/rightTriangle.png"></image>
  30. </view>
  31. </view>
  32. <view class="qiun-charts" style="background-color: #E5FDC3;">
  33. <canvas canvas-id="canvaColumn2" id="canvaColumn2" class="charts" disable-scroll=true @touchstart="touchLine2" @touchmove="moveLine2"
  34. @touchend="touchEndLine2" style="background-color: #E5FDC3;"></canvas>
  35. </view>
  36. </view>
  37. <view class="qiun-columns">
  38. <view class="qiun-bg-white qiun-title-bar qiun-common-mt">
  39. <view class="qiun-title-dot-light">本月销售情况</view>
  40. <view style="text-align: center;position: relative;">
  41. <image @click="pre('month')" class="preImg" src="/static/img/leftTriangle.png"></image>
  42. <span>{{startDate3}} 至 {{endDate3}}</span>
  43. <image @click="next('month')" class="nextImg" src="/static/img/rightTriangle.png"></image>
  44. </view>
  45. </view>
  46. <view class="qiun-charts" style="background-color: #E5FDC3;">
  47. <canvas canvas-id="canvaColumn3" id="canvaColumn3" class="charts" disable-scroll=true @touchstart="touchLine3" @touchmove="moveLine3"
  48. @touchend="touchEndLine3" style="background-color: #E5FDC3;"></canvas>
  49. </view>
  50. </view>
  51. <view class="qiun-columns">
  52. <view class="qiun-bg-white qiun-title-bar qiun-common-mt">
  53. <view class="qiun-title-dot-light">本年销售情况</view>
  54. <view style="text-align: center;position: relative;">
  55. <image @click="pre('year')" class="preImg" src="/static/img/leftTriangle.png"></image>
  56. <span>{{startDate4}} 至 {{endDate4}}</span>
  57. <image @click="next('year')" class="nextImg" src="/static/img/rightTriangle.png"></image>
  58. </view>
  59. </view>
  60. <view class="qiun-charts" style="background-color: #E5FDC3;">
  61. <canvas canvas-id="canvaColumn4" id="canvaColumn4" class="charts" disable-scroll=true @touchstart="touchLine4" @touchmove="moveLine4"
  62. @touchend="touchEndLine4" style="background-color: #E5FDC3;"></canvas>
  63. </view>
  64. </view>
  65. </view>
  66. </template>
  67. <script>
  68. import { mapState, mapActions, mapMutations } from 'vuex';
  69. import uCharts from '@/components/u-charts/u-charts.js';
  70. import {dateUtils} from '@/common/util.js';
  71. var _self;
  72. var canvaColumn1=null;
  73. var canvaColumn2=null;
  74. var canvaColumn3=null;
  75. var canvaColumn4=null;
  76. export default {
  77. name: 'mainStatistics',
  78. props: {
  79. equipmentId: '',
  80. adminId: '',
  81. },
  82. data() {
  83. return {
  84. dayTotalMoney:0,
  85. weekTotalMoney:0,
  86. monthTotalMoney:0,
  87. yearTotalMoney:0,
  88. cWidth: '',
  89. cHeight: '',
  90. pixelRatio: 1,
  91. startDate1: '',
  92. startDate2: '',
  93. endDate2: '',
  94. startDate3: '',
  95. endDate3: '',
  96. startDate4: '',
  97. endDate4: '',
  98. }
  99. },
  100. computed: {
  101. ...mapState(['loginUser']),
  102. },
  103. onLoad(state){
  104. this.init();
  105. },
  106. mounted() {
  107. },
  108. methods: {
  109. ...mapActions('chart', ['getStatistics','getMainStatistics']),
  110. init(){
  111. _self = this;
  112. this.cWidth = uni.upx2px(750);
  113. this.cHeight = uni.upx2px(500);
  114. this.getMainStatisticsData();
  115. this.initDateRang(new Date(),'day');
  116. this.initDateRang(new Date(),'week');
  117. this.initDateRang(new Date(),'month');
  118. this.initDateRang(new Date(),'year');
  119. },
  120. initDateRang(day,chartType) {
  121. const daystr = dateUtils.formateDate(day, 'yyyy/MM/dd');
  122. if(chartType === 'day'){
  123. this.startDate1 = dateUtils.formateDate(day, 'yyyy/MM/dd');
  124. }
  125. if (chartType === 'week') {
  126. this.startDate2 = dateUtils.formateDate(dateUtils.getFirstDayOfWeek(day), 'yyyy/MM/dd');
  127. this.endDate2 = dateUtils.formateDate(dateUtils.getLastDayOfWeek(day), 'yyyy/MM/dd');
  128. }
  129. if (chartType === 'month') {
  130. this.startDate3 = dateUtils.formateDate(dateUtils.getCurrentMonFirstDate(day), 'yyyy/MM/dd');
  131. this.endDate3 = dateUtils.formateDate(dateUtils.getCurrentMonLastDate(day), 'yyyy/MM/dd');
  132. }
  133. if (chartType === 'year') {
  134. this.startDate4 = dateUtils.formateDate(dateUtils.getCurrentYearFirstDate(day), 'yyyy/MM/dd');
  135. this.endDate4 = dateUtils.formateDate(dateUtils.getCurrentYearLastDate(day), 'yyyy/MM/dd');
  136. }
  137. this.getStatisticsData(chartType);
  138. },
  139. /**上一个 */
  140. pre(chartType) {
  141. let day;
  142. if (chartType === 'day') { // 日
  143. day = new Date(this.startDate1);
  144. day.setDate(day.getDate() - 1);
  145. }
  146. if(chartType === 'week'){ // 周
  147. day = new Date(this.startDate2);
  148. day.setDate(day.getDate() - 7);
  149. }
  150. if (chartType === 'month') { // 月
  151. day = new Date(this.startDate3);
  152. day.setMonth(day.getMonth() - 1);
  153. }
  154. if (chartType === 'year') { // 年
  155. day = new Date(this.startDate4);
  156. day.setFullYear(day.getFullYear() - 1);
  157. }
  158. this.initDateRang(day,chartType);
  159. },
  160. /**下一个 */
  161. next(chartType) {
  162. let day;
  163. if (chartType === 'day') { // 日
  164. day = new Date(this.startDate1);
  165. day.setDate(day.getDate() + 1);
  166. }
  167. if(chartType === 'week'){ // 周
  168. day = new Date(this.startDate2);
  169. day.setDate(day.getDate() + 7);
  170. }
  171. if (chartType === 'month') { // 月
  172. day = new Date(this.startDate3);
  173. day.setMonth(day.getMonth() + 1);
  174. }
  175. if (chartType === 'year') { // 年
  176. day = new Date(this.startDate4);
  177. day.setFullYear(day.getFullYear() + 1);
  178. }
  179. this.initDateRang(day,chartType);
  180. },
  181. getStatisticsData(chartType) {
  182. const param = {
  183. 'chartType': chartType
  184. };
  185. if(chartType=='day'){
  186. param['startDate'] = this.startDate1;
  187. param['endDate'] = this.startDate1;
  188. }
  189. if(chartType=='week'){
  190. param['startDate'] = this.startDate2;
  191. param['endDate'] = this.endDate2;
  192. }
  193. if(chartType=='month'){
  194. param['startDate'] = this.startDate3;
  195. param['endDate'] = this.endDate3;
  196. }
  197. if(chartType=='year'){
  198. param['startDate'] = this.startDate4;
  199. param['endDate'] = this.endDate4;
  200. }
  201. if(this.adminId){ // 子组件,则拿传过来的参
  202. param['adminId'] = this.adminId;
  203. }else if ('admin' !== this.loginUser['username']) { //否则为主页,拿登录用户
  204. param['adminId'] = this.loginUser['id'];
  205. }
  206. if (this.equipmentId) {
  207. param['equipmentId'] = this.equipmentId;
  208. }
  209. setTimeout(() => {
  210. this.getStatistics(param)
  211. .then(data => {
  212. uni.stopPullDownRefresh();
  213. if(param['chartType']=='day'){
  214. canvaColumn1 = this.initChart('canvaColumn1',data);
  215. }
  216. if(param['chartType']=='week'){
  217. canvaColumn2 = this.initChart('canvaColumn2',data);
  218. }
  219. if(param['chartType']=='month'){
  220. canvaColumn3 = this.initChart('canvaColumn3',data);
  221. }
  222. if(param['chartType']=='year'){
  223. canvaColumn4 = this.initChart('canvaColumn4',data);
  224. }
  225. }
  226. , _ => {
  227. uni.stopPullDownRefresh();
  228. if(param['chartType']=='day'){
  229. canvaColumn1 = this.initChart('canvaColumn1',{categories:['暂无数据'],series:[{name: '销售个数',data:[0]}]});
  230. }
  231. if(param['chartType']=='week'){
  232. canvaColumn2 = this.initChart('canvaColumn2',{categories:['暂无数据'],series:[{name: '销售个数',data:[0]}]});
  233. }
  234. if(param['chartType']=='month'){
  235. canvaColumn3 = this.initChart('canvaColumn3',{categories:['暂无数据'],series:[{name: '销售个数',data:[0]}]});
  236. }
  237. if(param['chartType']=='year'){
  238. canvaColumn4 = this.initChart('canvaColumn4',{categories:['暂无数据'],series:[{name: '销售个数',data:[0]}]});
  239. }
  240. }
  241. );
  242. }, 0);
  243. },
  244. initChart(canvasId, chartData){
  245. return new uCharts({
  246. $this: _self,
  247. canvasId: canvasId,
  248. enableScroll: true,
  249. type: 'column',
  250. legend: true,
  251. fontSize: 11,
  252. background: '#E5FDC3',
  253. pixelRatio: 1,
  254. animation: true,
  255. categories: chartData.categories,
  256. series: chartData.series,
  257. xAxis: {
  258. type: 'grid',
  259. gridType: 'dash',
  260. itemCount: 5, //x轴单屏显示数据的数量,默认为5个
  261. scrollShow: true, //新增是否显示滚动条,默认false
  262. scrollAlign: 'left', //滚动条初始位置
  263. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  264. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  265. // disableGrid:true,
  266. },
  267. yAxis: {
  268. //disabled:true
  269. },
  270. dataLabel: true,
  271. width: _self.cWidth * _self.pixelRatio,
  272. height: _self.cHeight * _self.pixelRatio,
  273. extra: {
  274. column: {
  275. // width: _self.cWidth*_self.pixelRatio*0.45/chartData.categories.length
  276. width: 30
  277. }
  278. }
  279. });
  280. },
  281. getMainStatisticsData(){
  282. setTimeout(() => {
  283. const param = {};
  284. if(this.adminId){ // 子组件,则拿传过来的参
  285. param['adminId'] = this.adminId;
  286. }else if ('admin' !== this.loginUser['username']) { //否则为主页,拿登录用户
  287. param['adminId'] = this.loginUser['id'];
  288. }
  289. if (this.equipmentId) {
  290. param['equipmentId'] = this.equipmentId;
  291. }
  292. console.log('getMainStatisticsData:{}',param)
  293. this.getMainStatistics(param)
  294. .then(data => {
  295. for (let bean of data) {
  296. if(bean['categorie']==='day'){
  297. this.dayTotalMoney=bean['salePrice'];
  298. }
  299. if(bean['categorie']==='week'){
  300. this.weekTotalMoney=bean['salePrice'];
  301. }
  302. if(bean['categorie']==='month'){
  303. this.monthTotalMoney=bean['salePrice'];
  304. }
  305. if(bean['categorie']==='year'){
  306. this.yearTotalMoney=bean['salePrice'];
  307. }
  308. }
  309. uni.stopPullDownRefresh();
  310. }
  311. , _ => void uni.stopPullDownRefresh());
  312. }, 0);
  313. },
  314. touchLine1(e) {
  315. canvaColumn1.scrollStart(e);
  316. },
  317. moveLine1(e) {
  318. canvaColumn1.scroll(e);
  319. },
  320. touchEndLine1(e) {
  321. canvaColumn1.scrollEnd(e);
  322. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  323. canvaColumn1.showToolTip(e, {
  324. format: function(item, category) {
  325. return category + ' ' + item.name + ':' + item.data
  326. }
  327. });
  328. },
  329. touchLine2(e) {
  330. canvaColumn2.scrollStart(e);
  331. },
  332. moveLine2(e) {
  333. canvaColumn2.scroll(e);
  334. },
  335. touchEndLine2(e) {
  336. canvaColumn2.scrollEnd(e);
  337. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  338. canvaColumn2.showToolTip(e, {
  339. format: function(item, category) {
  340. return category + ' ' + item.name + ':' + item.data
  341. }
  342. });
  343. },
  344. touchLine3(e) {
  345. canvaColumn3.scrollStart(e);
  346. },
  347. moveLine3(e) {
  348. canvaColumn3.scroll(e);
  349. },
  350. touchEndLine3(e) {
  351. canvaColumn3.scrollEnd(e);
  352. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  353. canvaColumn3.showToolTip(e, {
  354. format: function(item, category) {
  355. return category + ' ' + item.name + ':' + item.data
  356. }
  357. });
  358. },
  359. touchLine4(e) {
  360. canvaColumn4.scrollStart(e);
  361. },
  362. moveLine4(e) {
  363. canvaColumn4.scroll(e);
  364. },
  365. touchEndLine4(e) {
  366. canvaColumn4.scrollEnd(e);
  367. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  368. canvaColumn4.showToolTip(e, {
  369. format: function(item, category) {
  370. return category + ' ' + item.name + ':' + item.data
  371. }
  372. });
  373. },
  374. }
  375. }
  376. </script>
  377. <style>
  378. page {
  379. background: #F2F2F2;
  380. width: 750upx;
  381. overflow-x: hidden;
  382. }
  383. .qiun-padding {
  384. padding: 2%;
  385. width: 96%;
  386. }
  387. .qiun-wrap {
  388. display: flex;
  389. flex-wrap: wrap;
  390. }
  391. .qiun-rows {
  392. display: flex;
  393. flex-direction: row !important;
  394. }
  395. .qiun-columns {
  396. display: flex;
  397. flex-direction: column !important;
  398. }
  399. .qiun-common-mt {
  400. margin-top: 10upx;
  401. }
  402. .qiun-bg-white {
  403. background: #FFFFFF;
  404. }
  405. .qiun-title-bar {
  406. width: 96%;
  407. padding: 10upx 2%;
  408. flex-wrap: nowrap;
  409. }
  410. .qiun-title-dot-light {
  411. border-left: 10upx solid #0ea391;
  412. padding-left: 10upx;
  413. font-size: 32upx;
  414. color: #000000
  415. }
  416. .qiun-charts {
  417. width: 750upx;
  418. height: 500upx;
  419. background-color: #FFFFFF;
  420. }
  421. .charts {
  422. width: 750upx;
  423. height: 500upx;
  424. background-color: #FFFFFF;
  425. }
  426. .preImg {
  427. position: absolute;left: 40upx; width: 40upx;height: 40upx;
  428. }
  429. .nextImg {
  430. position: absolute;right: 40upx; width: 40upx;height: 40upx;
  431. }
  432. </style>