index.vue 13 KB

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