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