mainStatistics.vue 16 KB

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