mainStatistics.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  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(option){
  104. this.init();
  105. },
  106. mounted() {
  107. this.init();
  108. },
  109. methods: {
  110. ...mapActions('chart', ['getStatistics','getMainStatistics']),
  111. async init(){
  112. console.log("adminId:" + this.adminId)
  113. console.log("equipmentId:" + this.equipmentId)
  114. _self = this;
  115. this.cWidth = uni.upx2px(750);
  116. this.cHeight = uni.upx2px(500);
  117. await this.getMainStatisticsData();
  118. await this.initDateRang(new Date(),'day');
  119. await this.initDateRang(new Date(),'week');
  120. await this.initDateRang(new Date(),'month');
  121. await this.initDateRang(new Date(),'year');
  122. },
  123. initDateRang(day,chartType) {
  124. const daystr = dateUtils.formateDate(day, 'yyyy/MM/dd');
  125. if(chartType === 'day'){
  126. this.startDate1 = dateUtils.formateDate(day, 'yyyy/MM/dd');
  127. }
  128. if (chartType === 'week') {
  129. this.startDate2 = dateUtils.formateDate(dateUtils.getFirstDayOfWeek(day), 'yyyy/MM/dd');
  130. this.endDate2 = dateUtils.formateDate(dateUtils.getLastDayOfWeek(day), 'yyyy/MM/dd');
  131. }
  132. if (chartType === 'month') {
  133. this.startDate3 = dateUtils.formateDate(dateUtils.getCurrentMonFirstDate(day), 'yyyy/MM/dd');
  134. this.endDate3 = dateUtils.formateDate(dateUtils.getCurrentMonLastDate(day), 'yyyy/MM/dd');
  135. }
  136. if (chartType === 'year') {
  137. this.startDate4 = dateUtils.formateDate(dateUtils.getCurrentYearFirstDate(day), 'yyyy/MM/dd');
  138. this.endDate4 = dateUtils.formateDate(dateUtils.getCurrentYearLastDate(day), 'yyyy/MM/dd');
  139. }
  140. return this.getStatisticsData(chartType);
  141. },
  142. /**上一个 */
  143. pre(chartType) {
  144. let day;
  145. if (chartType === 'day') { // 日
  146. day = new Date(this.startDate1);
  147. day.setDate(day.getDate() - 1);
  148. }
  149. if(chartType === 'week'){ // 周
  150. day = new Date(this.startDate2);
  151. day.setDate(day.getDate() - 7);
  152. }
  153. if (chartType === 'month') { // 月
  154. day = new Date(this.startDate3);
  155. day.setMonth(day.getMonth() - 1);
  156. }
  157. if (chartType === 'year') { // 年
  158. day = new Date(this.startDate4);
  159. day.setFullYear(day.getFullYear() - 1);
  160. }
  161. this.initDateRang(day,chartType);
  162. },
  163. /**下一个 */
  164. next(chartType) {
  165. let day;
  166. if (chartType === 'day') { // 日
  167. day = new Date(this.startDate1);
  168. day.setDate(day.getDate() + 1);
  169. }
  170. if(chartType === 'week'){ // 周
  171. day = new Date(this.startDate2);
  172. day.setDate(day.getDate() + 7);
  173. }
  174. if (chartType === 'month') { // 月
  175. day = new Date(this.startDate3);
  176. day.setMonth(day.getMonth() + 1);
  177. }
  178. if (chartType === 'year') { // 年
  179. day = new Date(this.startDate4);
  180. day.setFullYear(day.getFullYear() + 1);
  181. }
  182. this.initDateRang(day,chartType);
  183. },
  184. getStatisticsData(chartType) {
  185. const param = {
  186. 'chartType': chartType
  187. };
  188. if(chartType=='day'){
  189. param['startDate'] = this.startDate1;
  190. param['endDate'] = this.startDate1;
  191. }
  192. if(chartType=='week'){
  193. param['startDate'] = this.startDate2;
  194. param['endDate'] = this.endDate2;
  195. }
  196. if(chartType=='month'){
  197. param['startDate'] = this.startDate3;
  198. param['endDate'] = this.endDate3;
  199. }
  200. if(chartType=='year'){
  201. param['startDate'] = this.startDate4;
  202. param['endDate'] = this.endDate4;
  203. }
  204. if(this.adminId){ // 子组件,则拿传过来的参
  205. param['adminId'] = this.adminId;
  206. }else if ('admin' !== this.loginUser['username']) { //否则为主页,拿登录用户
  207. param['adminId'] = this.loginUser['id'];
  208. }
  209. if (this.equipmentId) {
  210. param['equipmentId'] = this.equipmentId;
  211. }
  212. // setTimeout(() => {
  213. return this.getStatistics(param)
  214. .then(data => {
  215. uni.stopPullDownRefresh();
  216. if(param['chartType']=='day'){
  217. canvaColumn1 = this.initChart('canvaColumn1',data);
  218. }
  219. if(param['chartType']=='week'){
  220. canvaColumn2 = this.initChart('canvaColumn2',data);
  221. }
  222. if(param['chartType']=='month'){
  223. canvaColumn3 = this.initChart('canvaColumn3',data);
  224. }
  225. if(param['chartType']=='year'){
  226. canvaColumn4 = this.initChart('canvaColumn4',data);
  227. }
  228. }
  229. , _ => {
  230. uni.stopPullDownRefresh();
  231. if(param['chartType']=='day'){
  232. canvaColumn1 = this.initChart('canvaColumn1',{categories:['暂无数据'],series:[{name: '销售个数',data:[0]}]});
  233. }
  234. if(param['chartType']=='week'){
  235. canvaColumn2 = this.initChart('canvaColumn2',{categories:['暂无数据'],series:[{name: '销售个数',data:[0]}]});
  236. }
  237. if(param['chartType']=='month'){
  238. canvaColumn3 = this.initChart('canvaColumn3',{categories:['暂无数据'],series:[{name: '销售个数',data:[0]}]});
  239. }
  240. if(param['chartType']=='year'){
  241. canvaColumn4 = this.initChart('canvaColumn4',{categories:['暂无数据'],series:[{name: '销售个数',data:[0]}]});
  242. }
  243. }
  244. );
  245. // }, 0);
  246. },
  247. initChart(canvasId, chartData){
  248. return new uCharts({
  249. $this: _self,
  250. canvasId: canvasId,
  251. enableScroll: true,
  252. type: 'column',
  253. legend: true,
  254. fontSize: 11,
  255. background: '#E5FDC3',
  256. pixelRatio: 1,
  257. animation: true,
  258. categories: chartData.categories,
  259. series: chartData.series,
  260. xAxis: {
  261. type: 'grid',
  262. gridType: 'dash',
  263. itemCount: 5, //x轴单屏显示数据的数量,默认为5个
  264. scrollShow: true, //新增是否显示滚动条,默认false
  265. scrollAlign: 'left', //滚动条初始位置
  266. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  267. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  268. // disableGrid:true,
  269. },
  270. yAxis: {
  271. //disabled:true
  272. },
  273. dataLabel: true,
  274. width: _self.cWidth * _self.pixelRatio,
  275. height: _self.cHeight * _self.pixelRatio,
  276. extra: {
  277. column: {
  278. // width: _self.cWidth*_self.pixelRatio*0.45/chartData.categories.length
  279. width: 30
  280. }
  281. }
  282. });
  283. },
  284. getMainStatisticsData(){
  285. // setTimeout(() => {
  286. const param = {};
  287. if(this.adminId){ // 子组件,则拿传过来的参
  288. param['adminId'] = this.adminId;
  289. }else if ('admin' !== this.loginUser['username']) { //否则为主页,拿登录用户
  290. param['adminId'] = this.loginUser['id'];
  291. }
  292. if (this.equipmentId) {
  293. param['equipmentId'] = this.equipmentId;
  294. }
  295. console.log('getMainStatisticsData:{}',param)
  296. return this.getMainStatistics(param)
  297. .then(data => {
  298. for (let bean of data) {
  299. if(bean['categorie']==='day'){
  300. this.dayTotalMoney=bean['salePrice'];
  301. }
  302. if(bean['categorie']==='week'){
  303. this.weekTotalMoney=bean['salePrice'];
  304. }
  305. if(bean['categorie']==='month'){
  306. this.monthTotalMoney=bean['salePrice'];
  307. }
  308. if(bean['categorie']==='year'){
  309. this.yearTotalMoney=bean['salePrice'];
  310. }
  311. }
  312. uni.stopPullDownRefresh();
  313. }
  314. , _ => void uni.stopPullDownRefresh());
  315. // }, 0);
  316. },
  317. touchLine1(e) {
  318. if(canvaColumn1){
  319. canvaColumn1.scrollStart(e);
  320. }
  321. },
  322. moveLine1(e) {
  323. if(canvaColumn1){
  324. canvaColumn1.scroll(e);
  325. }
  326. },
  327. touchEndLine1(e) {
  328. if(canvaColumn1){
  329. canvaColumn1.scrollEnd(e);
  330. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  331. canvaColumn1.showToolTip(e, {
  332. format: function(item, category) {
  333. return category + ' ' + item.name + ':' + item.data
  334. }
  335. });
  336. }
  337. },
  338. touchLine2(e) {
  339. if(canvaColumn2){
  340. canvaColumn2.scrollStart(e);
  341. }
  342. },
  343. moveLine2(e) {
  344. if(canvaColumn2){
  345. canvaColumn2.scroll(e);
  346. }
  347. },
  348. touchEndLine2(e) {
  349. if(canvaColumn2){
  350. canvaColumn2.scrollEnd(e);
  351. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  352. canvaColumn2.showToolTip(e, {
  353. format: function(item, category) {
  354. return category + ' ' + item.name + ':' + item.data
  355. }
  356. });
  357. }
  358. },
  359. touchLine3(e) {
  360. if(canvaColumn3){
  361. canvaColumn3.scrollStart(e);
  362. }
  363. },
  364. moveLine3(e) {
  365. if(canvaColumn3){
  366. canvaColumn3.scroll(e);
  367. }
  368. },
  369. touchEndLine3(e) {
  370. if(canvaColumn3){
  371. canvaColumn3.scrollEnd(e);
  372. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  373. canvaColumn3.showToolTip(e, {
  374. format: function(item, category) {
  375. return category + ' ' + item.name + ':' + item.data
  376. }
  377. });
  378. }
  379. },
  380. touchLine4(e) {
  381. if(canvaColumn4){
  382. canvaColumn4.scrollStart(e);
  383. }
  384. },
  385. moveLine4(e) {
  386. if(canvaColumn4){
  387. canvaColumn4.scroll(e);
  388. }
  389. },
  390. touchEndLine4(e) {
  391. if(canvaColumn4){
  392. canvaColumn4.scrollEnd(e);
  393. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  394. canvaColumn4.showToolTip(e, {
  395. format: function(item, category) {
  396. return category + ' ' + item.name + ':' + item.data
  397. }
  398. });
  399. }
  400. },
  401. }
  402. }
  403. </script>
  404. <style>
  405. page {
  406. background: #F2F2F2;
  407. width: 750upx;
  408. overflow-x: hidden;
  409. }
  410. .qiun-padding {
  411. padding: 2%;
  412. width: 96%;
  413. }
  414. .qiun-wrap {
  415. display: flex;
  416. flex-wrap: wrap;
  417. }
  418. .qiun-rows {
  419. display: flex;
  420. flex-direction: row !important;
  421. }
  422. .qiun-columns {
  423. display: flex;
  424. flex-direction: column !important;
  425. }
  426. .qiun-common-mt {
  427. margin-top: 10upx;
  428. }
  429. .qiun-bg-white {
  430. background: #FFFFFF;
  431. }
  432. .qiun-title-bar {
  433. width: 96%;
  434. padding: 10upx 2%;
  435. flex-wrap: nowrap;
  436. }
  437. .qiun-title-dot-light {
  438. border-left: 10upx solid #0ea391;
  439. padding-left: 10upx;
  440. font-size: 32upx;
  441. color: #000000
  442. }
  443. .qiun-charts {
  444. width: 750upx;
  445. height: 500upx;
  446. background-color: #FFFFFF;
  447. }
  448. .charts {
  449. width: 750upx;
  450. height: 500upx;
  451. background-color: #FFFFFF;
  452. }
  453. .preImg {
  454. position: absolute;left: 40upx; width: 40upx;height: 40upx;
  455. }
  456. .nextImg {
  457. position: absolute;right: 40upx; width: 40upx;height: 40upx;
  458. }
  459. </style>