mainStatistics.vue 16 KB

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