statisticalReport.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. <template>
  2. <div class="home">
  3. <div class="report-page">
  4. <!-- 查询条件 -->
  5. <a-row>
  6. <a-card class="search-panel">
  7. <div class="toolsBar">
  8. <a-form ref="searchForm" :model="searchForm" layout="inline">
  9. <a-form-item props="queryWord" label="统计区间">
  10. <a-range-picker style="width: 220px;" @change="dateChange" v-model.trim="searchForm.queryWord" :disabledDate="disabledDate" />
  11. </a-form-item>
  12. <a-form-item props="storeIds" label="清运网点">
  13. <a-select
  14. allowClear
  15. mode="multiple"
  16. placeholder="选择网点"
  17. v-model="searchForm.storeIdList"
  18. style="width: 200px"
  19. option-filter-prop="children"
  20. :filter-option="filterOption"
  21. >
  22. <a-select-option :disabled="!isStationAll && searchForm.storeIdList.length > 0" value="all" key="all">全部</a-select-option>
  23. <a-select-option :disabled="isStationAll" v-for="item in stationList" :value="item.stationNo" :key="item.id">{{ item.name }}</a-select-option>
  24. </a-select>
  25. </a-form-item>
  26. <a-form-item>
  27. <a-button type="primary" class="search-btn" @click="handleSearch()">查询</a-button>
  28. <a-button type="" style="margin-left: 10px;" @click="handleReset()">重置</a-button>
  29. </a-form-item>
  30. <a-form-item>
  31. 快捷筛选:
  32. <span :class="['searchItem', curentType == item.type ? 'active' : '']" v-for="(item, index) in tabList" :key="index" @click="getCurentSearchTime(item)">
  33. {{ item.name }}
  34. </span>
  35. </a-form-item>
  36. </a-form>
  37. </div>
  38. </a-card>
  39. </a-row>
  40. <!-- 清运量数据 -->
  41. <a-card class="panel" title="清运量趋势">
  42. <!-- 清运量趋势图表展示 -->
  43. <chart-line
  44. style="height: 300px;"
  45. ref="chartLine"
  46. yUnit="kg"
  47. :xAxisRotate="resize"
  48. :xAxisData="XdaysData"
  49. :seriesData="clearnChartData"
  50. :color="washTypePieColor"
  51. text=""
  52. />
  53. <span v-if="isNoData" class="noData">暂无数据</span>
  54. </a-card>
  55. <!-- 各回收物类型数据 -->
  56. <a-card class="panel " title="各回收物类型清运数据">
  57. <a-row :gutter="24">
  58. <a-col :md="24" :lg="24">
  59. <div style="display: flex;align-items: center;">
  60. <div v-for="(item, index) in qyTotalPieData" :key="index" class="module-list" :style="{ background: washTypePieColor[index] }">
  61. <p>{{ item.name }}</p>
  62. <span>{{ item.value }} kg</span>
  63. </div>
  64. </div>
  65. </a-col>
  66. </a-row>
  67. <!-- 各回收物类型数据图表展示 -->
  68. <a-row :gutter="24">
  69. <a-col class="tab-card">
  70. <span :class="['tab-card-item', currentTabChart == 'tab1' ? 'checked-item' : '']" @click="currentTabChart = 'tab1'">详情数据</span>
  71. <span :class="['tab-card-item', currentTabChart == 'tab2' ? 'checked-item' : '']" @click="currentTabChart = 'tab2'">变化趋势</span>
  72. </a-col>
  73. <!-- 详情数据 -->
  74. <a-col span="24" v-if="currentTabChart == 'tab1'">
  75. <chart-bar
  76. ref="ChartBar"
  77. style="height: 300px;"
  78. :xAxisRotate="resize"
  79. yUnit="kg"
  80. :xAxisData="XdaysData1"
  81. :seriesData="hswTypeBarData"
  82. :color="washTypePieColor" />
  83. <span v-if="isNoData1" class="noData">暂无数据</span>
  84. </a-col>
  85. <!-- 变化趋势 -->
  86. <a-col span="24" v-if="currentTabChart == 'tab2'">
  87. <chart-line
  88. ref="ChartLine"
  89. style="height: 300px;"
  90. yUnit="kg"
  91. :xAxisRotate="resize"
  92. :xAxisData="XdaysData1"
  93. :seriesData="hswTypeLineData"
  94. :color="washTypePieColor" />
  95. <span v-if="isNoData1" class="noData">暂无数据</span>
  96. </a-col>
  97. </a-row>
  98. </a-card>
  99. <a-row :gutter="24">
  100. <a-col span="12">
  101. <a-card class="panel chart-pie" title="各回收物类型占比">
  102. <chart-pie
  103. ref="chartPie"
  104. class="chartPie-box"
  105. :value="qyTotalPieData"
  106. title="清运总量(kg)"
  107. :total="totalGroupRubbiData.cleanWeight"
  108. :color="washTypePieColor"
  109. :xAxisRotate="resize"
  110. text=""
  111. />
  112. </a-card>
  113. </a-col>
  114. <a-col span="12">
  115. <a-card class="panel chart-pie" title="各清运司机占比">
  116. <!-- 各清运司机占比 百分比展示 -->
  117. <chart-pie
  118. ref="serverChartPie"
  119. class="chartPie-box"
  120. :value="sjTotalPieData"
  121. title="清运总量(台)"
  122. :total="totalGroupUserData.cleanWeight"
  123. :color="couponColor"
  124. :xAxisRotate="resize"
  125. text=""
  126. />
  127. </a-card>
  128. </a-col>
  129. </a-row>
  130. </div>
  131. </div>
  132. </template>
  133. <script>
  134. import { ChartPie, ChartBar, ChartLine } from '@/components/Echarts'
  135. import _ from 'lodash'
  136. import getDate from '@/libs/getDate'
  137. import moment from 'moment'
  138. import { findTotalGroupRubbi, findTotalGroupUser, findTotalGroupDate, findTotalGroupDateAndRubbishType } from '@/api/cleanManage.js'
  139. import { stationList } from '@/api/releaseRecord.js'
  140. import { getLookUpData } from '@/api/data'
  141. export default {
  142. name: 'Home',
  143. components: {
  144. ChartPie,
  145. ChartBar,
  146. ChartLine
  147. },
  148. watch: {
  149. screenWidth (val) {
  150. // 为了避免频繁触发resize函数,使用定时器
  151. if (!this.timer) {
  152. this.screenWidth = val
  153. this.timer = true
  154. const that = this
  155. setTimeout(function () {
  156. // that.screenWidth = that.$store.state.canvasWidth
  157. console.log(that.screenWidth)
  158. that.timer = false
  159. }, 400)
  160. }
  161. }
  162. },
  163. computed: {
  164. isStationAll () {
  165. // 是否选择全部网点
  166. let boolean
  167. if (this.searchForm.storeIdList.length > 0) {
  168. if (this.searchForm.storeIdList.indexOf('all') >= 0) {
  169. boolean = true
  170. } else {
  171. boolean = false
  172. }
  173. } else {
  174. boolean = false
  175. }
  176. return boolean
  177. },
  178. resize () {
  179. if (this.screenWidth < 1640) {
  180. return 40
  181. } else {
  182. return 30
  183. }
  184. },
  185. // 各回收物类型占比
  186. qyTotalPieData () {
  187. const list = this.totalGroupRubbiData ? this.totalGroupRubbiData.cleanReportData : []
  188. const temp = []
  189. if (list) {
  190. list.map(item => {
  191. temp.push({
  192. name: item.rubbishTypeDictValue,
  193. value: Number(item.cleanWeight / 1000).toFixed(2)
  194. })
  195. })
  196. }
  197. return temp
  198. },
  199. // 各清运司机占比
  200. sjTotalPieData () {
  201. const list = this.totalGroupUserData ? this.totalGroupUserData.cleanReportData : []
  202. const temp = []
  203. if (list) {
  204. list.map(item => {
  205. temp.push({
  206. name: item.operatorName,
  207. value: Number(item.cleanWeight / 1000).toFixed(2)
  208. })
  209. })
  210. }
  211. return temp
  212. }
  213. },
  214. data () {
  215. return {
  216. screenWidth: document.body.clientWidth, // 这里是给到了一个默认值
  217. timer: false,
  218. form: this.$form.createForm(this, { name: 'searchForm' }),
  219. isNoData: false, // 是否有每天营业额及进店量数据
  220. isNoData1: false,
  221. stationList: [], // 清运网点列表
  222. searchForm: {
  223. queryWord: null, // 时间查询条件,默认本周
  224. storeIdList: [] // 已选清运网点
  225. },
  226. // 快速删选tab
  227. tabList: [
  228. {
  229. name: '今天',
  230. type: 'today'
  231. },
  232. {
  233. name: '本周',
  234. type: 'thisWeek'
  235. },
  236. {
  237. name: '上周',
  238. type: 'lastWeek'
  239. },
  240. {
  241. name: '本月',
  242. type: 'thisMonth'
  243. }
  244. ],
  245. curentType: 'thisWeek', // 当前所选时间查询类型
  246. beginDate: null, // 开始时间
  247. endDate: null, // 结束时间
  248. // 各回收物类型占比
  249. totalGroupRubbiData: {
  250. cleanWeight: 0,
  251. cleanReportData: []
  252. },
  253. // 各清运司机占比
  254. totalGroupUserData: {
  255. cleanWeight: 0,
  256. cleanReportData: []
  257. },
  258. // 洗车类型数据
  259. currentTabChart: 'tab1', // 洗车类型详情数据与变化趋势的tab 默认展示详情数据
  260. XdaysData: [], // 图表X轴时间集合
  261. XdaysData1: [],
  262. // 各类型占比
  263. washTypePieColor: ['#ffaa00', '#00aa00', '#00aaff', '#ff55ff', '#1dc5d4', '#8465c7', '#ff5500', '#527aff'],
  264. couponColor: ['#ffaa00', '#ff5500', '#00aaff', '#ff55ff', '#1dc5d4', '#8465c7', '#55aa00', '#527aff'],
  265. // 清运量趋势
  266. clearnChartData: [
  267. {
  268. name: '投递量',
  269. type: 'line',
  270. data: []
  271. },
  272. {
  273. name: '清运量',
  274. type: 'line',
  275. data: []
  276. }
  277. ],
  278. hswTypeBarData: [],
  279. hswTypeLineData: []
  280. }
  281. },
  282. methods: {
  283. moment,
  284. // 时间改变
  285. dateChange (dates) {
  286. this.curentType = ''
  287. },
  288. // 不可选日期
  289. disabledDate (date) {
  290. return (date && date.valueOf() > Date.now()) || date.valueOf() < Date.now() - 90 * 24 * 60 * 60 * 1000
  291. },
  292. filterOption (input, option) {
  293. return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  294. },
  295. // 查询分类数据字典
  296. getTypeCode (params) {
  297. const _this = this
  298. getLookUpData({
  299. pageNo: 1,
  300. pageSize: 1000,
  301. lookupCode: 'RUBBISH_TYPE'
  302. }).then(res => {
  303. const list = res.data.list
  304. list.map(item => {
  305. // 柱状图
  306. _this.hswTypeBarData.push({
  307. name: item.dispName,
  308. code: item.code,
  309. type: 'bar',
  310. data: []
  311. })
  312. // 折线图
  313. _this.hswTypeLineData.push({
  314. name: item.dispName,
  315. code: item.code,
  316. type: 'line',
  317. data: []
  318. })
  319. })
  320. setTimeout(() => {
  321. _this.getGroupDateAndRubbishType(params)
  322. }, 500)
  323. })
  324. },
  325. // 查询网点列表
  326. getListStation () {
  327. stationList().then(res => {
  328. if (res.status == 200) {
  329. this.stationList = res.data || []
  330. } else {
  331. this.stationList = []
  332. }
  333. })
  334. },
  335. // 页面初始化
  336. pageInit () {
  337. this.form.resetFields()
  338. },
  339. // 查询
  340. handleSearch () {
  341. this.showChart = false
  342. if (this.searchForm.queryWord != ',' && this.searchForm.queryWord.length) {
  343. const searchTime = this.searchForm.queryWord.toString().split(',')
  344. this.beginDate = this.exitTime(searchTime[0])
  345. this.endDate = this.exitTime(searchTime[1])
  346. this.XdaysData = []
  347. this.XdaysData1 = []
  348. this.getPageData()
  349. } else {
  350. this.$message.error('请选择统计区间')
  351. }
  352. },
  353. // 重置
  354. handleReset () {
  355. this.searchForm.storeIdList = []
  356. this.curentType = 'thisWeek'
  357. this.getCurentSearchTime()
  358. },
  359. // 格式化时间
  360. exitTime (time) {
  361. const D = new Date(time)
  362. const RES_DATE = D.getFullYear() + '-' + this.p(D.getMonth() + 1) + '-' + this.p(D.getDate())
  363. return RES_DATE
  364. },
  365. // p为不够10添加0的函数
  366. p (s) {
  367. return s < 10 ? '0' + s : s
  368. },
  369. // 获取快速查询时间 并 赋值到时间选择框中
  370. getCurentSearchTime (item) {
  371. this.curentType = item ? item.type : this.curentType
  372. const quickType = {
  373. lastMonth: [moment(getDate.getLastMonthDays().starttime), moment(getDate.getLastMonthDays().endtime)],
  374. thisMonth: [moment(getDate.getCurrMonthDays().starttime), moment(getDate.getCurrMonthDays().endtime)],
  375. lastWeek: [moment(getDate.getLastWeekDays().starttime), moment(getDate.getLastWeekDays().endtime)],
  376. thisWeek: [moment(getDate.getCurrWeekDays().starttime), moment(getDate.getCurrWeekDays().endtime)],
  377. yesterday: [moment(getDate.getYesterday().starttime), moment(getDate.getYesterday().endtime)],
  378. today: [moment(getDate.getToday().starttime), moment(getDate.getToday().endtime)]
  379. }
  380. console.log(quickType[this.curentType])
  381. this.searchForm.queryWord = quickType[this.curentType]
  382. this.beginDate = quickType[this.curentType][0].format('YYYY-MM-DD')
  383. this.endDate = quickType[this.curentType][1].format('YYYY-MM-DD')
  384. console.log(this.searchForm.queryWord, '1111111')
  385. this.getPageData()
  386. },
  387. // 重置图表数据
  388. resetChartsData () {
  389. this.XdaysData = [] // x轴置空
  390. this.XdaysData1 = [] // x轴置空
  391. // 各回收物类型占比
  392. this.totalGroupRubbiData = {
  393. cleanWeight: 0,
  394. cleanReportData: []
  395. }
  396. // 各清运司机占比
  397. this.totalGroupUserData = {
  398. cleanWeight: 0,
  399. cleanReportData: []
  400. }
  401. // 重置清运量趋势图表数据
  402. this.clearnChartData[0].data = []
  403. this.clearnChartData[1].data = []
  404. // 重置各回收物类型清运数据
  405. this.hswTypeBarData.map(item => (item.data = []))
  406. this.hswTypeLineData.map(item => (item.data = []))
  407. },
  408. // 根据查询条件获取所有数据
  409. getPageData () {
  410. this.resetChartsData()
  411. const params = {
  412. beginDate: this.beginDate + ' 00:00:00',
  413. endDate: this.endDate + ' 00:00:00',
  414. storeIdList: this.searchForm.storeIdList
  415. }
  416. // 各回收物类型占比
  417. findTotalGroupRubbi(params).then(res => {
  418. console.log(res, '各回收物类型占比')
  419. if (res.status == 200) {
  420. this.totalGroupRubbiData = res.data
  421. }
  422. })
  423. // 各清运司机占比
  424. findTotalGroupUser(params).then(res => {
  425. console.log(res, '各清运司机占比')
  426. if (res.status == 200) {
  427. this.totalGroupUserData = res.data
  428. }
  429. })
  430. // 清运量趋势
  431. findTotalGroupDate(params).then(res => {
  432. console.log(res, '清运量趋势')
  433. if (res.status == 200) {
  434. const a = res.data.deliveryReportData
  435. const b = res.data.cleanReportData
  436. for (const key in a) {
  437. const val = Number(a[key] / 1000).toFixed(2)
  438. this.clearnChartData[0].data.push(val)
  439. }
  440. for (const key in b) {
  441. this.XdaysData.push(key)
  442. const val = Number(b[key] / 1000).toFixed(2)
  443. this.clearnChartData[1].data.push(val)
  444. }
  445. this.isNoData = false
  446. } else {
  447. this.isNoData = true
  448. }
  449. })
  450. if (this.hswTypeBarData.length == 0) {
  451. this.getTypeCode(params)
  452. } else {
  453. this.getGroupDateAndRubbishType(params)
  454. }
  455. },
  456. // 各回收物类型清运数据柱状图
  457. getGroupDateAndRubbishType (params) {
  458. findTotalGroupDateAndRubbishType(params).then(res => {
  459. console.log(res, '各回收物类型清运数据柱状图')
  460. if (res.status == 200 && res.data.cleanReportData) {
  461. const data = res.data.cleanReportData
  462. // x 时间轴
  463. for (const key in data) {
  464. this.XdaysData1.push(key)
  465. }
  466. this.hswTypeBarData = this.formAtGroupDateAndRubbishType(data, this.hswTypeBarData)
  467. this.hswTypeLineData = this.formAtGroupDateAndRubbishType(data, this.hswTypeLineData)
  468. this.isNoData1 = false
  469. } else {
  470. this.isNoData1 = true
  471. }
  472. })
  473. },
  474. // 格式化数据
  475. formAtGroupDateAndRubbishType (data, obj) {
  476. obj.map(item => {
  477. const ret = []
  478. for (const key in data) {
  479. const leve2 = data[key]
  480. const row = leve2[item.code]
  481. const val = row ? Number(row.cleanWeight / 1000).toFixed(2) : 0
  482. ret.push(val)
  483. }
  484. item.data = ret
  485. })
  486. return obj
  487. }
  488. },
  489. beforeRouteEnter (to, from, next) {
  490. next(vm => {
  491. vm.pageInit()
  492. vm.getListStation() // 获取网点列表
  493. vm.curentType = 'thisWeek'
  494. vm.getCurentSearchTime()
  495. })
  496. },
  497. // 将 reisze 事件在 vue mounted 的时候 去挂载一下它的方法
  498. mounted () {
  499. const that = this
  500. window.onresize = () => {
  501. return (() => {
  502. window.screenWidth = document.body.clientWidth
  503. that.screenWidth = window.screenWidth
  504. })()
  505. }
  506. }
  507. }
  508. </script>
  509. <style lang="less" scoped>
  510. .home {
  511. width: 100%;
  512. }
  513. .report-page {
  514. margin-top: 10px;
  515. overflow-y: scroll;
  516. overflow-x: hidden;
  517. .search-panel {
  518. .ivu-card-body > div {
  519. display: inline-block;
  520. margin-right: 20px;
  521. }
  522. .desc {
  523. color: #999;
  524. }
  525. .searchItem {
  526. padding: 8px 20px;
  527. border: 1px dashed #eeeeee;
  528. margin: 0 5px;
  529. border-radius: 5px;
  530. }
  531. .active {
  532. background-color: #ff9900;
  533. color: #fff;
  534. border: none;
  535. }
  536. }
  537. .search-panel /deep/ .ant-select-selection {
  538. max-height: 150px;
  539. overflow: auto;
  540. }
  541. .panel {
  542. margin-top: 10px;
  543. background-color: #ffffff;
  544. .noData {
  545. background-color: rgba(50, 50, 50, 0.7);
  546. color: #fff;
  547. padding: 15px 30px;
  548. position: absolute;
  549. top: 40%;
  550. left: 40%;
  551. }
  552. .chartPie-box {
  553. height: 300px;
  554. max-width: 600px;
  555. margin: 0 auto;
  556. }
  557. .panel-title {
  558. font-size: 18px;
  559. color: #333;
  560. padding-bottom: 5px;
  561. }
  562. .tab-card {
  563. float: right;
  564. .tab-card-item {
  565. padding: 5px 10px;
  566. border: 1px solid #eee;
  567. cursor: pointer;
  568. }
  569. .checked-item {
  570. border-color: #2d8cf0;
  571. color: #2d8cf0;
  572. }
  573. }
  574. }
  575. .module-list {
  576. color: #ffffff;
  577. height: 100px;
  578. padding: 10px;
  579. border-radius: 15px;
  580. display: flex;
  581. align-items: center;
  582. flex-direction: column;
  583. margin: 5px;
  584. span {
  585. font-weight: 600;
  586. font-size: 20px;
  587. }
  588. }
  589. .module-icon {
  590. width: 52px;
  591. height: 54px;
  592. }
  593. }
  594. </style>