equipmentStatistics.vue 13 KB

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