index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. <template>
  2. <view class="content">
  3. <scrollView ref="scrollViewComponent"></scrollView>
  4. <view class="chart-con">
  5. <view class="cartsList-all">
  6. <view class="cartsList-name">
  7. 消耗数据趋势
  8. </view>
  9. <view class="cartsList-seleven">
  10. <uni-data-select v-model="valueList" :localdata="rangelineChart" @change="changelineChart"
  11. :clear="false"></uni-data-select>
  12. </view>
  13. </view>
  14. <view class="select-button">
  15. <view :style="{
  16. border: flagE === index + 1 ? '1px solid #90ffe4' : '1px solid #808080',
  17. color: flagE === index + 1 ? '#90ffe4' : '#808080',
  18. height: '40rpx',
  19. width: '100rpx',
  20. display: 'inline-block',
  21. cursor: 'pointer',
  22. textAlign: 'center',
  23. fontSize: '24rpx',
  24. fontFamily: '微软雅黑',
  25. lineHeight: '40rpx',
  26. }" v-for="(item, index) in navList" :key="item.id" @click="handleClickBtnE(index)">
  27. {{ item.name }}
  28. </view>
  29. </view>
  30. <view class="chart-wrap">
  31. <view class="line-chart-con">
  32. <l-echart class="line-chart" ref="lineChart"></l-echart>
  33. </view>
  34. </view>
  35. </view>
  36. <PieCharts ref="PieChartsComponent"></PieCharts>
  37. <view class="chart-con">
  38. <view class="cartsList-all">
  39. <view class="cartsList-name">
  40. 分类消耗占比
  41. </view>
  42. <view class="cartsList-seleven">
  43. <uni-data-select v-model="valueTimeType" :localdata="rangeringChart" @change="changeringChart"
  44. :clear="false"></uni-data-select>
  45. </view>
  46. </view>
  47. <view class=".chart-wrap-bing">
  48. <view class="ring-chart">
  49. <l-echart ref="ringChart"></l-echart>
  50. </view>
  51. </view>
  52. </view>
  53. <tiewk ref="tiewkComponent"></tiewk>
  54. <enterprise ref="enterpriseComponent"></enterprise>
  55. </view>
  56. </template>
  57. <script>
  58. import * as echarts from '@/uni_modules/lime-echart/static/echarts.min.js';
  59. import scrollView from './scrollView/scrollView.vue';
  60. import PieCharts from './PieCharts/PieCharts.vue';
  61. import enterprise from './enterprise/enterprise.vue';
  62. import tiewk from './tiewk/tiewk.vue';
  63. export default {
  64. components: {
  65. scrollView,
  66. PieCharts,
  67. tiewk,
  68. enterprise
  69. },
  70. data() {
  71. return {
  72. navList: [
  73. // {
  74. // name: "按科室"
  75. // },
  76. {
  77. name: "按种类"
  78. }, {
  79. name: "集采"
  80. }
  81. ],
  82. statType: "mcsType",
  83. LineData: [], //折线图数据
  84. EllData: [], //总汇折线图
  85. AllData: [], //存放全部数据
  86. yearl: [], //切换年月的数组
  87. pieData: [], //饼图
  88. AdList: null, //main实例
  89. type: 1, //交易分析模块里的类型
  90. valueList: 'Y',
  91. valueTimeType: "Y",
  92. flagE: 1,
  93. rangelineChart: [{
  94. value: 'Y',
  95. text: "年"
  96. },
  97. {
  98. value: 'M',
  99. text: "月"
  100. },
  101. ],
  102. rangeringChart: [{
  103. value: 'Y',
  104. text: "年",
  105. }, {
  106. value: 'M',
  107. text: "月",
  108. }, {
  109. value: 'W',
  110. text: "周",
  111. }, {
  112. value: 'D',
  113. text: "日",
  114. }]
  115. }
  116. },
  117. created() {
  118. this.listData();
  119. this.Listson()
  120. },
  121. mounted() {
  122. //加载饼环数据
  123. this.loadRingData();
  124. //加载折线图数据
  125. this.loadLineData();
  126. },
  127. methods: {
  128. onPullDownRefresh() {
  129. this.listData();
  130. this.Listson();
  131. this.$refs.enterpriseComponent.getData();
  132. this.$refs.tiewkComponent.listData();
  133. this.$refs.scrollViewComponent.listData();
  134. this.$refs.PieChartsComponent.listData();
  135. setTimeout(function() {
  136. uni.stopPullDownRefresh(); //停止下拉刷新动画
  137. }, 1000);
  138. },
  139. Listson() {
  140. this.$http('homePage.amtCosm', {
  141. timeType: this.valueTimeType
  142. }, '加载中').then((res) => {
  143. this.pieData = res.data;
  144. this.pieData = res.data.map((item) => {
  145. return {
  146. value: item.mcsAmt,
  147. name: item.mcsType,
  148. };
  149. });
  150. // 获取饼图的图例数据
  151. this.pieName = res.data.map((item) => item.mcsType);
  152. this.loadRingData();
  153. });
  154. },
  155. listData() {
  156. this.AllData = [];
  157. // 获取每个月的天数;
  158. const getDaysInMonth = (year, month) => {
  159. return new Date(year, month, 0).getDate();
  160. };
  161. this.$http('homePage.statCosm', {
  162. timeType: this.valueList,
  163. statType: this.statType
  164. }, '加载中').then((res) => {
  165. const year = new Date().getFullYear(); // 获取当前年份
  166. if (this.valueList === "M") {
  167. const daysInMonth = getDaysInMonth(year, new Date().getMonth() + 1); // 获取当前月份的天数
  168. this.yearl = Array.from({
  169. length: daysInMonth
  170. }, (_, i) => i + 1).map(
  171. (day) => `${day}`
  172. );
  173. } else {
  174. this.yearl = Array.from({
  175. length: 12
  176. }, (_, i) => i + 1).map(
  177. (month) => `${month}月`
  178. );
  179. }
  180. this.LineData = res.data.deptCosmList;
  181. this.EllData = res.data.totalCosm;
  182. const ellSeries = {
  183. name: "全部",
  184. data: this.EllData,
  185. smooth: true,
  186. type: "line",
  187. };
  188. this.AllData.push(ellSeries);
  189. const lineSeries = this.LineData.map((item) => ({
  190. name: item.type,
  191. data: item.cnt,
  192. smooth: true,
  193. type: "line",
  194. }));
  195. this.AllData = this.AllData.concat(lineSeries);
  196. this.loadLineData();
  197. })
  198. },
  199. changelineChart(e) {
  200. this.valueList = e
  201. this.updateListData();
  202. },
  203. // 消耗数据统计
  204. handleClickBtnE(index) {
  205. this.flagE = index + 1;
  206. if (index === 0) {
  207. // this.handleQuery("dept");
  208. // this.updateListData();
  209. this.handleQuery("mcsType");
  210. this.updateListData();
  211. } else if (index === 1) {
  212. this.handleQuery("isFas");
  213. this.updateListData();
  214. } else if (index === 2) {
  215. }
  216. },
  217. handleQuery(param) {
  218. this.statType = param;
  219. },
  220. updateListData() {
  221. this.listData({
  222. mcsType: this.valueList,
  223. timeType: this.value
  224. });
  225. },
  226. changeringChart(e) {
  227. this.valueTimeType = e
  228. this.Listson({
  229. timeType: this.valueTimeType
  230. })
  231. },
  232. loadRingData() {
  233. //这里请求服务器得到数据
  234. let data = this.pieData
  235. //这里option配置参考文档:https://echarts.apache.org/zh/option.html
  236. this.$refs.ringChart.init(echarts, chart => {
  237. chart.setOption({
  238. legend: {
  239. data: this.pieData.map((item) => item.name),
  240. left: "3%",
  241. top: "30%",
  242. orient: "vertical",
  243. },
  244. tooltip: {
  245. trigger: "item",
  246. position: ['30%', '30%'],
  247. axisPointer: {
  248. type: "shadow",
  249. },
  250. backgroundColor: "#fff", // 悬浮框背景色
  251. // borderColor: "#000", // 悬浮框边框颜色
  252. borderWidth: 1, // 悬浮框边框宽度
  253. textStyle: {
  254. // 悬浮框文字样式
  255. color: "#000",
  256. fontSize: '10rpx',
  257. },
  258. formatter: "{b} : {c}万元: {d}%", //鼠标移入提示框显示内容
  259. },
  260. series: [{
  261. type: 'pie',
  262. // selectedMode: 'single',
  263. // selectedOffset: 0,
  264. // hoverAnimation: false,
  265. radius: [40, 65],
  266. left: 'center',
  267. width: '98%',
  268. //隐藏默认白边
  269. itemStyle: {
  270. borderColor: '#fff',
  271. borderWidth: 0
  272. },
  273. //格式化label显示
  274. label: {
  275. alignTo: 'edge',
  276. show: true,
  277. formatter: "{b} : {c}万元: {d}%",
  278. minMargin: 5,
  279. edgeDistance: 20,
  280. lineHeight: 24,
  281. rich: {
  282. time: {
  283. fontSize: 10,
  284. color: '#999'
  285. }
  286. }
  287. },
  288. //指向label的线设置
  289. labelLine: {
  290. length: 15,
  291. length2: 0,
  292. maxSurfaceAngle: 80
  293. },
  294. //布局样式
  295. labelLayout: function(params) {
  296. const isLeft = params.labelRect.x < chart.getWidth() / 2;
  297. const points = params.labelLinePoints;
  298. points[2][0] = isLeft ?
  299. params.labelRect.x :
  300. params.labelRect.x + params.labelRect.width;
  301. return {
  302. labelLinePoints: points
  303. };
  304. },
  305. //数据
  306. data: this.pieData
  307. }]
  308. });
  309. //默认突出高亮显示,可以放开下面注释
  310. // chart.dispatchAction({
  311. // type: 'highlight',
  312. // seriesIndex: 0,
  313. // dataIndex: 0
  314. // });
  315. //监听图标项点击事件
  316. chart.on("click", function(e) {
  317. for (var i = 0; i < data.length; i++) {
  318. if (i != e.dataIndex) {
  319. chart.dispatchAction({
  320. type: 'downplay', //取消高亮显示;
  321. seriesIndex: 0,
  322. dataIndex: i
  323. });
  324. } else {
  325. chart.dispatchAction({
  326. type: 'highlight', //突出高亮显示;
  327. seriesIndex: 0,
  328. dataIndex: i
  329. });
  330. }
  331. }
  332. });
  333. });
  334. },
  335. //加载折线图数据
  336. loadLineData() {
  337. //这里请求服务器拿到数据
  338. let res = {
  339. //x轴数据
  340. }
  341. //这里option配置参考文档:https://echarts.apache.org/zh/option.html
  342. let option = {
  343. legend: {
  344. data: this.AllData.map((item) => item.name),
  345. },
  346. dataZoom: [{
  347. bottom: 10, // 下滑块距离x轴底部的距离
  348. height: 20, // 下滑块手柄的高度调节
  349. type: 'inside', // 类型,滑动块插件
  350. show: true, // 是否显示下滑块
  351. xAxisIndex: [0], // 选择的x轴
  352. start: this.valueList === "M" ? 10 : 120, // 初始数据显示多少
  353. end: this.valueList === "M" ? 35 : 350 // 初始数据最多显示多少
  354. }],
  355. xAxis: {
  356. type: 'category',
  357. // x轴数据文字颜色
  358. axisLabel: {
  359. color: '#a7a7a7',
  360. },
  361. // x轴那天坐标轴线的颜色
  362. axisLine: {
  363. lineStyle: {
  364. color: '#f1f1f1',
  365. }
  366. },
  367. //x轴上面刻度线隐藏
  368. axisTick: {
  369. show: false,
  370. },
  371. //这里是x轴数据
  372. data: this.yearl,
  373. },
  374. //设置网格
  375. grid: {
  376. top: 40,
  377. bottom: 30,
  378. },
  379. //y轴设置
  380. yAxis: {
  381. type: 'value',
  382. //y轴标签文字颜色
  383. axisLabel: {
  384. color: '#a7a7a7'
  385. },
  386. // y轴分割线设置为虚线
  387. splitLine: {
  388. show: true,
  389. lineStyle: {
  390. type: 'dashed'
  391. }
  392. }
  393. },
  394. //设置提示为点击时
  395. tooltip: {
  396. trigger: 'axis',
  397. triggerOn: 'click',
  398. formatter: '{b}: \n {a0}: {c0} \n {a1}: {c1} \n {a2}: {c2} \n {a3}: {c3}'
  399. },
  400. //设置曲线的颜色
  401. color: ['#4e9d77', '#fac858', '#ee6666'],
  402. series: this.AllData
  403. };
  404. this.$refs.lineChart.init(echarts, chart => {
  405. chart.setOption(option);
  406. });
  407. }
  408. },
  409. }
  410. </script>
  411. <style lang="scss" scoped>
  412. .content {
  413. width: 100%;
  414. min-height: 100vh;
  415. padding: 20rpx 0rpx 100rpx;
  416. }
  417. .chart-scroll-wrap {
  418. width: 100%;
  419. }
  420. .chart-con {
  421. width: 100%;
  422. box-sizing: border-box;
  423. padding: 0rpx 28rpx;
  424. .chart-wrap {
  425. width: 100%;
  426. box-sizing: border-box;
  427. padding: 32rpx 0rpx;
  428. border-bottom-left-radius: 20rpx;
  429. border-bottom-right-radius: 20rpx;
  430. background-color: #fff;
  431. border-width: 0 4rpx 4rpx 4rpx;
  432. /* 上、右、下、左 边框宽度 */
  433. border-style: solid;
  434. border-color: #90ffe4;
  435. }
  436. .chart-wrap-bing {
  437. width: 100%;
  438. box-sizing: border-box;
  439. border-radius: 20rpx;
  440. background-color: #fff;
  441. .ring-chart {
  442. height: 400rpx;
  443. width: 100%;
  444. box-sizing: border-box;
  445. padding: 0rpx 28rpx;
  446. // margin-top: 32rpx;
  447. border-width: 0 4rpx 4rpx 4rpx;
  448. /* 上、右、下、左 边框宽度 */
  449. border-style: solid;
  450. border-color: #90ffe4;
  451. border-bottom-left-radius: 20rpx;
  452. border-bottom-right-radius: 20rpx;
  453. }
  454. }
  455. }
  456. .line-chart-con {
  457. box-sizing: border-box;
  458. padding: 0rpx 28rpx;
  459. .line-chart {
  460. width: 100%;
  461. margin-top: 30rpx;
  462. height: 450rpx;
  463. }
  464. }
  465. .cartsList-all {
  466. width: 100%;
  467. height: 100rpx;
  468. display: flex;
  469. justify-content: space-between;
  470. background-color: #ffffff;
  471. border-width: 4rpx 4rpx 4rpx 4rpx;
  472. /* 上、右、下、左 边框宽度 */
  473. border-style: solid;
  474. border-color: #90ffe4;
  475. padding: 20rpx;
  476. box-sizing: border-box;
  477. border-top-left-radius: 20rpx;
  478. border-top-right-radius: 20rpx;
  479. .cartsList-name {
  480. font-size: 35rpx;
  481. font-weight: bold;
  482. position: relative;
  483. }
  484. }
  485. .select-button {
  486. width: 375rpx;
  487. position: absolute;
  488. right: 100rpx;
  489. top: 510rpx;
  490. z-index: 999;
  491. }
  492. </style>