mainStatistics.vue 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255
  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"> {{$t('mainStatistics.name')}}: {{pnameData}}
  9. </font>
  10. </view>
  11. <view class="company">
  12. <font style="color: #BDD6F3;font-size:28upx">{{$t('mainStatistics.company')}}</font>
  13. </view>
  14. </view>
  15. <view class="ri">
  16. <view class="riShell">
  17. <view class="riImg">
  18. <image style="width: 64upx;height: 64upx;padding-top: 20upx;" :src="$t('mainStatistics.dayImg')">
  19. </image>
  20. </view>
  21. <view class="riTitle">
  22. <view style="text-align:left;font-size:28upx;font-family:PingFang-SC-Medium">
  23. <font class="fontLeft" style="color: #596D83;">{{$t('mainStatistics.dayTotalMoney')}}:</font>
  24. <font style="color: #ED341F;">{{dayTotalMoney}}</font>
  25. </view>
  26. <view style="text-align:left;font-size:28upx;font-family:PingFang-SC-Medium">
  27. <font class="fontLeft" style="color: #596D83;">{{$t('mainStatistics.dayTotalNum')}}:</font>
  28. <font style="color: #ED341F;">{{dayTotalNum}}</font>
  29. </view>
  30. </view>
  31. </view>
  32. <view class="riqi">
  33. <view style="text-align:right" class="tody">
  34. <font style="color: #596D83;">{{today}}</font>
  35. </view>
  36. <view style="text-align:right" class="xingqi">
  37. <font style="color: #596D83;">{{week}}</font>
  38. </view>
  39. </view>
  40. </view>
  41. <view class="fourTitle">
  42. <view class="four">
  43. <view class="fourImg">
  44. <image style="width: 54upx;height: 54upx;padding-top: 20upx;" :src="$t('mainStatistics.weekImg')"
  45. mode=""></image>
  46. </view>
  47. <view class="fourShell">
  48. <view class="one">
  49. <font class="fontLeft" style="color: #596D83;">{{$t('mainStatistics.weekTotalMoney')}}:</font>
  50. <font style="color: #ED341F;">{{weekTotalMoney}}</font>
  51. </view>
  52. <view class="two">
  53. <font class="fontLeft" style="color: #596D83;">{{$t('mainStatistics.weekTotalNum')}}:</font>
  54. <font style="color: #ED341F;">{{weekTotalNum}}</font>
  55. </view>
  56. </view>
  57. </view>
  58. <view class="four">
  59. <view class="fourImg">
  60. <image style="width: 54upx;height: 54upx;padding-top: 20upx;" :src="$t('mainStatistics.monthImg')"
  61. mode=""></image>
  62. </view>
  63. <view class="fourShell">
  64. <view class="one">
  65. <font class="fontLeft" style="color: #596D83;">{{$t('mainStatistics.monthTotalMoney')}}:</font>
  66. <font style="color: #ED341F;">{{monthTotalMoney}}</font>
  67. </view>
  68. <view class="two">
  69. <font class="fontLeft" style="color: #596D83;">{{$t('mainStatistics.monthTotalNum')}}:</font>
  70. <font style="color: #ED341F;">{{monthTotalNum}}</font>
  71. </view>
  72. </view>
  73. </view>
  74. <view class="four">
  75. <view class="fourImg">
  76. <image style="width: 54upx;height: 54upx;padding-top: 20upx;" :src="$t('mainStatistics.yearImg')"
  77. mode=""></image>
  78. </view>
  79. <view class="fourShell">
  80. <view class="one">
  81. <font class="fontLeft" style="color: #596D83;">{{$t('mainStatistics.yearTotalMoney')}}:</font>
  82. <font style="color: #ED341F;">{{yearTotalMoney}}</font>
  83. </view>
  84. <view class="two">
  85. <font class="fontLeft" style="color: #596D83;">{{$t('mainStatistics.yearTotalNum')}}:</font>
  86. <font style="color: #ED341F;">{{yearTotalNum}}</font>
  87. </view>
  88. </view>
  89. </view>
  90. <view class="four">
  91. <view class="fourImg">
  92. <image style="width: 54upx;height: 54upx;padding-top: 20upx;" :src="$t('mainStatistics.allImg')"
  93. mode=""></image>
  94. </view>
  95. <view class="fourShell">
  96. <view class="one">
  97. <font class="fontLeft" style="color: #596D83;">{{$t('mainStatistics.machineTotalNum')}}:</font>
  98. <font style="color: #ED341F;">{{machineTotalNum}}</font>
  99. </view>
  100. <view class="two">
  101. <font class="fontLeft" style="color: #596D83;">{{$t('mainStatistics.machineUseNum')}}:</font>
  102. <font style="color: #ED341F;">{{machineUseNum}}</font>
  103. </view>
  104. </view>
  105. </view>
  106. </view>
  107. <!-- 商家选择 -->
  108. <view v-if="id!=1&&type<4&&length>0" class="td-right">
  109. <view class="uni-list">
  110. <view class="uni-list-cell">
  111. <view class="uni-list-cell-left">
  112. 当前商家:
  113. </view>
  114. <view class="uni-list-cell-db" style="overflow: hidden;text-overflow: ellipsis;">
  115. <picker @change="changeAdmin" :value="index" :range="adminList">
  116. <view class="uni-input">{{adminList[index]}}</view>
  117. </picker>
  118. </view>
  119. </view>
  120. </view>
  121. </view>
  122. <view class="qiun-columns">
  123. <view class="qiun-bg-white qiun-title-bar qiun-common-mt">
  124. <view class="qiun-title-dot-light">
  125. <view class="dis">{{$t('mainStatistics.day')}}</view>
  126. </view>
  127. <view class="shijian" style="text-align: center;position: relative;">
  128. <image @click="pre('day')" class="preImg" src="/static/img/leftTriangle.png"></image>
  129. <span>{{startDate1}}</span>
  130. <image @click="next('day')" class="nextImg" src="/static/img/rightTriangle.png"></image>
  131. </view>
  132. </view>
  133. <view v-show="noticeTRUE" class="qiun-charts" style="background-color: #FFFFFF;">
  134. <canvas canvas-id="canvaColumn1" id="canvaColumn1" class="charts" disable-scroll=true
  135. @touchstart="touchLine1" @touchmove="moveLine1" @touchend="touchEndLine1"
  136. style="background-color: #FFFFFF;"></canvas>
  137. </view>
  138. </view>
  139. <view class="line"></view>
  140. <view class="qiun-columns">
  141. <view class="qiun-bg-white qiun-title-bar qiun-common-mt">
  142. <view class="qiun-title-dot-light">
  143. <view class="dis">{{$t('mainStatistics.week')}}</view>
  144. </view>
  145. <view class="shijian" style="text-align: center;position: relative;">
  146. <image @click="pre('week')" class="preImg" src="/static/img/leftTriangle.png"></image>
  147. <span>{{startDate2}} -- {{endDate2}}</span>
  148. <image @click="next('week')" class="nextImg" src="/static/img/rightTriangle.png"></image>
  149. </view>
  150. </view>
  151. <view v-show="noticeTRUE" class="qiun-charts" style="background-color: #FFFFFF;">
  152. <canvas canvas-id="canvaColumn2" id="canvaColumn2" class="charts" disable-scroll=true
  153. @touchstart="touchLine2" @touchmove="moveLine2" @touchend="touchEndLine2"
  154. style="background-color: #FFFFFF;"></canvas>
  155. </view>
  156. </view>
  157. <view class="line"></view>
  158. <view class="qiun-columns">
  159. <view class="qiun-bg-white qiun-title-bar qiun-common-mt">
  160. <view class="qiun-title-dot-light">
  161. <view class="dis">{{$t('mainStatistics.month')}}</view>
  162. </view>
  163. <view class="shijian" style="text-align: center;position: relative;">
  164. <image @click="pre('month')" class="preImg" src="/static/img/leftTriangle.png"></image>
  165. <span>{{startDate3}} -- {{endDate3}}</span>
  166. <image @click="next('month')" class="nextImg" src="/static/img/rightTriangle.png"></image>
  167. </view>
  168. </view>
  169. <view v-show="noticeTRUE" class="qiun-charts" style="background-color: #FFFFFF;">
  170. <canvas canvas-id="canvaColumn3" id="canvaColumn3" class="charts" disable-scroll=true
  171. @touchstart="touchLine3" @touchmove="moveLine3" @touchend="touchEndLine3"
  172. style="background-color: #FFFFFF;"></canvas>
  173. </view>
  174. </view>
  175. <view class="line"></view>
  176. <view class="qiun-columns">
  177. <view class="qiun-bg-white qiun-title-bar qiun-common-mt">
  178. <view class="qiun-title-dot-light">
  179. <view class="dis">{{$t('mainStatistics.year')}}</view>
  180. </view>
  181. <view class="shijian" style="text-align: center;position: relative;">
  182. <image @click="pre('year')" class="preImg" src="/static/img/leftTriangle.png"></image>
  183. <span>{{startDate4}} -- {{endDate4}}</span>
  184. <image @click="next('year')" class="nextImg" src="/static/img/rightTriangle.png"></image>
  185. </view>
  186. </view>
  187. <view v-show="noticeTRUE" class="qiun-charts" style="background-color: #FFFFFF;">
  188. <canvas canvas-id="canvaColumn4" id="canvaColumn4" class="charts" disable-scroll=true
  189. @touchstart="touchLine4" @touchmove="moveLine4" @touchend="touchEndLine4"
  190. style="background-color: #FFFFFF;"></canvas>
  191. </view>
  192. </view>
  193. <view v-show="noticeShow">
  194. <uni-popup id="popupDialog" ref="popupDialog" type="dialog">
  195. <uni-popup-dialog :type="msgType" title="通知" content="欢迎使用 unisdfdd-popup!" :before-close="true"
  196. @confirm="dialogConfirm(noticeId)" @close="dialogClose">
  197. <scroll-view scroll-y="true" class="scroll-Y" :style="{height:scrollHeight*0.8+'px'}">
  198. <view class="scroll-view-item ">
  199. {{noticeTitle}}<br />
  200. <p v-html="noticeNote">{{noticeNote}}</p>
  201. </view>
  202. </scroll-view>
  203. </uni-popup-dialog>
  204. </uni-popup>
  205. </view>
  206. </view>
  207. </template>
  208. <script>
  209. import {
  210. mapState,
  211. mapActions,
  212. mapMutations
  213. } from 'vuex';
  214. import uCharts from '@/components/u-charts/u-charts.js';
  215. import {
  216. dateUtils
  217. } from '@/common/util.js';
  218. var _self;
  219. var canvaColumn1 = null;
  220. var canvaColumn2 = null;
  221. var canvaColumn3 = null;
  222. var canvaColumn4 = null;
  223. export default {
  224. name: 'mainStatistics',
  225. props: {
  226. equipmentId: '',
  227. adminId: '',
  228. pname: '',
  229. },
  230. data() {
  231. return {
  232. machineTotalNum: 0,
  233. machineUseNum: 0,
  234. dayTotalMoney: 0,
  235. dayTotalNum: 0,
  236. weekTotalMoney: 0,
  237. weekTotalNum: 0,
  238. monthTotalMoney: 0,
  239. monthTotalNum: 0,
  240. yearTotalMoney: 0,
  241. yearTotalNum: 0,
  242. cWidth: '',
  243. cHeight: '',
  244. pixelRatio: 1,
  245. startDate1: '',
  246. startDate2: '',
  247. endDate2: '',
  248. startDate3: '',
  249. endDate3: '',
  250. startDate4: '',
  251. endDate4: '',
  252. today: '',
  253. week: '',
  254. adminList: [],
  255. admins: [],
  256. index: 0,
  257. id: 0,
  258. length: 0,
  259. type: null,
  260. noticeShow: false,
  261. noticeTRUE: true,
  262. noticeTitle: '',
  263. noticeNote: '',
  264. noticeId: '',
  265. msgType: 'success',
  266. scrollHeight: uni.getSystemInfoSync().windowHeight - 130,
  267. }
  268. },
  269. onReady() {
  270. // 页面打开自动打开对话框
  271. // setTimeout(() => {
  272. // // this.msgType = 'success'
  273. // this.$refs.popupDialog.open()
  274. // }, 500)
  275. },
  276. computed: {
  277. ...mapState(['loginUser']),
  278. pnameData: {
  279. get() {
  280. return this.pname;
  281. }
  282. },
  283. },
  284. onShow() {
  285. uni.setNavigationBarTitle({
  286. title: this.$t('mainStatistics.title')
  287. });
  288. uni.setTabBarItem({
  289. index: 0,
  290. text: this.$t('tabs.tab1')
  291. });
  292. // uni.setStorageSync('test',1);
  293. this.id = 0;
  294. this.index = 0;
  295. var test = uni.getStorageSync('test');
  296. var globalUser = uni.getStorageSync("globalUser");
  297. //test 判断是不是初次登陆
  298. if (globalUser.id != 1 && test == 1) {
  299. setTimeout(() => {
  300. this.getNOtice();
  301. }, 5000);
  302. }
  303. var token = uni.getStorageSync("token");
  304. if (token.toString().length > 1) {
  305. this.init();
  306. } else {
  307. uni.reLaunch({
  308. url: '../Login/Login',
  309. });
  310. }
  311. if (globalUser.toString().length > 1) {
  312. if (globalUser.type > 0 && globalUser.type < 4) {
  313. this.getAdmin();
  314. }
  315. this.id = globalUser.id;
  316. this.type = globalUser.type;
  317. }
  318. this.day();
  319. },
  320. mounted() {
  321. var token = uni.getStorageSync("token");
  322. if (token.toString().length > 1) {
  323. var test = uni.getStorageSync('test');
  324. if (test > 1||test==0) {
  325. this.init();
  326. }
  327. } else {
  328. uni.reLaunch({
  329. url: '../Login/Login',
  330. });
  331. }
  332. // this.day();
  333. this.equipmentStatus();
  334. },
  335. methods: {
  336. // open() {
  337. // this.show = true;
  338. // },
  339. ...mapActions('chart', ['getStatistics', 'getMachineNum']),
  340. async init() {
  341. if (!this.pname) {
  342. this.pname = this.loginUser.name;
  343. }
  344. _self = this;
  345. //图表中图
  346. this.cWidth = uni.upx2px(690);
  347. this.cHeight = uni.upx2px(370);
  348. await this.getMainStatisticsData();
  349. var test = uni.getStorageSync('test');
  350. await this.initDateRang(new Date(), 'day', 0);
  351. if (test == null || test < 2) {
  352. await this.initDateRang(new Date(), 'week', 0);
  353. await this.initDateRang(new Date(), 'month', 0);
  354. await this.initDateRang(new Date(), 'year', 0);
  355. }
  356. var test = uni.getStorageSync('test');
  357. var globalUser = uni.getStorageSync("globalUser");
  358. //初次登陆跳转后,把test变成2
  359. uni.setStorageSync('test', '2');
  360. },
  361. getNOtice() {
  362. // console.log("notice")
  363. var globalUser = uni.getStorageSync("globalUser");
  364. var token = uni.getStorageSync("token");
  365. uni.request({
  366. url: this.serverurl + '/TNotice/getNotice?id=' + globalUser.id,
  367. // data: {
  368. // "id": globalUser.id
  369. // },
  370. header: {
  371. 'token': token
  372. },
  373. method: "POST",
  374. success: (res) => {
  375. if (res.data.code) {
  376. if (res.data.message == '1') {
  377. var notice = res.data.data;
  378. this.noticeTitle = notice.title,
  379. this.noticeNote = notice.note,
  380. this.noticeId = notice.id,
  381. this.noticeTRUE = false,
  382. this.noticeShow = true,
  383. this.$refs.popupDialog.open()
  384. }
  385. }
  386. },
  387. });
  388. },
  389. day() {
  390. var date = new Date();
  391. // var daystr = dateUtils.formateDate(date, 'yyyy年MM月dd日');
  392. var daystr = dateUtils.formateDate(date, 'yyyy-MM-dd');
  393. this.today = daystr;
  394. // var str= '星期'+'日一二三四五六'.charAt(date.getDay());
  395. this.week = this.$t('mainStatistics.week' + date.getDay());
  396. },
  397. //查询下级用户
  398. getAdmin() {
  399. var param = {};
  400. var token = uni.getStorageSync("token");
  401. var globalUser = uni.getStorageSync("globalUser");
  402. param['id'] = globalUser.id;
  403. uni.request({
  404. url: this.serverurl + '/TAdmin/selectLowAdmin',
  405. data: param,
  406. header: {
  407. 'token': token
  408. },
  409. method: "POST",
  410. success: (res) => {
  411. if (res.data.code) {
  412. var admins = res.data.data;
  413. // this.admins = admins;
  414. var adminss = [];
  415. var adminList = [];
  416. adminList.push('本商户');
  417. if (admins.length > 0) {
  418. this.length = admins.length;
  419. adminList.push('所有下级');
  420. for (var i = 0; i < admins.length; i++) {
  421. // console.log(admins[i].name)
  422. if (i == 0) {
  423. var globalUser = uni.getStorageSync("globalUser");
  424. var id = admins[i].id;
  425. if (id == globalUser.id) {
  426. continue;
  427. }
  428. }
  429. if (admins[i].name != null || admins[i].name != '') {
  430. adminss.push(admins[i]);
  431. adminList.push(admins[i].name);
  432. } else {
  433. adminList.push(admins[i].username);
  434. adminss.push(admins[i]);
  435. }
  436. }
  437. }
  438. this.adminList = adminList;
  439. this.admins = adminss;
  440. } else {
  441. uni.showToast({
  442. title: `获取信息失败:` + res.data.message,
  443. icon: 'none'
  444. })
  445. }
  446. },
  447. });
  448. },
  449. // 改变商家
  450. changeAdmin: function(e) {
  451. this.index = e.target.value;
  452. var id = '';
  453. if (e.target.value > 1) {
  454. id = this.admins[e.target.value - 2].id;
  455. }
  456. if (e.target.value == 1) {
  457. id = 'all';
  458. }
  459. if (e.target.value == 0) {
  460. id = 0;
  461. }
  462. // console.log("adminID="+id);
  463. this.id = id;
  464. uni.setStorageSync('test', 1);
  465. this.init();
  466. },
  467. equipmentStatus() {
  468. var that = this;
  469. var id = uni.getStorageSync("globalUser").id;
  470. var token = uni.getStorageSync("token");
  471. uni.request({
  472. url: this.serverurl + '/TEquipment/equipmentStatus',
  473. data: {
  474. "adminId": id
  475. },
  476. header: {
  477. 'token': token
  478. },
  479. method: "POST",
  480. success: (res) => {
  481. setTimeout(function() {
  482. that.checkEquipmentStatus(id);
  483. }, 5000);
  484. },
  485. });
  486. },
  487. checkEquipmentStatus(id) {
  488. var token = uni.getStorageSync("token");
  489. uni.request({
  490. url: this.serverurl + '/TEquipment/checkEquipmentStatus',
  491. data: {
  492. "adminId": id
  493. },
  494. header: {
  495. 'token': token
  496. },
  497. method: "POST",
  498. success: (res) => {
  499. },
  500. });
  501. },
  502. initDateRang(day, chartType, type) {
  503. const daystr = dateUtils.formateDate(day, 'yyyy/MM/dd');
  504. if (chartType === 'day') {
  505. this.startDate1 = dateUtils.formateDate(day, 'yyyy/MM/dd');
  506. }
  507. if (chartType === 'week') {
  508. this.startDate2 = dateUtils.formateDate(dateUtils.getFirstDayOfWeek(day), 'yyyy/MM/dd');
  509. this.endDate2 = dateUtils.formateDate(dateUtils.getLastDayOfWeek(day), 'yyyy/MM/dd');
  510. }
  511. if (chartType === 'month') {
  512. this.startDate3 = dateUtils.formateDate(dateUtils.getCurrentMonFirstDate(day), 'yyyy/MM/dd');
  513. this.endDate3 = dateUtils.formateDate(dateUtils.getCurrentMonLastDate(day), 'yyyy/MM/dd');
  514. }
  515. if (chartType === 'year') {
  516. this.startDate4 = dateUtils.formateDate(dateUtils.getCurrentYearFirstDate(day), 'yyyy/MM/dd');
  517. this.endDate4 = dateUtils.formateDate(dateUtils.getCurrentYearLastDate(day), 'yyyy/MM/dd');
  518. }
  519. return this.getStatisticsData(chartType, type);
  520. },
  521. /**上一个 */
  522. pre(chartType) {
  523. let day;
  524. if (chartType === 'day') { // 日
  525. day = new Date(this.startDate1);
  526. day.setDate(day.getDate() - 1);
  527. }
  528. if (chartType === 'week') { // 周
  529. day = new Date(this.startDate2);
  530. day.setDate(day.getDate() - 7);
  531. }
  532. if (chartType === 'month') { // 月
  533. day = new Date(this.startDate3);
  534. day.setMonth(day.getMonth() - 1);
  535. }
  536. if (chartType === 'year') { // 年
  537. day = new Date(this.startDate4);
  538. day.setFullYear(day.getFullYear() - 1);
  539. }
  540. this.initDateRang(day, chartType, 1);
  541. },
  542. /**下一个 */
  543. next(chartType) {
  544. let day;
  545. if (chartType === 'day') { // 日
  546. day = new Date(this.startDate1);
  547. day.setDate(day.getDate() + 1);
  548. }
  549. if (chartType === 'week') { // 周
  550. day = new Date(this.startDate2);
  551. day.setDate(day.getDate() + 7);
  552. }
  553. if (chartType === 'month') { // 月
  554. day = new Date(this.startDate3);
  555. day.setMonth(day.getMonth() + 1);
  556. }
  557. if (chartType === 'year') { // 年
  558. day = new Date(this.startDate4);
  559. day.setFullYear(day.getFullYear() + 1);
  560. }
  561. this.initDateRang(day, chartType, 1);
  562. },
  563. getStatisticsData(chartType, type) {
  564. //type=0 头顶统计数字变,type=1 头顶统计数字不变
  565. const param = {
  566. 'chartType': chartType
  567. };
  568. if (chartType == 'day') {
  569. param['startDate'] = this.startDate1;
  570. param['endDate'] = this.startDate1;
  571. }
  572. if (chartType == 'week') {
  573. param['startDate'] = this.startDate2;
  574. param['endDate'] = this.endDate2;
  575. }
  576. if (chartType == 'month') {
  577. param['startDate'] = this.startDate3;
  578. param['endDate'] = this.endDate3;
  579. }
  580. if (chartType == 'year') {
  581. param['startDate'] = this.startDate4;
  582. param['endDate'] = this.endDate4;
  583. }
  584. if (this.adminId) { // 子组件,则拿传过来的参
  585. param['adminId'] = this.adminId;
  586. } else if ('admin' !== this.loginUser['username']) { //否则为主页,拿登录用户
  587. param['adminId'] = this.loginUser['id'];
  588. }
  589. var globalUser = uni.getStorageSync("globalUser");
  590. if (globalUser.id != 1) {
  591. if (param.adminId == null || param.adminId == undefined) {
  592. param['adminId'] = globalUser.id;
  593. }
  594. }
  595. if (this.equipmentId) {
  596. param['equipmentId'] = this.equipmentId;
  597. }
  598. if (this.id != 1) {
  599. var id = this.id;
  600. } else {
  601. var id = 0;
  602. }
  603. if (id == 'all') {
  604. param['adminId'] = null;
  605. if (this.type == 1) {
  606. param['agencyId'] = globalUser.id;
  607. }
  608. if (this.type == 2) {
  609. param['merchantId'] = globalUser.id;
  610. }
  611. } else if (id == 0) {
  612. } else {
  613. param['adminId'] = id;
  614. }
  615. var type = type;
  616. return this.getStatistics(param)
  617. .then(data => {
  618. uni.stopPullDownRefresh();
  619. var date = new Date();
  620. var num = date.getDay(); //'日一二三四五六'0123456
  621. var categories = data.categories;
  622. var series = data.series;
  623. if (param['chartType'] == 'day') {
  624. canvaColumn1 = this.initChart('canvaColumn1', data);
  625. if (type == 0) {
  626. var dayTotalMoney = 0;
  627. var dayTotalNum = 0;
  628. for (var i = 0; i < series[0].data.length; i++) {
  629. dayTotalMoney = dayTotalMoney + series[1].data[i];
  630. dayTotalNum = dayTotalNum + series[0].data[i]
  631. }
  632. this.dayTotalNum = dayTotalNum;
  633. this.dayTotalMoney = dayTotalMoney;
  634. }
  635. }
  636. if (param['chartType'] == 'week') {
  637. canvaColumn2 = this.initChart('canvaColumn2', data);
  638. if (type == 0) {
  639. var weekTotalMoney = 0;
  640. var weekTotalNum = 0;
  641. for (var i = 0; i < series[0].data.length; i++) {
  642. weekTotalMoney = weekTotalMoney + series[1].data[i];
  643. weekTotalNum = weekTotalNum + series[0].data[i]
  644. }
  645. this.weekTotalMoney = weekTotalMoney;
  646. this.weekTotalNum = weekTotalNum;
  647. }
  648. }
  649. if (param['chartType'] == 'month') {
  650. canvaColumn3 = this.initChart('canvaColumn3', data);
  651. if (type == 0) {
  652. var monthTotalMoney = 0;
  653. var monthTotalNum = 0;
  654. for (var i = 0; i < series[0].data.length; i++) {
  655. monthTotalMoney = monthTotalMoney + series[1].data[i];
  656. monthTotalNum = monthTotalNum + series[0].data[i]
  657. }
  658. this.monthTotalMoney = monthTotalMoney;
  659. this.monthTotalNum = monthTotalNum;
  660. }
  661. }
  662. if (param['chartType'] == 'year') {
  663. canvaColumn4 = this.initChart('canvaColumn4', data);
  664. if (type == 0) {
  665. var yearTotalMoney = 0;
  666. var yearTotalNum = 0;
  667. for (var i = 0; i < series[0].data.length; i++) {
  668. yearTotalMoney = yearTotalMoney + series[1].data[i];
  669. yearTotalNum = yearTotalNum + series[0].data[i]
  670. }
  671. this.yearTotalMoney = yearTotalMoney;
  672. this.yearTotalNum = yearTotalNum;
  673. }
  674. }
  675. }, _ => {
  676. uni.stopPullDownRefresh();
  677. if (param['chartType'] == 'day') {
  678. canvaColumn1 = this.initChart('canvaColumn1', {
  679. categories: ['暂无数据'],
  680. series: [{
  681. name: '销售个数',
  682. data: [0]
  683. }]
  684. });
  685. }
  686. if (param['chartType'] == 'week') {
  687. canvaColumn2 = this.initChart('canvaColumn2', {
  688. categories: ['暂无数据'],
  689. series: [{
  690. name: '销售个数',
  691. data: [0]
  692. }]
  693. });
  694. }
  695. if (param['chartType'] == 'month') {
  696. canvaColumn3 = this.initChart('canvaColumn3', {
  697. categories: ['暂无数据'],
  698. series: [{
  699. name: '销售个数',
  700. data: [0]
  701. }]
  702. });
  703. }
  704. if (param['chartType'] == 'year') {
  705. canvaColumn4 = this.initChart('canvaColumn4', {
  706. categories: ['暂无数据'],
  707. series: [{
  708. name: '销售个数',
  709. data: [0]
  710. }]
  711. });
  712. }
  713. });
  714. },
  715. initChart(canvasId, chartData) {
  716. if (this.$t('lang') != null && this.$t('lang') != '') {
  717. if (this.$t('lang') != 'zh') {
  718. chartData.categories = chartData.categories.map(e => {
  719. if (e.indexOf('点') >= 0) {
  720. return e.replace('点', this.$t('mainStatistics.oclock'));
  721. }
  722. if (e.indexOf('周') >= 0) {
  723. const weekNum = e.substring(e.length - 1) == '日' ? '0' : e.substring(e.length - 1);
  724. return this.$t('mainStatistics.week' + weekNum);
  725. }
  726. if (e.indexOf('月') >= 0) {
  727. var res = e.toString();
  728. if (res.length > 3) {
  729. return e.replace('月', this.$t('mainStatistics.mon'));
  730. } else {
  731. return e.replace('月', this.$t('mainStatistics.y'));
  732. }
  733. }
  734. return e;
  735. });
  736. chartData.series = chartData.series.map(e => {
  737. if (e['name'] == '销售个数') {
  738. e['name'] = this.$t('mainStatistics.saleNum');
  739. }
  740. if (e['name'] == '销售额') {
  741. e['name'] = this.$t('mainStatistics.saleroom');
  742. }
  743. return e;
  744. });
  745. }
  746. }
  747. return new uCharts({
  748. $this: _self,
  749. canvasId: canvasId,
  750. enableScroll: true,
  751. type: 'column',
  752. legend: true,
  753. fontSize: 10,
  754. background: '#FFFFFF', //y轴颜色
  755. pixelRatio: 1,
  756. animation: true,
  757. categories: chartData.categories,
  758. series: chartData.series,
  759. xAxis: {
  760. type: 'grid',
  761. gridType: 'dash',
  762. itemCount: 5, //x轴单屏显示数据的数量,默认为5个
  763. scrollShow: true, //新增是否显示滚动条,默认false
  764. scrollAlign: 'left', //滚动条初始位置
  765. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF 滚动条颜色底色
  766. scrollColor: '#DEE7F7', //默认为 #A6A6A6 滚动条颜色
  767. disableGrid: true,
  768. },
  769. yAxis: {
  770. type: 'grid',
  771. gridType: 'soild',
  772. // disabled:true
  773. // disableGrid:true,
  774. },
  775. dataLabel: true,
  776. width: _self.cWidth * _self.pixelRatio,
  777. height: _self.cHeight * _self.pixelRatio,
  778. extra: {
  779. column: {
  780. // width: _self.cWidth*_self.pixelRatio*0.45/chartData.categories.length
  781. width: 18
  782. }
  783. }
  784. });
  785. },
  786. getMainStatisticsData() {
  787. const param = {};
  788. if (this.adminId) { // 子组件,则拿传过来的参
  789. param['adminId'] = this.adminId;
  790. } else if ('admin' !== this.loginUser['username']) { //否则为主页,拿登录用户
  791. param['adminId'] = this.loginUser['id'];
  792. }
  793. var globalUser = uni.getStorageSync("globalUser");
  794. if (globalUser.id != 1) {
  795. if (param.adminId == null || param.adminId == undefined) {
  796. param['adminId'] = globalUser.id;
  797. }
  798. }
  799. if (this.equipmentId) {
  800. param['equipmentId'] = this.equipmentId;
  801. }
  802. if (this.id != 1) {
  803. var id = this.id;
  804. } else {
  805. var id = 0;
  806. }
  807. var aid = param.adminId;
  808. if (id == 'all') {
  809. param['adminId'] = null;
  810. if (this.type == 1) {
  811. param['agencyId'] = globalUser.id;
  812. }
  813. if (this.type == 2) {
  814. param['merchantId'] = globalUser.id;
  815. }
  816. } else if (id == 0) {
  817. } else {
  818. param['adminId'] = id;
  819. aid = id;
  820. }
  821. // console.log('getMainStatisticsData:{}', param);
  822. var adminId = param.adminId;
  823. var equipmentId = this.equipmentId;
  824. var serverurl = this.serverurl;
  825. var token = uni.getStorageSync("token");
  826. var test = uni.getStorageSync("test");
  827. param['test'] = test;
  828. uni.request({
  829. url: serverurl + '/TEquipment/getMachineNum',
  830. data: {
  831. "adminId": aid,
  832. "equipmentId": equipmentId
  833. },
  834. method: "POST",
  835. header: {
  836. 'token': token
  837. },
  838. success: (res) => {
  839. var list = res.data.data;
  840. this.machineTotalNum = list[0];
  841. this.machineUseNum = list[1];
  842. }
  843. });
  844. // uni.request({
  845. // url: serverurl + '/TOrder/getMainStatistics',
  846. // data: param,
  847. // method: "POST",
  848. // header: {
  849. // 'token': token
  850. // },
  851. // success: (res) => {
  852. // var list = res.data.data;
  853. // for (let bean of list) {
  854. // if (bean['categorie'] === 'day') {
  855. // this.dayTotalMoney = bean['salePrice'];
  856. // this.dayTotalNum = bean['saleNum'];
  857. // }
  858. // if (bean['categorie'] === 'week') {
  859. // this.weekTotalMoney = bean['salePrice'];
  860. // this.weekTotalNum = bean['saleNum'];
  861. // }
  862. // if (bean['categorie'] === 'month') {
  863. // this.monthTotalMoney = bean['salePrice'];
  864. // this.monthTotalNum = bean['saleNum'];
  865. // }
  866. // if (bean['categorie'] === 'year') {
  867. // this.yearTotalMoney = bean['salePrice'];
  868. // this.yearTotalNum = bean['saleNum'];
  869. // }
  870. // }
  871. // }
  872. // });
  873. },
  874. touchLine1(e) {
  875. if (canvaColumn1) {
  876. canvaColumn1.scrollStart(e);
  877. }
  878. },
  879. moveLine1(e) {
  880. if (canvaColumn1) {
  881. canvaColumn1.scroll(e);
  882. }
  883. },
  884. touchEndLine1(e) {
  885. if (canvaColumn1) {
  886. canvaColumn1.scrollEnd(e);
  887. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  888. canvaColumn1.showToolTip(e, {
  889. format: function(item, category) {
  890. return category + ' ' + item.name + ':' + item.data
  891. }
  892. });
  893. }
  894. },
  895. touchLine2(e) {
  896. if (canvaColumn2) {
  897. canvaColumn2.scrollStart(e);
  898. }
  899. },
  900. moveLine2(e) {
  901. if (canvaColumn2) {
  902. canvaColumn2.scroll(e);
  903. }
  904. },
  905. touchEndLine2(e) {
  906. if (canvaColumn2) {
  907. canvaColumn2.scrollEnd(e);
  908. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  909. canvaColumn2.showToolTip(e, {
  910. format: function(item, category) {
  911. return category + ' ' + item.name + ':' + item.data
  912. }
  913. });
  914. }
  915. },
  916. touchLine3(e) {
  917. if (canvaColumn3) {
  918. canvaColumn3.scrollStart(e);
  919. }
  920. },
  921. moveLine3(e) {
  922. if (canvaColumn3) {
  923. canvaColumn3.scroll(e);
  924. }
  925. },
  926. touchEndLine3(e) {
  927. if (canvaColumn3) {
  928. canvaColumn3.scrollEnd(e);
  929. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  930. canvaColumn3.showToolTip(e, {
  931. format: function(item, category) {
  932. return category + ' ' + item.name + ':' + item.data
  933. }
  934. });
  935. }
  936. },
  937. touchLine4(e) {
  938. if (canvaColumn4) {
  939. canvaColumn4.scrollStart(e);
  940. }
  941. },
  942. moveLine4(e) {
  943. if (canvaColumn4) {
  944. canvaColumn4.scroll(e);
  945. }
  946. },
  947. touchEndLine4(e) {
  948. if (canvaColumn4) {
  949. canvaColumn4.scrollEnd(e);
  950. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  951. canvaColumn4.showToolTip(e, {
  952. format: function(item, category) {
  953. return category + ' ' + item.name + ':' + item.data
  954. }
  955. });
  956. }
  957. },
  958. // 点击确定
  959. dialogConfirm(id) {
  960. this.noticeTRUE = true;
  961. var adminId = uni.getStorageSync("globalUser").id;
  962. var token = uni.getStorageSync("token");
  963. uni.request({
  964. url: this.serverurl + '/TNotice/updateNotice?adminId=' + adminId + '&noticeId=' + id,
  965. // data: {
  966. // "adminId": adminId,
  967. // "noticeId":id
  968. // },
  969. header: {
  970. 'token': token
  971. },
  972. method: "POST",
  973. success: (res) => {
  974. uni.showModal({
  975. title: "提示",
  976. content: res.data.message,
  977. success: (res) => {
  978. }
  979. })
  980. },
  981. });
  982. this.$refs.popupDialog.close()
  983. },
  984. //点击取消
  985. dialogClose(done) {
  986. this.noticeTRUE = true,
  987. // this.msgType = 'success'
  988. // 需要执行 done 才能关闭对话框
  989. this.$refs.popupDialog.close()
  990. }
  991. }
  992. }
  993. </script>
  994. <style>
  995. page {
  996. /* background: #F2F2F2; */
  997. background: #FFFFFF;
  998. width: 750upx;
  999. overflow-x: hidden;
  1000. }
  1001. .head {
  1002. display: flex;
  1003. flex-direction: row;
  1004. background: #206DC3;
  1005. width: 750upx;
  1006. height: 180upx;
  1007. }
  1008. .company {
  1009. width: 48%;
  1010. text-align: right;
  1011. }
  1012. .pname {
  1013. display: flex;
  1014. flex-direction: row;
  1015. width: 40%;
  1016. }
  1017. .userFlagimg {
  1018. padding-left: 30upx;
  1019. padding-top: 10upx;
  1020. width: 26upx;
  1021. height: 28upx;
  1022. }
  1023. .wenzi {
  1024. padding-left: 5upx;
  1025. /* text-align:right; */
  1026. white-space: nowrap;
  1027. overflow: hidden;
  1028. /* text-overflow: ellipsis; */
  1029. }
  1030. .ri {
  1031. width: 690upx;
  1032. height: 180upx;
  1033. background: #FFFFFF;
  1034. border-radius: 15upx;
  1035. /* 上移 */
  1036. transform: translateY(-90upx);
  1037. text-align: center;
  1038. margin: auto;
  1039. display: flex;
  1040. flex-direction: row;
  1041. /* 阴影 */
  1042. box-shadow: 0upx -1upx 20upx #D3D3D3;
  1043. /* box-shadow:0px 0px 10px 5px #aaa; */
  1044. }
  1045. .riShell {
  1046. display: flex;
  1047. flex-direction: row;
  1048. margin: auto;
  1049. }
  1050. .riTitle {
  1051. display: flex;
  1052. flex-direction: column;
  1053. margin: auto;
  1054. }
  1055. .riqi {
  1056. display: flex;
  1057. flex-direction: column;
  1058. margin: auto;
  1059. }
  1060. .fourTitle {
  1061. width: 690upx;
  1062. height: 294upx;
  1063. display: flex;
  1064. flex-direction: row;
  1065. flex-wrap: wrap;
  1066. background: #FFFFFF;
  1067. box-shadow: 0upx 0upx 20upx #D3D3D3;
  1068. margin: auto;
  1069. border-radius: 15upx;
  1070. transform: translateY(-60upx);
  1071. }
  1072. .four {
  1073. display: flex;
  1074. flex-direction: row;
  1075. margin: auto;
  1076. width: 48%;
  1077. }
  1078. .fourImg {
  1079. width: 54upx;
  1080. height: 54upx;
  1081. }
  1082. .qiun-padding {
  1083. padding: 2%;
  1084. width: 96%;
  1085. }
  1086. .qiun-wrap {
  1087. display: flex;
  1088. flex-wrap: wrap;
  1089. }
  1090. .qiun-rows {
  1091. display: flex;
  1092. flex-direction: row !important;
  1093. }
  1094. .qiun-columns {
  1095. display: flex;
  1096. flex-direction: column !important;
  1097. }
  1098. .qiun-common-mt {
  1099. margin-top: 0upx;
  1100. height: 160upx;
  1101. }
  1102. .qiun-bg-white {
  1103. background: #FFFFFF;
  1104. }
  1105. .qiun-title-bar {
  1106. width: 100%;
  1107. /* padding: 10upx 2%; */
  1108. flex-wrap: nowrap;
  1109. border-radius: 15upx;
  1110. }
  1111. .qiun-title-dot-light {
  1112. width: 92%;
  1113. border-left: 20upx;
  1114. border-left: 10upx solid #206DC3;
  1115. padding-left: 10upx;
  1116. height: 32upx;
  1117. /* padding-bottom: 40upx; */
  1118. font-family: "PingFang-SC-Bold";
  1119. font-weight: bold;
  1120. margin: auto;
  1121. font-size: 32upx;
  1122. color: #363D44;
  1123. transform: translateY(20upx);
  1124. }
  1125. .dis {
  1126. transform: translateY(-13upx);
  1127. font-size: 32upx;
  1128. font-family: "PingFang-SC-Bold";
  1129. color: #363D44;
  1130. }
  1131. .shijian {
  1132. transform: translateY(40upx);
  1133. padding-top: 30upx;
  1134. height: 80upx;
  1135. width: 690upx;
  1136. margin: auto;
  1137. box-shadow: 0upx 0upx 10upx #D3D3D3;
  1138. }
  1139. .line {
  1140. background: #ECECEC;
  1141. height: 20upx;
  1142. }
  1143. .qiun-charts {
  1144. width: 690upx;
  1145. height: 370upx;
  1146. padding-top: 50upx;
  1147. background-color: #FFFFFF;
  1148. margin: auto;
  1149. }
  1150. .charts {
  1151. width: 690upx;
  1152. height: 370upx;
  1153. background-color: #FFFFFF;
  1154. margin: auto;
  1155. }
  1156. .preImg {
  1157. position: absolute;
  1158. left: 30upx;
  1159. width: 71upx;
  1160. height: 57upx;
  1161. }
  1162. .nextImg {
  1163. position: absolute;
  1164. right: 30upx;
  1165. width: 71upx;
  1166. height: 57upx;
  1167. }
  1168. .fontLeft {
  1169. margin-right: 6upx;
  1170. }
  1171. .tr {
  1172. padding-top: 15upx;
  1173. display: flex;
  1174. flex-direction: row;
  1175. justify-content: flex-start;
  1176. font-size: 26upx;
  1177. font-family: "PingFang-SC-Bold";
  1178. }
  1179. .td-left {
  1180. font-family: "PingFang-SC-Bold";
  1181. margin: auto;
  1182. font-size: 26upx;
  1183. width: 30%;
  1184. text-align: right;
  1185. }
  1186. .td-right {
  1187. font-family: "PingFang-SC-Bold";
  1188. /* font-weight: bold; */
  1189. margin: auto;
  1190. /* font-size: 26upx; */
  1191. width: 70%;
  1192. text-align: left;
  1193. }
  1194. </style>