equipmentStatistics.vue 15 KB

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