mainStatistics.vue 14 KB

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