mainStatistics.vue 14 KB

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