equipmentStatistics.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. <!-- 机器销售排行 -->
  2. <template>
  3. <view>
  4. <view class="head">
  5. </view>
  6. <view class="ri">
  7. <font class="title">机器销售排行</font>
  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 class="dis">今日销售排行</view></view>
  12. <view class="shijian" 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: #FFFFFF;">
  19. <canvas canvas-id="canvaColumn1" id="canvaColumn1" class="charts" disable-scroll=true @touchstart="touchLine1" @touchmove="moveLine1"
  20. @touchend="touchEndLine1" style="background-color: #FFFFFF;"></canvas>
  21. </view>
  22. </view>
  23. <view class="line"></view>
  24. <view class="qiun-columns">
  25. <view class="qiun-bg-white qiun-title-bar qiun-common-mt">
  26. <view class="qiun-title-dot-light"><view class="dis">本周销售排行</view></view>
  27. <view class="shijian" style="text-align: center;position: relative;">
  28. <image @click="pre('week')" class="preImg" src="/static/img/leftTriangle.png"></image>
  29. <span>{{startDate2}} 至 {{endDate2}}</span>
  30. <image @click="next('week')" class="nextImg" src="/static/img/rightTriangle.png"></image>
  31. </view>
  32. </view>
  33. <view class="qiun-charts" style="background-color: #FFFFFF;">
  34. <canvas canvas-id="canvaColumn2" id="canvaColumn2" class="charts" disable-scroll=true @touchstart="touchLine2" @touchmove="moveLine2"
  35. @touchend="touchEndLine2" style="background-color: #FFFFFF;"></canvas>
  36. </view>
  37. </view>
  38. <view class="line"></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 class="dis">本月销售排行</view></view>
  42. <view class="shijian" 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: #FFFFFF;">
  49. <canvas canvas-id="canvaColumn3" id="canvaColumn3" class="charts" disable-scroll=true @touchstart="touchLine3" @touchmove="moveLine3"
  50. @touchend="touchEndLine3" style="background-color: #FFFFFF;"></canvas>
  51. </view>
  52. </view>
  53. <view class="line"></view>
  54. <view class="qiun-columns">
  55. <view class="qiun-bg-white qiun-title-bar qiun-common-mt">
  56. <view class="qiun-title-dot-light"><view class="dis">本年销售排行</view></view>
  57. <view class="shijian" style="text-align: center;position: relative;">
  58. <image @click="pre('year')" class="preImg" src="/static/img/leftTriangle.png"></image>
  59. <span>{{startDate4}} 至 {{endDate4}}</span>
  60. <image @click="next('year')" class="nextImg" src="/static/img/rightTriangle.png"></image>
  61. </view>
  62. </view>
  63. <view class="qiun-charts" style="background-color: #FFFFFF;">
  64. <canvas canvas-id="canvaColumn4" id="canvaColumn4" class="charts" disable-scroll=true @touchstart="touchLine4" @touchmove="moveLine4"
  65. @touchend="touchEndLine4" style="background-color: #FFFFFF;"></canvas>
  66. </view>
  67. </view>
  68. </view>
  69. </template>
  70. <script>
  71. import { mapState, mapActions, mapMutations } from 'vuex';
  72. import uCharts from '@/components/u-charts/u-charts.js';
  73. import {dateUtils} from '@/common/util.js';
  74. var _self;
  75. var canvaColumn1=null;
  76. var canvaColumn2=null;
  77. var canvaColumn3=null;
  78. var canvaColumn4=null;
  79. export default {
  80. name: 'equipmentStatistics',
  81. props: {
  82. adminId: '',
  83. },
  84. data() {
  85. return {
  86. pname:'',
  87. cWidth: '',
  88. cHeight: '',
  89. pixelRatio: 1,
  90. startDate1: '',
  91. endDate1: '',
  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.adminId = option['adminId'];
  106. // this.pname = option['pname'];
  107. // this.init();
  108. // },
  109. mounted() {
  110. // this.init();
  111. },
  112. onShow() {
  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(690);
  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: '#FFFFFF',//y轴颜色
  262. pixelRatio: 1,
  263. animation: true,
  264. categories: chartData.categories,
  265. series: chartData.series,
  266. xAxis: {
  267. type: 'grid',
  268. gridType: 'dash',
  269. rotateLabel: true,
  270. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  271. scrollShow: true, //新增是否显示滚动条,默认false
  272. scrollAlign: 'left', //滚动条初始位置
  273. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF 滚动条颜色底色
  274. scrollColor: '#DEE7F7', //默认为 #A6A6A6 滚动条颜色
  275. // disableGrid:true,
  276. },
  277. yAxis: {
  278. //disabled:true
  279. },
  280. dataLabel: true,
  281. width: _self.cWidth * _self.pixelRatio,
  282. height: _self.cHeight * _self.pixelRatio,
  283. extra: {
  284. column: {
  285. // width: _self.cWidth*_self.pixelRatio*0.45/chartData.categories.length
  286. width: 15
  287. }
  288. }
  289. });
  290. },
  291. touchLine1(e) {
  292. if(canvaColumn1){
  293. canvaColumn1.scrollStart(e);
  294. }
  295. },
  296. moveLine1(e) {
  297. if(canvaColumn1){
  298. canvaColumn1.scroll(e);
  299. }
  300. },
  301. touchEndLine1(e) {
  302. if(canvaColumn1){
  303. canvaColumn1.scrollEnd(e);
  304. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  305. canvaColumn1.showToolTip(e, {
  306. format: function(item, category) {
  307. return category + ' ' + item.name + ':' + item.data
  308. }
  309. });
  310. }
  311. },
  312. touchLine2(e) {
  313. if(canvaColumn2){
  314. canvaColumn2.scrollStart(e);
  315. }
  316. },
  317. moveLine2(e) {
  318. if(canvaColumn2){
  319. canvaColumn2.scroll(e);
  320. }
  321. },
  322. touchEndLine2(e) {
  323. if(canvaColumn2){
  324. canvaColumn2.scrollEnd(e);
  325. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  326. canvaColumn2.showToolTip(e, {
  327. format: function(item, category) {
  328. return category + ' ' + item.name + ':' + item.data
  329. }
  330. });
  331. }
  332. },
  333. touchLine3(e) {
  334. if(canvaColumn3){
  335. canvaColumn3.scrollStart(e);
  336. }
  337. },
  338. moveLine3(e) {
  339. if(canvaColumn3){
  340. canvaColumn3.scroll(e);
  341. }
  342. },
  343. touchEndLine3(e) {
  344. if(canvaColumn3){
  345. canvaColumn3.scrollEnd(e);
  346. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  347. canvaColumn3.showToolTip(e, {
  348. format: function(item, category) {
  349. return category + ' ' + item.name + ':' + item.data
  350. }
  351. });
  352. }
  353. },
  354. touchLine4(e) {
  355. if(canvaColumn4){
  356. canvaColumn4.scrollStart(e);
  357. }
  358. },
  359. moveLine4(e) {
  360. if(canvaColumn4){
  361. canvaColumn4.scroll(e);
  362. }
  363. },
  364. touchEndLine4(e) {
  365. if(canvaColumn4){
  366. canvaColumn4.scrollEnd(e);
  367. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  368. canvaColumn4.showToolTip(e, {
  369. format: function(item, category) {
  370. return category + ' ' + item.name + ':' + item.data
  371. }
  372. });
  373. }
  374. },
  375. }
  376. }
  377. </script>
  378. <style>
  379. page {
  380. /* background: #F2F2F2; */
  381. background: #FFFFFF;
  382. width: 750upx;
  383. overflow-x: hidden;
  384. }
  385. .head {
  386. display: flex;
  387. flex-direction: row;
  388. background: #206DC3;
  389. width: 750upx;
  390. height: 120upx;
  391. }
  392. .title{
  393. /* border-left: 10upx solid #0ea391; */
  394. color: #363D44;
  395. font-size: 62upx;
  396. font-family: "PingFang-SC-Bold";
  397. text-align: center;
  398. margin: auto;
  399. }
  400. .ri {
  401. width: 690upx;
  402. height: 210upx;
  403. background: #FFFFFF;
  404. border-radius: 15upx;
  405. /* 上移 */
  406. transform: translateY(-90upx);
  407. text-align: center;
  408. margin: auto;
  409. display: flex;
  410. flex-direction: row;
  411. /* 阴影 */
  412. box-shadow: 0upx -1upx 20upx #D3D3D3;
  413. /* box-shadow:0px 0px 10px 5px #aaa; */
  414. }
  415. .riShell {
  416. display: flex;
  417. flex-direction: row;
  418. margin: auto;
  419. }
  420. .riTitle {
  421. display: flex;
  422. flex-direction: column;
  423. margin: auto;
  424. }
  425. .riqi {
  426. display: flex;
  427. flex-direction: column;
  428. margin: auto;
  429. }
  430. .fourTitle {
  431. width: 690upx;
  432. height: 294upx;
  433. display: flex;
  434. flex-direction: row;
  435. flex-wrap: wrap;
  436. background: #FFFFFF;
  437. box-shadow: 0upx 0upx 20upx #D3D3D3;
  438. margin: auto;
  439. border-radius: 15upx;
  440. transform: translateY(-60upx);
  441. }
  442. .four {
  443. display: flex;
  444. flex-direction: row;
  445. margin: auto;
  446. width: 48%;
  447. }
  448. .fourImg {
  449. width: 54upx;
  450. height: 54upx;
  451. }
  452. .qiun-padding {
  453. padding: 2%;
  454. width: 96%;
  455. }
  456. .qiun-wrap {
  457. display: flex;
  458. flex-wrap: wrap;
  459. }
  460. .qiun-rows {
  461. display: flex;
  462. flex-direction: row !important;
  463. }
  464. .qiun-columns {
  465. display: flex;
  466. flex-direction: column !important;
  467. }
  468. .qiun-common-mt {
  469. margin-top: 0upx;
  470. height: 160upx;
  471. }
  472. .qiun-bg-white {
  473. background: #FFFFFF;
  474. }
  475. .qiun-title-bar {
  476. width: 100%;
  477. /* padding: 10upx 2%; */
  478. flex-wrap: nowrap;
  479. border-radius: 15upx;
  480. }
  481. .qiun-title-dot-light {
  482. width: 92%;
  483. border-left: 20upx;
  484. border-left: 10upx solid #206DC3;
  485. padding-left: 10upx;
  486. height: 32upx;
  487. font-family: "PingFang-SC-Bold";
  488. font-weight: bold;
  489. margin: auto;
  490. font-size: 32upx;
  491. color: #363D44;
  492. }
  493. .dis{
  494. transform: translateY(-13upx);
  495. font-size: 32upx;
  496. font-family: "PingFang-SC-Bold";
  497. color: #363D44;
  498. }
  499. .shijian {
  500. padding-top: 30upx;
  501. height: 80upx;
  502. width: 690upx;
  503. margin: auto;
  504. box-shadow: 0upx 0upx 10upx #D3D3D3;
  505. }
  506. .line{
  507. background:#ECECEC ;
  508. height: 20upx;
  509. }
  510. .qiun-charts {
  511. width: 690upx;
  512. height: 370upx;
  513. padding-top: 50upx;
  514. background-color: #FFFFFF;
  515. margin: auto;
  516. }
  517. .charts {
  518. width: 690upx;
  519. height: 370upx;
  520. background-color: #FFFFFF;
  521. margin: auto;
  522. }
  523. .preImg {
  524. position: absolute;
  525. right: 30upx;
  526. width: 71upx;
  527. height: 57upx;
  528. }
  529. .nextImg {
  530. position: absolute;
  531. right: 30upx;
  532. width: 71upx;
  533. height: 57upx;
  534. }
  535. </style>