equipmentStatistics.vue 15 KB

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