mainStatistics.vue 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140
  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 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 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 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 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>
  194. </template>
  195. <script>
  196. import {
  197. mapState,
  198. mapActions,
  199. mapMutations
  200. } from 'vuex';
  201. import uCharts from '@/components/u-charts/u-charts.js';
  202. import {
  203. dateUtils
  204. } from '@/common/util.js';
  205. var _self;
  206. var canvaColumn1 = null;
  207. var canvaColumn2 = null;
  208. var canvaColumn3 = null;
  209. var canvaColumn4 = null;
  210. export default {
  211. name: 'mainStatistics',
  212. props: {
  213. equipmentId: '',
  214. adminId: '',
  215. pname: '',
  216. },
  217. data() {
  218. return {
  219. machineTotalNum: 0,
  220. machineUseNum: 0,
  221. dayTotalMoney: 0,
  222. dayTotalNum: 0,
  223. weekTotalMoney: 0,
  224. weekTotalNum: 0,
  225. monthTotalMoney: 0,
  226. monthTotalNum: 0,
  227. yearTotalMoney: 0,
  228. yearTotalNum: 0,
  229. cWidth: '',
  230. cHeight: '',
  231. pixelRatio: 1,
  232. startDate1: '',
  233. startDate2: '',
  234. endDate2: '',
  235. startDate3: '',
  236. endDate3: '',
  237. startDate4: '',
  238. endDate4: '',
  239. today: '',
  240. week: '',
  241. adminList: [],
  242. admins: [],
  243. index: 0,
  244. id: 0,
  245. length:0,
  246. type: null,
  247. }
  248. },
  249. computed: {
  250. ...mapState(['loginUser']),
  251. pnameData: {
  252. get() {
  253. return this.pname;
  254. }
  255. },
  256. },
  257. onShow() {
  258. uni.setNavigationBarTitle({
  259. title: this.$t('mainStatistics.title')
  260. });
  261. uni.setTabBarItem({
  262. index: 0,
  263. text: this.$t('tabs.tab1')
  264. });
  265. this.id = 0;
  266. this.index = 0;
  267. var token = uni.getStorageSync("token");
  268. if (token.toString().length > 1) {
  269. this.init();
  270. } else {
  271. uni.reLaunch({
  272. url: '../Login/Login',
  273. });
  274. }
  275. // console.log("onShow");
  276. var test = uni.getStorageSync('test');
  277. var globalUser = uni.getStorageSync("globalUser");
  278. if (globalUser.toString().length > 1) {
  279. //判断是不是初次登陆
  280. // if (test == 2) {
  281. // this.init();
  282. // }
  283. if (globalUser.type > 0&&globalUser.type<4) {
  284. this.getAdmin();
  285. }
  286. this.id = globalUser.id;
  287. this.type = globalUser.type;
  288. }
  289. // var id = this.adminId;
  290. this.day();
  291. // this.equipmentStatus();
  292. },
  293. mounted() {
  294. var token = uni.getStorageSync("token");
  295. if (token.toString().length > 1) {
  296. this.init();
  297. } else {
  298. uni.reLaunch({
  299. url: '../Login/Login',
  300. });
  301. }
  302. // this.day();
  303. this.equipmentStatus();
  304. },
  305. methods: {
  306. ...mapActions('chart', ['getStatistics', 'getMachineNum']),
  307. async init() {
  308. if (!this.pname) {
  309. this.pname = this.loginUser.name;
  310. }
  311. _self = this;
  312. //图表中图
  313. this.cWidth = uni.upx2px(690);
  314. this.cHeight = uni.upx2px(370);
  315. await this.getMainStatisticsData();
  316. await this.initDateRang(new Date(), 'day');
  317. await this.initDateRang(new Date(), 'week');
  318. await this.initDateRang(new Date(), 'month');
  319. await this.initDateRang(new Date(), 'year');
  320. //初次登陆跳转后,把test变成2
  321. uni.setStorageSync('test', '2');
  322. },
  323. day() {
  324. var date = new Date();
  325. // var daystr = dateUtils.formateDate(date, 'yyyy年MM月dd日');
  326. var daystr = dateUtils.formateDate(date, 'yyyy-MM-dd');
  327. this.today = daystr;
  328. // var str= '星期'+'日一二三四五六'.charAt(date.getDay());
  329. this.week = this.$t('mainStatistics.week' + date.getDay());
  330. },
  331. //查询下级用户
  332. getAdmin() {
  333. var param = {};
  334. var token = uni.getStorageSync("token");
  335. var globalUser = uni.getStorageSync("globalUser");
  336. param['id'] = globalUser.id;
  337. uni.request({
  338. url: this.serverurl + '/TAdmin/selectLowAdmin',
  339. data: param,
  340. header: {
  341. 'token': token
  342. },
  343. method: "POST",
  344. success: (res) => {
  345. if (res.data.code) {
  346. var admins = res.data.data;
  347. this.admins = admins;
  348. var adminList = [];
  349. adminList.push('本商户');
  350. if (admins.length > 0) {
  351. this.length = admins.length;
  352. adminList.push('所有下级');
  353. for (var i = 1; i < admins.length; i++) {
  354. // console.log(admins[i].name)
  355. if (admins[i].name != null || admins[i].name != '') {
  356. adminList.push(admins[i].name);
  357. } else {
  358. adminList.push(admins[i].username);
  359. }
  360. }
  361. }
  362. this.adminList = adminList;
  363. } else {
  364. uni.showToast({
  365. title: `获取信息失败:` + res.data.message,
  366. icon: 'none'
  367. })
  368. }
  369. },
  370. });
  371. // this.selectLowAdmin(param)
  372. // .then(res => {
  373. // if (res.code) {
  374. // var admins = res.data;
  375. // this.admins = admins;
  376. // var adminList = [];
  377. // adminList.push('本商户');
  378. // if (admins.length > 0) {
  379. // this.length = admins.length;
  380. // adminList.push('所有下级');
  381. // for (var i = 1; i < admins.length; i++) {
  382. // // console.log(admins[i].name)
  383. // if (admins[i].name != null || admins[i].name != '') {
  384. // adminList.push(admins[i].name);
  385. // } else {
  386. // adminList.push(admins[i].username);
  387. // }
  388. // }
  389. // }
  390. // this.adminList = adminList;
  391. // } else {
  392. // uni.showToast({
  393. // title: `获取信息失败:` + res.message,
  394. // icon: 'none'
  395. // })
  396. // }
  397. // });
  398. },
  399. // 改变商家
  400. changeAdmin: function(e){
  401. this.index = e.target.value;
  402. var id = '';
  403. if(e.target.value>1){
  404. id = this.admins[e.target.value-1].id;
  405. }
  406. if(e.target.value==1){
  407. id = 'all';
  408. }
  409. if(e.target.value==0){
  410. id = 0;
  411. }
  412. // console.log("adminID="+id);
  413. this.id = id;
  414. this.init();
  415. },
  416. equipmentStatus() {
  417. var that = this;
  418. var id = uni.getStorageSync("globalUser").id;
  419. var token = uni.getStorageSync("token");
  420. uni.request({
  421. url: this.serverurl + '/TEquipment/equipmentStatus',
  422. data: {
  423. "adminId": id
  424. },
  425. header: {
  426. 'token': token
  427. },
  428. method: "POST",
  429. success: (res) => {
  430. setTimeout(function() {
  431. that.checkEquipmentStatus(id);
  432. }, 5000);
  433. },
  434. });
  435. },
  436. checkEquipmentStatus(id) {
  437. var token = uni.getStorageSync("token");
  438. uni.request({
  439. url: this.serverurl + '/TEquipment/checkEquipmentStatus',
  440. data: {
  441. "adminId": id
  442. },
  443. header: {
  444. 'token': token
  445. },
  446. method: "POST",
  447. success: (res) => {
  448. },
  449. });
  450. },
  451. initDateRang(day, chartType) {
  452. const daystr = dateUtils.formateDate(day, 'yyyy/MM/dd');
  453. if (chartType === 'day') {
  454. this.startDate1 = dateUtils.formateDate(day, 'yyyy/MM/dd');
  455. }
  456. if (chartType === 'week') {
  457. this.startDate2 = dateUtils.formateDate(dateUtils.getFirstDayOfWeek(day), 'yyyy/MM/dd');
  458. this.endDate2 = dateUtils.formateDate(dateUtils.getLastDayOfWeek(day), 'yyyy/MM/dd');
  459. }
  460. if (chartType === 'month') {
  461. this.startDate3 = dateUtils.formateDate(dateUtils.getCurrentMonFirstDate(day), 'yyyy/MM/dd');
  462. this.endDate3 = dateUtils.formateDate(dateUtils.getCurrentMonLastDate(day), 'yyyy/MM/dd');
  463. }
  464. if (chartType === 'year') {
  465. this.startDate4 = dateUtils.formateDate(dateUtils.getCurrentYearFirstDate(day), 'yyyy/MM/dd');
  466. this.endDate4 = dateUtils.formateDate(dateUtils.getCurrentYearLastDate(day), 'yyyy/MM/dd');
  467. }
  468. return this.getStatisticsData(chartType);
  469. },
  470. /**上一个 */
  471. pre(chartType) {
  472. let day;
  473. if (chartType === 'day') { // 日
  474. day = new Date(this.startDate1);
  475. day.setDate(day.getDate() - 1);
  476. }
  477. if (chartType === 'week') { // 周
  478. day = new Date(this.startDate2);
  479. day.setDate(day.getDate() - 7);
  480. }
  481. if (chartType === 'month') { // 月
  482. day = new Date(this.startDate3);
  483. day.setMonth(day.getMonth() - 1);
  484. }
  485. if (chartType === 'year') { // 年
  486. day = new Date(this.startDate4);
  487. day.setFullYear(day.getFullYear() - 1);
  488. }
  489. this.initDateRang(day, chartType);
  490. },
  491. /**下一个 */
  492. next(chartType) {
  493. let day;
  494. if (chartType === 'day') { // 日
  495. day = new Date(this.startDate1);
  496. day.setDate(day.getDate() + 1);
  497. }
  498. if (chartType === 'week') { // 周
  499. day = new Date(this.startDate2);
  500. day.setDate(day.getDate() + 7);
  501. }
  502. if (chartType === 'month') { // 月
  503. day = new Date(this.startDate3);
  504. day.setMonth(day.getMonth() + 1);
  505. }
  506. if (chartType === 'year') { // 年
  507. day = new Date(this.startDate4);
  508. day.setFullYear(day.getFullYear() + 1);
  509. }
  510. this.initDateRang(day, chartType);
  511. },
  512. getStatisticsData(chartType) {
  513. const param = {
  514. 'chartType': chartType
  515. };
  516. if (chartType == 'day') {
  517. param['startDate'] = this.startDate1;
  518. param['endDate'] = this.startDate1;
  519. }
  520. if (chartType == 'week') {
  521. param['startDate'] = this.startDate2;
  522. param['endDate'] = this.endDate2;
  523. }
  524. if (chartType == 'month') {
  525. param['startDate'] = this.startDate3;
  526. param['endDate'] = this.endDate3;
  527. }
  528. if (chartType == 'year') {
  529. param['startDate'] = this.startDate4;
  530. param['endDate'] = this.endDate4;
  531. }
  532. if (this.adminId) { // 子组件,则拿传过来的参
  533. param['adminId'] = this.adminId;
  534. } else if ('admin' !== this.loginUser['username']) { //否则为主页,拿登录用户
  535. param['adminId'] = this.loginUser['id'];
  536. }
  537. var globalUser = uni.getStorageSync("globalUser");
  538. if (globalUser.id != 1) {
  539. if (param.adminId == null || param.adminId == undefined) {
  540. param['adminId'] = globalUser.id;
  541. }
  542. }
  543. if (this.equipmentId) {
  544. param['equipmentId'] = this.equipmentId;
  545. }
  546. if (this.id!=1) {
  547. var id = this.id;
  548. }else{
  549. var id = 0;
  550. }
  551. if(id=='all'){
  552. param['adminId'] = null;
  553. if(this.type==1){
  554. param['agencyId'] = globalUser.id;
  555. }
  556. if(this.type==2){
  557. param['merchantId'] = globalUser.id;
  558. }
  559. }else if(id==0){
  560. }else{
  561. param['adminId'] = id;
  562. }
  563. return this.getStatistics(param)
  564. .then(data => {
  565. uni.stopPullDownRefresh();
  566. if (param['chartType'] == 'day') {
  567. canvaColumn1 = this.initChart('canvaColumn1', data);
  568. }
  569. if (param['chartType'] == 'week') {
  570. canvaColumn2 = this.initChart('canvaColumn2', data);
  571. }
  572. if (param['chartType'] == 'month') {
  573. canvaColumn3 = this.initChart('canvaColumn3', data);
  574. }
  575. if (param['chartType'] == 'year') {
  576. canvaColumn4 = this.initChart('canvaColumn4', data);
  577. }
  578. }, _ => {
  579. uni.stopPullDownRefresh();
  580. if (param['chartType'] == 'day') {
  581. canvaColumn1 = this.initChart('canvaColumn1', {
  582. categories: ['暂无数据'],
  583. series: [{
  584. name: '销售个数',
  585. data: [0]
  586. }]
  587. });
  588. }
  589. if (param['chartType'] == 'week') {
  590. canvaColumn2 = this.initChart('canvaColumn2', {
  591. categories: ['暂无数据'],
  592. series: [{
  593. name: '销售个数',
  594. data: [0]
  595. }]
  596. });
  597. }
  598. if (param['chartType'] == 'month') {
  599. canvaColumn3 = this.initChart('canvaColumn3', {
  600. categories: ['暂无数据'],
  601. series: [{
  602. name: '销售个数',
  603. data: [0]
  604. }]
  605. });
  606. }
  607. if (param['chartType'] == 'year') {
  608. canvaColumn4 = this.initChart('canvaColumn4', {
  609. categories: ['暂无数据'],
  610. series: [{
  611. name: '销售个数',
  612. data: [0]
  613. }]
  614. });
  615. }
  616. });
  617. },
  618. initChart(canvasId, chartData) {
  619. if (this.$t('lang') != null && this.$t('lang') != '') {
  620. if (this.$t('lang') != 'zh') {
  621. chartData.categories = chartData.categories.map(e => {
  622. if (e.indexOf('点') >= 0) {
  623. return e.replace('点', this.$t('mainStatistics.oclock'));
  624. }
  625. if (e.indexOf('周') >= 0) {
  626. const weekNum = e.substring(e.length - 1) == '日' ? '0' : e.substring(e.length - 1);
  627. return this.$t('mainStatistics.week' + weekNum);
  628. }
  629. if (e.indexOf('月') >= 0) {
  630. var res = e.toString();
  631. if (res.length > 3) {
  632. return e.replace('月', this.$t('mainStatistics.mon'));
  633. } else {
  634. return e.replace('月', this.$t('mainStatistics.y'));
  635. }
  636. }
  637. return e;
  638. });
  639. chartData.series = chartData.series.map(e => {
  640. if (e['name'] == '销售个数') {
  641. e['name'] = this.$t('mainStatistics.saleNum');
  642. }
  643. if (e['name'] == '销售额') {
  644. e['name'] = this.$t('mainStatistics.saleroom');
  645. }
  646. return e;
  647. });
  648. }
  649. }
  650. return new uCharts({
  651. $this: _self,
  652. canvasId: canvasId,
  653. enableScroll: true,
  654. type: 'column',
  655. legend: true,
  656. fontSize: 10,
  657. background: '#FFFFFF', //y轴颜色
  658. pixelRatio: 1,
  659. animation: true,
  660. categories: chartData.categories,
  661. series: chartData.series,
  662. xAxis: {
  663. type: 'grid',
  664. gridType: 'dash',
  665. itemCount: 5, //x轴单屏显示数据的数量,默认为5个
  666. scrollShow: true, //新增是否显示滚动条,默认false
  667. scrollAlign: 'left', //滚动条初始位置
  668. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF 滚动条颜色底色
  669. scrollColor: '#DEE7F7', //默认为 #A6A6A6 滚动条颜色
  670. disableGrid: true,
  671. },
  672. yAxis: {
  673. type: 'grid',
  674. gridType: 'soild',
  675. // disabled:true
  676. // disableGrid:true,
  677. },
  678. dataLabel: true,
  679. width: _self.cWidth * _self.pixelRatio,
  680. height: _self.cHeight * _self.pixelRatio,
  681. extra: {
  682. column: {
  683. // width: _self.cWidth*_self.pixelRatio*0.45/chartData.categories.length
  684. width: 18
  685. }
  686. }
  687. });
  688. },
  689. getMainStatisticsData() {
  690. const param = {};
  691. if (this.adminId) { // 子组件,则拿传过来的参
  692. param['adminId'] = this.adminId;
  693. } else if ('admin' !== this.loginUser['username']) { //否则为主页,拿登录用户
  694. param['adminId'] = this.loginUser['id'];
  695. }
  696. var globalUser = uni.getStorageSync("globalUser");
  697. if (globalUser.id != 1) {
  698. if (param.adminId == null || param.adminId == undefined) {
  699. param['adminId'] = globalUser.id;
  700. }
  701. }
  702. if (this.equipmentId) {
  703. param['equipmentId'] = this.equipmentId;
  704. }
  705. if (this.id!=1) {
  706. var id = this.id;
  707. }else{
  708. var id = 0;
  709. }
  710. var aid = param.adminId;
  711. if(id=='all'){
  712. param['adminId'] = null;
  713. if(this.type==1){
  714. param['agencyId'] = globalUser.id;
  715. }
  716. if(this.type==2){
  717. param['merchantId'] = globalUser.id;
  718. }
  719. }else if(id==0){
  720. }else{
  721. param['adminId'] = id;
  722. aid = id;
  723. }
  724. // console.log('getMainStatisticsData:{}', param);
  725. var adminId = param.adminId;
  726. var equipmentId = this.equipmentId;
  727. var serverurl = this.serverurl;
  728. var token = uni.getStorageSync("token");
  729. uni.request({
  730. url: serverurl + '/TEquipment/getMachineNum',
  731. data: {
  732. "adminId": aid,
  733. "equipmentId": equipmentId
  734. },
  735. method: "POST",
  736. header: {
  737. 'token': token
  738. },
  739. success: (res) => {
  740. var list = res.data.data;
  741. this.machineTotalNum = list[0];
  742. this.machineUseNum = list[1];
  743. }
  744. });
  745. uni.request({
  746. url: serverurl + '/TOrder/getMainStatistics',
  747. data: param,
  748. method: "POST",
  749. header: {
  750. 'token': token
  751. },
  752. success: (res) => {
  753. var list = res.data.data;
  754. for (let bean of list) {
  755. if (bean['categorie'] === 'day') {
  756. this.dayTotalMoney = bean['salePrice'];
  757. this.dayTotalNum = bean['saleNum'];
  758. }
  759. if (bean['categorie'] === 'week') {
  760. this.weekTotalMoney = bean['salePrice'];
  761. this.weekTotalNum = bean['saleNum'];
  762. }
  763. if (bean['categorie'] === 'month') {
  764. this.monthTotalMoney = bean['salePrice'];
  765. this.monthTotalNum = bean['saleNum'];
  766. }
  767. if (bean['categorie'] === 'year') {
  768. this.yearTotalMoney = bean['salePrice'];
  769. this.yearTotalNum = bean['saleNum'];
  770. }
  771. }
  772. }
  773. });
  774. // return this.getMainStatistics(param)
  775. // .then(data => {
  776. // for (let bean of data) {
  777. // if (bean['categorie'] === 'day') {
  778. // this.dayTotalMoney = bean['salePrice'];
  779. // this.dayTotalNum = bean['saleNum'];
  780. // }
  781. // if (bean['categorie'] === 'week') {
  782. // this.weekTotalMoney = bean['salePrice'];
  783. // this.weekTotalNum = bean['saleNum'];
  784. // }
  785. // if (bean['categorie'] === 'month') {
  786. // this.monthTotalMoney = bean['salePrice'];
  787. // this.monthTotalNum = bean['saleNum'];
  788. // }
  789. // if (bean['categorie'] === 'year') {
  790. // this.yearTotalMoney = bean['salePrice'];
  791. // this.yearTotalNum = bean['saleNum'];
  792. // }
  793. // }
  794. // uni.stopPullDownRefresh();
  795. // }, _ => void uni.stopPullDownRefresh());
  796. },
  797. touchLine1(e) {
  798. if (canvaColumn1) {
  799. canvaColumn1.scrollStart(e);
  800. }
  801. },
  802. moveLine1(e) {
  803. if (canvaColumn1) {
  804. canvaColumn1.scroll(e);
  805. }
  806. },
  807. touchEndLine1(e) {
  808. if (canvaColumn1) {
  809. canvaColumn1.scrollEnd(e);
  810. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  811. canvaColumn1.showToolTip(e, {
  812. format: function(item, category) {
  813. return category + ' ' + item.name + ':' + item.data
  814. }
  815. });
  816. }
  817. },
  818. touchLine2(e) {
  819. if (canvaColumn2) {
  820. canvaColumn2.scrollStart(e);
  821. }
  822. },
  823. moveLine2(e) {
  824. if (canvaColumn2) {
  825. canvaColumn2.scroll(e);
  826. }
  827. },
  828. touchEndLine2(e) {
  829. if (canvaColumn2) {
  830. canvaColumn2.scrollEnd(e);
  831. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  832. canvaColumn2.showToolTip(e, {
  833. format: function(item, category) {
  834. return category + ' ' + item.name + ':' + item.data
  835. }
  836. });
  837. }
  838. },
  839. touchLine3(e) {
  840. if (canvaColumn3) {
  841. canvaColumn3.scrollStart(e);
  842. }
  843. },
  844. moveLine3(e) {
  845. if (canvaColumn3) {
  846. canvaColumn3.scroll(e);
  847. }
  848. },
  849. touchEndLine3(e) {
  850. if (canvaColumn3) {
  851. canvaColumn3.scrollEnd(e);
  852. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  853. canvaColumn3.showToolTip(e, {
  854. format: function(item, category) {
  855. return category + ' ' + item.name + ':' + item.data
  856. }
  857. });
  858. }
  859. },
  860. touchLine4(e) {
  861. if (canvaColumn4) {
  862. canvaColumn4.scrollStart(e);
  863. }
  864. },
  865. moveLine4(e) {
  866. if (canvaColumn4) {
  867. canvaColumn4.scroll(e);
  868. }
  869. },
  870. touchEndLine4(e) {
  871. if (canvaColumn4) {
  872. canvaColumn4.scrollEnd(e);
  873. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  874. canvaColumn4.showToolTip(e, {
  875. format: function(item, category) {
  876. return category + ' ' + item.name + ':' + item.data
  877. }
  878. });
  879. }
  880. },
  881. }
  882. }
  883. </script>
  884. <style>
  885. page {
  886. /* background: #F2F2F2; */
  887. background: #FFFFFF;
  888. width: 750upx;
  889. overflow-x: hidden;
  890. }
  891. .head {
  892. display: flex;
  893. flex-direction: row;
  894. background: #206DC3;
  895. width: 750upx;
  896. height: 180upx;
  897. }
  898. .company {
  899. width: 48%;
  900. text-align: right;
  901. }
  902. .pname {
  903. display: flex;
  904. flex-direction: row;
  905. width: 40%;
  906. }
  907. .userFlagimg {
  908. padding-left: 30upx;
  909. padding-top: 10upx;
  910. width: 26upx;
  911. height: 28upx;
  912. }
  913. .wenzi {
  914. padding-left: 5upx;
  915. /* text-align:right; */
  916. white-space: nowrap;
  917. overflow: hidden;
  918. /* text-overflow: ellipsis; */
  919. }
  920. .ri {
  921. width: 690upx;
  922. height: 180upx;
  923. background: #FFFFFF;
  924. border-radius: 15upx;
  925. /* 上移 */
  926. transform: translateY(-90upx);
  927. text-align: center;
  928. margin: auto;
  929. display: flex;
  930. flex-direction: row;
  931. /* 阴影 */
  932. box-shadow: 0upx -1upx 20upx #D3D3D3;
  933. /* box-shadow:0px 0px 10px 5px #aaa; */
  934. }
  935. .riShell {
  936. display: flex;
  937. flex-direction: row;
  938. margin: auto;
  939. }
  940. .riTitle {
  941. display: flex;
  942. flex-direction: column;
  943. margin: auto;
  944. }
  945. .riqi {
  946. display: flex;
  947. flex-direction: column;
  948. margin: auto;
  949. }
  950. .fourTitle {
  951. width: 690upx;
  952. height: 294upx;
  953. display: flex;
  954. flex-direction: row;
  955. flex-wrap: wrap;
  956. background: #FFFFFF;
  957. box-shadow: 0upx 0upx 20upx #D3D3D3;
  958. margin: auto;
  959. border-radius: 15upx;
  960. transform: translateY(-60upx);
  961. }
  962. .four {
  963. display: flex;
  964. flex-direction: row;
  965. margin: auto;
  966. width: 48%;
  967. }
  968. .fourImg {
  969. width: 54upx;
  970. height: 54upx;
  971. }
  972. .qiun-padding {
  973. padding: 2%;
  974. width: 96%;
  975. }
  976. .qiun-wrap {
  977. display: flex;
  978. flex-wrap: wrap;
  979. }
  980. .qiun-rows {
  981. display: flex;
  982. flex-direction: row !important;
  983. }
  984. .qiun-columns {
  985. display: flex;
  986. flex-direction: column !important;
  987. }
  988. .qiun-common-mt {
  989. margin-top: 0upx;
  990. height: 160upx;
  991. }
  992. .qiun-bg-white {
  993. background: #FFFFFF;
  994. }
  995. .qiun-title-bar {
  996. width: 100%;
  997. /* padding: 10upx 2%; */
  998. flex-wrap: nowrap;
  999. border-radius: 15upx;
  1000. }
  1001. .qiun-title-dot-light {
  1002. width: 92%;
  1003. border-left: 20upx;
  1004. border-left: 10upx solid #206DC3;
  1005. padding-left: 10upx;
  1006. height: 32upx;
  1007. /* padding-bottom: 40upx; */
  1008. font-family: "PingFang-SC-Bold";
  1009. font-weight: bold;
  1010. margin: auto;
  1011. font-size: 32upx;
  1012. color: #363D44;
  1013. transform: translateY(20upx);
  1014. }
  1015. .dis {
  1016. transform: translateY(-13upx);
  1017. font-size: 32upx;
  1018. font-family: "PingFang-SC-Bold";
  1019. color: #363D44;
  1020. }
  1021. .shijian {
  1022. transform: translateY(40upx);
  1023. padding-top: 30upx;
  1024. height: 80upx;
  1025. width: 690upx;
  1026. margin: auto;
  1027. box-shadow: 0upx 0upx 10upx #D3D3D3;
  1028. }
  1029. .line {
  1030. background: #ECECEC;
  1031. height: 20upx;
  1032. }
  1033. .qiun-charts {
  1034. width: 690upx;
  1035. height: 370upx;
  1036. padding-top: 50upx;
  1037. background-color: #FFFFFF;
  1038. margin: auto;
  1039. }
  1040. .charts {
  1041. width: 690upx;
  1042. height: 370upx;
  1043. background-color: #FFFFFF;
  1044. margin: auto;
  1045. }
  1046. .preImg {
  1047. position: absolute;
  1048. left: 30upx;
  1049. width: 71upx;
  1050. height: 57upx;
  1051. }
  1052. .nextImg {
  1053. position: absolute;
  1054. right: 30upx;
  1055. width: 71upx;
  1056. height: 57upx;
  1057. }
  1058. .fontLeft {
  1059. margin-right: 6upx;
  1060. }
  1061. .tr {
  1062. padding-top: 15upx;
  1063. display: flex;
  1064. flex-direction: row;
  1065. justify-content: flex-start;
  1066. font-size: 26upx;
  1067. font-family: "PingFang-SC-Bold";
  1068. }
  1069. .td-left {
  1070. font-family: "PingFang-SC-Bold";
  1071. margin: auto;
  1072. font-size: 26upx;
  1073. width: 30%;
  1074. text-align: right;
  1075. }
  1076. .td-right {
  1077. font-family: "PingFang-SC-Bold";
  1078. /* font-weight: bold; */
  1079. margin: auto;
  1080. /* font-size: 26upx; */
  1081. width: 70%;
  1082. text-align: left;
  1083. }
  1084. </style>