demo02.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. <template>
  2. <!-- <Resize> -->
  3. <div class="boxx">
  4. <!-- 标题 -->
  5. <div class="title">jolijoli实时数据大屏</div>
  6. <div class="box">
  7. <!-- 图表 -->
  8. <div class="pic">
  9. <!-- 左边部分 -->
  10. <div class="left">
  11. <div class="left-top">
  12. <el-card
  13. ><div class="btn">
  14. <el-button
  15. :class="{ bgc: activeClass == 0 }"
  16. size="small"
  17. type="info"
  18. @click="yesterday(0)"
  19. :disabled="activeClass == 0"
  20. >昨天</el-button
  21. >
  22. <el-button
  23. size="small"
  24. type="info"
  25. @click="thisWeek(1)"
  26. :class="{ bgc: activeClass == 1 }"
  27. :disabled="activeClass == 1"
  28. >本周</el-button
  29. >
  30. <el-button
  31. size="small"
  32. type="info"
  33. @click="thisMonth(2)"
  34. :class="{ bgc: activeClass == 2 }"
  35. :disabled="activeClass == 2"
  36. >本月</el-button
  37. >
  38. <!-- 选择店铺 -->
  39. <div class="selectStore">
  40. <!-- 日期选择 -->
  41. <el-date-picker
  42. v-model="value1"
  43. type="daterange"
  44. range-separator="至"
  45. start-placeholder="开始日期"
  46. end-placeholder="结束日期"
  47. size="mini"
  48. @change="selectTime"
  49. >
  50. </el-date-picker>
  51. <!-- 选择店铺 -->
  52. <div>
  53. <el-dropdown class="Store" @command="selectStore">
  54. <el-button type="info" size="small">
  55. {{ store
  56. }}<i class="el-icon-arrow-down el-icon--right"></i>
  57. </el-button>
  58. <el-dropdown-menu slot="dropdown">
  59. <el-dropdown-item
  60. :command="item.store_name"
  61. v-for="(item, index) in storeList"
  62. :key="index"
  63. >{{ item.store_name }}</el-dropdown-item
  64. >
  65. </el-dropdown-menu>
  66. </el-dropdown>
  67. <el-button
  68. :class="{ refresh, bgc: istrue }"
  69. size="small"
  70. type="info"
  71. @click="refresh"
  72. :disabled="istrue"
  73. >{{ button }}</el-button
  74. >
  75. </div>
  76. </div>
  77. </div></el-card
  78. >
  79. </div>
  80. <div class="left-center1">
  81. <el-card
  82. ><div><manage v-if="listData" :listData="listData"></manage></div
  83. ></el-card>
  84. </div>
  85. <div class="left-center2">
  86. <el-card
  87. ><project-data v-if="listData" :listData="listData"></project-data
  88. ></el-card>
  89. </div>
  90. <!-- <div class="left-bottom"><el-card></el-card></div> -->
  91. </div>
  92. <!-- 中间部分 -->
  93. <div class="center">
  94. <div class="center-top">
  95. <el-card
  96. ><programAmount
  97. v-if="listData"
  98. :listData="listData"
  99. ></programAmount
  100. ></el-card>
  101. </div>
  102. <div class="center-center">
  103. <el-card
  104. ><BprogramAmount
  105. v-if="listData"
  106. :listData="listData"
  107. ></BprogramAmount
  108. ></el-card>
  109. </div>
  110. <div class="center-bottom">
  111. <el-card
  112. ><div>
  113. <product-ratio
  114. v-if="listData"
  115. :listData="listData.product_ratio"
  116. ></product-ratio
  117. ><project-ratio
  118. v-if="listData"
  119. :listData="listData.project_proportion"
  120. ></project-ratio></div
  121. ></el-card>
  122. </div>
  123. </div>
  124. <!-- 右边部分 -->
  125. <div class="right">
  126. <div class="right-top">
  127. <el-card
  128. ><recharge-data
  129. v-if="listData"
  130. :listData="listData"
  131. ></recharge-data
  132. ></el-card>
  133. </div>
  134. <div class="right-center">
  135. <el-card
  136. ><cardExpend v-if="listData" :listData="listData"></cardExpend
  137. ></el-card>
  138. </div>
  139. <div class="right-bottom">
  140. <el-card>
  141. <productData v-if="listData" :listData="listData"></productData
  142. ></el-card>
  143. </div>
  144. </div>
  145. </div>
  146. </div>
  147. <!-- </Resize> -->
  148. </div>
  149. </template>
  150. <script>
  151. import Resize from "../util/Resize.vue";
  152. import manage from "./manage/manage.vue";
  153. import projectData from "./projectData/projectData.vue";
  154. import programAmount from "./programAmount/programAmount.vue";
  155. import projectRatio from "./projectRatio/projectRatio.vue";
  156. import productRatio from "./productRatio/productRatio.vue";
  157. import rechargeData from "./rechargeData/rechargeData.vue";
  158. import cardExpend from "./cardExpend/cardExpend.vue";
  159. import productData from "./productData/productData.vue";
  160. import BprogramAmount from "./BprogramAmount/BprogramAmount.vue";
  161. import { getStoreList, getData } from "../api/index"; //获取店铺列表和数据大屏数据
  162. export default {
  163. components: {
  164. Resize,
  165. manage,
  166. projectData,
  167. programAmount,
  168. projectRatio,
  169. productRatio,
  170. rechargeData,
  171. cardExpend,
  172. productData,
  173. BprogramAmount
  174. },
  175. data() {
  176. return {
  177. store: "全部店铺",
  178. storeList: "", //店铺列表
  179. storeId: "", //当前店铺id
  180. listData: "", //项目总数据
  181. flag: false, //获取数据开关阀
  182. start_time: "", //开始时间
  183. end_time: "", //结束时间
  184. value1: [new Date(), new Date()], //选择日期当前时间
  185. button: "刷新", //按钮提交文案
  186. istrue: false, //刷新禁用
  187. refreshInfo: "秒",
  188. count: 10, //点击刷新倒计时
  189. activeClass: 3, //按钮动态类
  190. };
  191. },
  192. methods: {
  193. // 选择店铺
  194. async selectStore(e) {
  195. this.store = e;
  196. this.storeList.filter((item) => {
  197. if (item.store_name == e) {
  198. this.storeId = item.id;
  199. }
  200. });
  201. this.getListData();
  202. },
  203. // 选择昨天
  204. yesterday(e) {
  205. this.activeClass = e;
  206. var startTime = this.getDay1(-1, "-") + " 00:00:00"; // -1 代表前一天,-2前两天...
  207. var endTime = this.getDay1(-1, "-") + " 23:59:59"; // -1 代表前一天,-2前两天...
  208. this.start_time = Date.parse(startTime) / 1000;
  209. this.end_time = Date.parse(endTime) / 1000;
  210. var startTime1 = this.getDay1(-1, "-");
  211. var endTime1 = this.getDay1(-1, "-");
  212. this.$set(this.value1, 0, startTime1);
  213. this.$set(this.value1, 1, endTime1);
  214. this.getListData();
  215. },
  216. //本周
  217. thisWeek(e) {
  218. this.activeClass = e;
  219. var now = new Date();
  220. var nowDayOfWeek = now.getDay() == 0 ? 6 : now.getDay() - 1;
  221. var startTime =
  222. this.getDateStr(
  223. new Date(now.getTime() - nowDayOfWeek * 24 * 60 * 60 * 1000)
  224. ) + " 00:00:00";
  225. var endTime = this.getDateStr(now) + " 23:59:59";
  226. this.start_time = Date.parse(startTime) / 1000;
  227. this.end_time = Date.parse(endTime) / 1000;
  228. var startTime1 = this.getDateStr(
  229. new Date(now.getTime() - nowDayOfWeek * 24 * 60 * 60 * 1000)
  230. );
  231. var endTime1 = this.getDateStr(now);
  232. this.$set(this.value1, 0, startTime1);
  233. this.$set(this.value1, 1, endTime1);
  234. this.getListData();
  235. },
  236. // 本月
  237. thisMonth(e) {
  238. this.activeClass = e;
  239. var now = new Date();
  240. var nowDay = now.getDate() - 1;
  241. var startTime =
  242. this.getDateStr(
  243. new Date(now.getTime() - nowDay * 24 * 60 * 60 * 1000)
  244. ) + " 00:00:00";
  245. var endTime = this.getDateStr(now) + " 23:59:59";
  246. this.start_time = Date.parse(startTime) / 1000;
  247. this.end_time = Date.parse(endTime) / 1000;
  248. var startTime1 = this.getDateStr(
  249. new Date(now.getTime() - nowDay * 24 * 60 * 60 * 1000)
  250. );
  251. var endTime1 = this.getDateStr(now);
  252. this.$set(this.value1, 0, startTime1);
  253. this.$set(this.value1, 1, endTime1);
  254. this.getListData();
  255. },
  256. // 封装获取时间
  257. getDateStr(now) {
  258. var year = now.getFullYear(); // 年
  259. var month = now.getMonth() + 1; // 月
  260. var day = now.getDate(); // 日
  261. if (day < 10) {
  262. day = "0" + day;
  263. }
  264. if (month < 10) {
  265. month = "0" + month;
  266. }
  267. return year + "-" + month + "-" + day;
  268. },
  269. // 封装获取昨天时间
  270. getDay1(num, str) {
  271. var today = new Date();
  272. var nowTime = today.getTime();
  273. var ms = 24 * 3600 * 1000 * num;
  274. today.setTime(parseInt(nowTime + ms));
  275. var oYear = today.getFullYear();
  276. var oMoth = (today.getMonth() + 1).toString();
  277. if (oMoth.length <= 1) oMoth = "0" + oMoth;
  278. var oDay = today.getDate().toString();
  279. if (oDay.length <= 1) oDay = "0" + oDay;
  280. return oYear + str + oMoth + str + oDay;
  281. },
  282. // 获取图表数据
  283. async getListData() {
  284. let res = await getData({
  285. store_id: this.storeId || "",
  286. start_time: this.start_time,
  287. end_time: this.end_time,
  288. });
  289. console.log(res);
  290. this.listData = res.data.data;
  291. },
  292. // 获取店铺列表
  293. async getStoreList() {
  294. let res = await getStoreList();
  295. let allStore = { id: "", store_name: "全部店铺" };
  296. res.data.data.unshift(allStore);
  297. this.storeList = res.data.data;
  298. },
  299. // 选择时间
  300. selectTime(e) {
  301. var startTime = this.getDateStr(e[0]) + " 00:00:00";
  302. var endTime = this.getDateStr(e[1]) + " 23:59:59";
  303. var start_time = Date.parse(startTime) / 1000;
  304. var end_time = Date.parse(endTime) / 1000;
  305. this.start_time = start_time;
  306. this.end_time = end_time;
  307. console.log(start_time, end_time);
  308. this.getListData();
  309. },
  310. // 刷新页面
  311. refresh() {
  312. this.getListData();
  313. this.istrue = true;
  314. let interval = setInterval(() => {
  315. this.count--;
  316. this.button = this.count + this.refreshInfo;
  317. if (this.count == 0) {
  318. clearInterval(interval);
  319. this.istrue = false;
  320. this.count = 10;
  321. this.button = "刷新";
  322. }
  323. }, 1000);
  324. },
  325. },
  326. async created() {
  327. // 获取店铺列表
  328. this.getStoreList();
  329. // 获取当天时间
  330. var now = new Date();
  331. var endTime = this.getDateStr(now) + " 23:59:59";
  332. var startTime = this.getDateStr(now) + " 00:00:00";
  333. var start_time = Date.parse(startTime) / 1000;
  334. var end_time = Date.parse(endTime) / 1000;
  335. this.start_time = start_time;
  336. this.end_time = end_time;
  337. // 获取当天所有店铺数据
  338. let res = await getData({
  339. store_id: "",
  340. start_time: start_time,
  341. end_time: end_time,
  342. });
  343. this.listData = res.data.data;
  344. this.flag = true;
  345. },
  346. };
  347. </script>
  348. <style scoped lang='less'>
  349. .title {
  350. font-size: 30px;
  351. font-weight: 700;
  352. text-align: center;
  353. background-color: #f0f0f0;
  354. color: #fa7d22;
  355. height: 60px;
  356. line-height: 60px;
  357. width: 100%;
  358. }
  359. .box {
  360. width: 100%;
  361. height: 93%;
  362. background-color: #f0f0f0;
  363. .pic {
  364. width: 100%;
  365. height: 87%;
  366. display: flex;
  367. .left {
  368. width: 22%;
  369. height: 100%;
  370. margin-right: 15px;
  371. margin-left: 15px;
  372. .left-top {
  373. width: 100%;
  374. height: 24%;
  375. .el-card {
  376. .btn {
  377. button.el-button.el-button--info.el-button--small {
  378. background-color: #fa7d22;
  379. border: #fa7d22;
  380. }
  381. .selectStore {
  382. margin-top: 14px;
  383. /deep/.el-range-editor--mini.el-input__inner {
  384. height: 30px;
  385. width: 290px;
  386. border: 1px solid #fa7d22;
  387. }
  388. .Store {
  389. margin-top: 14px;
  390. margin-right: 14px;
  391. }
  392. .refresh {
  393. margin-top: 14px;
  394. }
  395. }
  396. }
  397. }
  398. }
  399. .left-center1 {
  400. width: 100%;
  401. height: 43%;
  402. margin-top: 15px;
  403. }
  404. .left-center2 {
  405. width: 100%;
  406. height: 43%;
  407. margin-top: 15px;
  408. }
  409. // .left-bottom {
  410. // width: 100%;
  411. // height: 25%;
  412. // margin-top: 15px;
  413. // }
  414. }
  415. .center {
  416. width: 50%;
  417. height: 100%;
  418. margin-right: 15px;
  419. .center-top {
  420. height: 38%;
  421. width: 100%;
  422. }
  423. .center-center {
  424. margin-top: 15px;
  425. height: 33%;
  426. width: 100%;
  427. }
  428. .center-bottom {
  429. height: 39%;
  430. width: 100%;
  431. margin-top: 15px;
  432. .el-card {
  433. div {
  434. display: flex;
  435. justify-content: space-around;
  436. }
  437. }
  438. }
  439. }
  440. .right {
  441. width: 28%;
  442. height: 100%;
  443. margin-right: 15px;
  444. .right-top {
  445. width: 100%;
  446. height: 39%;
  447. }
  448. .right-center {
  449. height: 39%;
  450. width: 100%;
  451. margin-top: 15px;
  452. }
  453. .right-bottom {
  454. height: 32%;
  455. width: 100%;
  456. margin-top: 15px;
  457. }
  458. }
  459. }
  460. }
  461. .el-card {
  462. width: 100%;
  463. height: 100%;
  464. }
  465. // 点击选中后背景颜色
  466. .bgc {
  467. background-color: #9fa0a6 !important;
  468. }
  469. .boxx {
  470. width: 100vw;
  471. height: 100vh;
  472. background-color: #f0f0f0;
  473. }
  474. </style>