index.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. <template>
  2. <div class="dashboard_container">
  3. <div class="refresh">
  4. <el-date-picker
  5. style="width: 130px"
  6. v-model="value1"
  7. format="yyyy"
  8. size="mini"
  9. type="year"
  10. placeholder="选择日期"
  11. >
  12. </el-date-picker>
  13. <span style="color: #1d82ff; margin-left: 20px" @click="refreshData">刷新数据</span>
  14. <i class="el-icon-refresh-left" style="color: #1d82ff" @click="refreshData"></i>
  15. </div>
  16. <div class="container_top">
  17. <div class="tab" v-for="(item, index) in tabs" :key="index" @click="openOrder(item.type, item.title)">
  18. <el-image class="img" :src="item.url" fit="fit"></el-image>
  19. <div class="text">
  20. <div class="title">{{ item.title }}</div>
  21. <div class="num">{{ item.num }}</div>
  22. </div>
  23. </div>
  24. </div>
  25. <div class="container_center">
  26. <div class="chart">
  27. <div class="head">
  28. <div class="title">近7天订单趋势</div>
  29. <div class="more" @click="openOrder()">查看更多</div>
  30. </div>
  31. <div ref="chart1" style="width: 100%; height: 280px"></div>
  32. </div>
  33. <div class="chart">
  34. <div class="head">
  35. <div class="title">未来7天需上门</div>
  36. </div>
  37. <div ref="chart2" style="width: 100%; height: 280px"></div>
  38. </div>
  39. </div>
  40. <div class="container_bottom">
  41. <div class="chart">
  42. <div class="head">
  43. <div class="title">近30天完工类型分布</div>
  44. </div>
  45. <div ref="chart3" style="width: 100%; height: 330px"></div>
  46. </div>
  47. </div>
  48. </div>
  49. </template>
  50. <script>
  51. import { getCount } from '@/api/workOrder/orderHome'
  52. export default {
  53. data() {
  54. return {
  55. tabs: [
  56. { title: '待派工', num: 0, url: require('@/assets/orderHome/dpg.png'), type: 'DWDPG' },
  57. { title: '待预约', num: 0, url: require('@/assets/orderHome/dpg.png'), type: 'DYY' },
  58. { title: '待抢单', num: 0, url: require('@/assets/orderHome/djs.png'), type: 'DQD' },
  59. { title: '待接收', num: 0, url: require('@/assets/orderHome/djs.png'), type: 'DJD' },
  60. { title: '服务中', num: 0, url: require('@/assets/orderHome/ffz.png'), type: 'FWZ' },
  61. { title: '异常待处理', num: 0, url: require('@/assets/orderHome/yc.png'), type: 'YCD' },
  62. { title: '差评统计', num: 0, url: require('@/assets/orderHome/pj.png'), type: 'appraise' }
  63. ],
  64. qtsm: [],
  65. qtddqs: {},
  66. wglxfb: {},
  67. value1: new Date()
  68. }
  69. },
  70. watch: {
  71. value1(newVal) {
  72. this.getCount()
  73. }
  74. },
  75. computed: {
  76. getDate() {
  77. return function (d, t) {
  78. var date = new Date()
  79. var base = Date.parse(date) // 转换为时间戳
  80. var year = date.getFullYear() //获取当前年份
  81. var mon = date.getMonth() + 1 //获取当前月份
  82. var day = date.getDate() //获取当前日
  83. var oneDay = 24 * 3600 * 1000
  84. var daytimeArr = []
  85. for (var i = 0; i < d; i++) {
  86. //前七天的时间
  87. var now = new Date(t == 'before' ? base - oneDay * i : base + oneDay * i)
  88. var myear = now.getFullYear()
  89. var month = now.getMonth() + 1
  90. var mday = now.getDate()
  91. daytimeArr.push([month >= 10 ? month : '0' + month, mday >= 10 ? mday : '0' + mday].join('-'))
  92. }
  93. return t == 'before' ? daytimeArr.reverse() : daytimeArr
  94. }
  95. },
  96. filterOrderType() {
  97. return function (obj, type) {
  98. let names = []
  99. let series = []
  100. for (let key in this[obj]) {
  101. names.push(key)
  102. series.push({
  103. name: key,
  104. data: this[obj][key],
  105. type: 'line',
  106. smooth: true
  107. })
  108. }
  109. return type == 'name' ? names : series
  110. }
  111. }
  112. },
  113. created() {
  114. this.getCount()
  115. },
  116. mounted() {
  117. // this.drawChat1()
  118. },
  119. methods: {
  120. refreshData() {
  121. this.$echarts.init(this.$refs.chart1).dispose()
  122. this.$echarts.init(this.$refs.chart2).dispose()
  123. this.$echarts.init(this.$refs.chart3).dispose()
  124. this.getCount()
  125. },
  126. openOrder(type, name) {
  127. if (!type) {
  128. this.$router.push({
  129. name: window.isWorkOrderPoolPath,
  130. query: {}
  131. })
  132. } else if (type == 'appraise') {
  133. this.$router.push({
  134. name: 'appraise',
  135. query: {
  136. type: 1
  137. }
  138. })
  139. } else {
  140. this.$router.push({
  141. name: window.isWorkOrderPoolPath,
  142. params: {
  143. pageName: name || '-',
  144. pageType: 'orderStatus',
  145. pageCode: type
  146. }
  147. })
  148. }
  149. },
  150. getCount() {
  151. getCount(
  152. this.value1
  153. ? {
  154. startTime: `${new Date(this.value1).getFullYear()}-01-01 00:00:00`,
  155. endTime: `${new Date(this.value1).getFullYear()}-12-31 23:59:59`
  156. }
  157. : {}
  158. ).then(res => {
  159. this.tabs[0].num = res.data.dpg || 0
  160. this.tabs[1].num = res.data.dyy || 0
  161. this.tabs[2].num = res.data.dqd || 0
  162. this.tabs[3].num = res.data.djs || 0
  163. this.tabs[4].num = res.data.fwz || 0
  164. this.tabs[5].num = res.data.ycdcl || 0
  165. this.tabs[6].num = res.data.cp || 0
  166. this.qtsm = res.data.qtsm
  167. this.qtddqs = res.data.qtddqs
  168. this.wglxfb = res.data.wglxfb
  169. this.drawChat1()
  170. })
  171. },
  172. drawChat1() {
  173. let chart1 = this.$echarts.init(this.$refs.chart1)
  174. let chart2 = this.$echarts.init(this.$refs.chart2)
  175. let chart3 = this.$echarts.init(this.$refs.chart3)
  176. let option1 = {
  177. tooltip: {
  178. trigger: 'axis'
  179. },
  180. legend: {
  181. data: this.filterOrderType('qtddqs', 'name')
  182. },
  183. xAxis: {
  184. type: 'category',
  185. boundaryGap: false,
  186. data: this.getDate(7, 'before')
  187. },
  188. yAxis: {
  189. type: 'value'
  190. },
  191. min: 0,
  192. max: value => {
  193. // 百位起最大值向上取整
  194. return Math.ceil(value.max / 100) * 100
  195. },
  196. series: this.filterOrderType('qtddqs', 'series')
  197. }
  198. let option2 = {
  199. tooltip: {
  200. trigger: 'axis'
  201. },
  202. xAxis: {
  203. type: 'category',
  204. boundaryGap: false,
  205. data: this.getDate(7, 'after')
  206. },
  207. yAxis: {
  208. type: 'value'
  209. },
  210. min: 0,
  211. max: value => {
  212. // 百位起最大值向上取整
  213. return Math.ceil(value.max / 100) * 100
  214. },
  215. series: [
  216. {
  217. name: '工单数',
  218. data: this.qtsm,
  219. type: 'line',
  220. smooth: true
  221. }
  222. ]
  223. }
  224. let option3 = {
  225. tooltip: {
  226. trigger: 'axis'
  227. },
  228. legend: {
  229. data: this.filterOrderType('wglxfb', 'name')
  230. },
  231. xAxis: {
  232. type: 'category',
  233. boundaryGap: false,
  234. data: this.getDate(30, 'before')
  235. },
  236. min: 0,
  237. max: value => {
  238. // 百位起最大值向上取整
  239. return Math.ceil(value.max / 100) * 100
  240. },
  241. yAxis: {
  242. type: 'value'
  243. },
  244. series: this.filterOrderType('wglxfb', 'series')
  245. }
  246. chart1.setOption(option1)
  247. chart2.setOption(option2)
  248. chart3.setOption(option3)
  249. }
  250. }
  251. }
  252. </script>
  253. <style scoped lang="scss">
  254. .dashboard_container {
  255. background: #f5f5f5;
  256. padding: 20px;
  257. min-height: calc(100vh - 86px);
  258. box-sizing: border-box;
  259. .refresh {
  260. text-align: right;
  261. margin-bottom: 10px;
  262. span {
  263. cursor: pointer;
  264. }
  265. i {
  266. font-weight: bold;
  267. margin-left: 4px;
  268. cursor: pointer;
  269. }
  270. }
  271. .container_top {
  272. display: flex;
  273. .tab {
  274. display: flex;
  275. align-items: center;
  276. flex: 1;
  277. padding: 20px;
  278. margin-right: 20px;
  279. background-color: #ffffff;
  280. border-radius: 10px;
  281. cursor: pointer;
  282. .text {
  283. margin-left: 30px;
  284. .title {
  285. color: #666666;
  286. font-size: 16px;
  287. margin-bottom: 8px;
  288. }
  289. .num {
  290. font-size: 26px;
  291. font-weight: bold;
  292. }
  293. }
  294. .img {
  295. width: 36px;
  296. height: 36px;
  297. }
  298. }
  299. .tab:last-child {
  300. margin-right: 0;
  301. }
  302. }
  303. .container_center {
  304. display: flex;
  305. margin: 10px 0;
  306. margin-top: 20px;
  307. .chart {
  308. flex: 1;
  309. height: 300px;
  310. background-color: #ffffff;
  311. margin-right: 20px;
  312. }
  313. .chart:last-child {
  314. margin-right: 0;
  315. }
  316. }
  317. .container_bottom {
  318. width: 100%;
  319. height: 350px;
  320. background-color: #ffffff;
  321. }
  322. .head {
  323. width: 100%;
  324. display: flex;
  325. justify-content: space-between;
  326. padding: 16px 20px;
  327. font-weight: bold;
  328. .more {
  329. color: #1d82ff;
  330. cursor: pointer;
  331. }
  332. }
  333. }
  334. </style>