chart-section.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. (function(){
  2. Vue.component('chart-section', {
  3. template: '<div class="panel-box4">\
  4. <h4 class="c-b5e1fc c-f16 c-t-center">{{sectionTitle}}(数据展示)</h4>\
  5. <div v-show="hasData" id="lineChart" style="height: calc(100% - 0.1rem);"></div>\
  6. <div v-show="!hasData" class="no-result-panel">\
  7. <div class="no-result-img">\
  8. <img src="../images/wushuju_icon.png">\
  9. </div>\
  10. <div class="no-result-text">暂无相关体征数据</div>\
  11. </div>\
  12. </div>',
  13. props: ['patient'],
  14. data: function() {
  15. return {
  16. sectionTitle: "血压",
  17. hasData: true,
  18. fontSize: 0.007 * window.screen.width,
  19. dateType: 1
  20. }
  21. },
  22. mounted: function(){
  23. var vm = this;
  24. getChartInfo(vm);
  25. },
  26. methods: {}
  27. });
  28. function getChartInfo(vm){
  29. EventBus.$on('get-chart-data', function(arg){
  30. vm.dateType = arg.dateType ? arg.dateType : vm.dateType;
  31. var type = arg.type,
  32. gi_type = arg.gi_type,
  33. dateType = vm.dateType,
  34. startDate = getStartDate(dateType),
  35. endDate = getEndDate(),
  36. time = getTimeName(dateType);
  37. var params = {
  38. patient: vm.patient,
  39. type: type, //1-血糖,2-血压,3-体重,4-腰围
  40. gi_type: gi_type, //就餐类型
  41. time: time,
  42. begin: startDate,
  43. end: endDate
  44. };
  45. patientAPI.getChartData(params).then(function(res){
  46. if(res.status == 200){
  47. //触发指标分析内容修改
  48. EventBus.$emit("get-zhibiao-analysis", {content: res.data.content});
  49. //触发指标统计值
  50. EventBus.$emit("get-zhibiao-count", {total: res.data.total});
  51. if(res.data.list.length == 0){
  52. vm.hasData = false;
  53. return false;
  54. }else{
  55. vm.hasData = true;
  56. }
  57. var xData = _.map(res.data.list, function(o){
  58. return o.date;
  59. });
  60. // 为echarts对象加载数据
  61. if (type == 1) {
  62. var xuetangDuring = ['','早餐前', '早餐后', '午餐前', '午餐后', '晚餐前', '晚餐后', '睡前'],
  63. labelName = xuetangDuring[gi_type] + "血糖";
  64. vm.sectionTitle = labelName;
  65. var seriesData = getSeriesData(res.data.list, labelName, vm.fontSize);
  66. var legent = {show: false};
  67. drawLineChart(xData, seriesData, legent, vm.fontSize);
  68. }
  69. if (type == 2) {
  70. var seriesData = getSeriesData2(res.data.list, vm.fontSize);
  71. var legent = {
  72. top: 'top',
  73. data:['舒张压', '收缩压'],
  74. textStyle: {
  75. color: "#fff",
  76. fontSize: vm.fontSize
  77. }
  78. };
  79. drawLineChart(xData, seriesData, legent, vm.fontSize);
  80. }
  81. }else{
  82. console.log(res.msg);
  83. }
  84. });
  85. })
  86. }
  87. function getSeriesData(data, labelName, fontSize){
  88. //餐前血糖值: [7.0, 4.0]
  89. //餐后血糖值: [4.0, 11.1]
  90. var list = _.map(data, function(o){
  91. if(o.type == 1){ //血糖
  92. if(["1", "3", "5", "7"].indexOf(o.value2) > -1){ //餐前数据
  93. return buildData(parseFloat(o.value1), 7.0, 4.0);
  94. }else{
  95. return buildData(parseFloat(o.value1), 11.1, 4.0)
  96. }
  97. }else{
  98. return "";
  99. }
  100. });
  101. var obj = {
  102. name: labelName+'血糖',
  103. type: 'line',
  104. smooth: true,
  105. symbol: "circle",
  106. symbolSize: 0.005 * window.screen.width,
  107. data: list,
  108. itemStyle:{
  109. normal: {
  110. borderWidth: 10,
  111. color: '#03d95d',
  112. lineStyle: { // 系列级个性化折线样式,横向渐变描边
  113. borderWidth: 2,
  114. color: '#CC66FF',
  115. width: window.screen.width > 3000 ? 4 : 2
  116. },
  117. label:{
  118. textStyle: {
  119. fontSize: fontSize
  120. }
  121. }
  122. }
  123. }
  124. };
  125. return [obj];
  126. }
  127. function getSeriesData2(data, fontSize){
  128. //获取收缩压和舒张压的值
  129. //舒张压
  130. var list1 = _.map(data, function(o){
  131. return buildData(parseFloat(o.value1), 90, 60);
  132. });
  133. //收缩压
  134. var list2 = _.map(data, function(o){
  135. return buildData(parseFloat(o.value2), 140, 90)
  136. });
  137. return [{
  138. name: "舒张压",
  139. type: 'line',
  140. smooth: true,
  141. symbol: "circle",
  142. symbolSize: 0.005 * window.screen.width,
  143. data: list1,
  144. itemStyle:{
  145. normal: {
  146. borderWidth: 10,
  147. color: '#CC66FF',
  148. lineStyle: { // 系列级个性化折线样式,横向渐变描边
  149. borderWidth: 2,
  150. width: window.screen.width > 3000 ? 4 : 2
  151. },
  152. label:{
  153. textStyle: {
  154. fontSize: fontSize
  155. }
  156. }
  157. },
  158. emphasis: {
  159. label: {
  160. show: true
  161. }
  162. }
  163. }
  164. },{
  165. name: "收缩压",
  166. type: 'line',
  167. smooth: true,
  168. symbol: "circle",
  169. symbolSize: 0.005 * window.screen.width,
  170. data: list2,
  171. itemStyle:{
  172. normal: {
  173. borderWidth: 10,
  174. color: '#5dd1d2',
  175. lineStyle: { // 系列级个性化折线样式,横向渐变描边
  176. borderWidth: 2,
  177. width: window.screen.width > 3000 ? 4 : 2
  178. },
  179. label:{
  180. textStyle: {
  181. fontSize: fontSize
  182. }
  183. }
  184. },
  185. emphasis: {
  186. label: {
  187. show: true
  188. }
  189. }
  190. }
  191. }]
  192. }
  193. function buildData(value, max, min) {
  194. if(value > 0 && value < min) {
  195. return {
  196. value: value,
  197. itemStyle: {
  198. normal: {
  199. color: '#fd9c0d'
  200. }
  201. }
  202. }
  203. } else if(value > 0 && value > max) {
  204. return {
  205. value: value,
  206. itemStyle: {
  207. normal: {
  208. color: '#ff3803'
  209. }
  210. }
  211. }
  212. }else{
  213. return {
  214. value: value,
  215. itemStyle:{
  216. normal: {
  217. color: "#0ad800"
  218. }
  219. }
  220. }
  221. }
  222. }
  223. function drawLineChart(xData, seriesData, legent, fontSize){
  224. $("#lineChart").show();
  225. var lastIndex = xData.length % 10;
  226. if(xData.length >10 ){
  227. var dataZoom_end = 100-(9/xData.length)*100;
  228. }else{
  229. var dataZoom_end = 0;
  230. }
  231. var lineCharts = echarts.init(document.getElementById('lineChart'));
  232. var options = {
  233. tooltip: {
  234. trigger: 'axis',
  235. textStyle: {
  236. fontSize: fontSize,
  237. color: '#0fa5f2'
  238. },
  239. backgroundColor: "#B5E1FC"
  240. },
  241. legend: legent,
  242. grid: {
  243. left: '5%',
  244. right: '5%',
  245. bottom: '15%',
  246. top: '12%',
  247. containLabel: true
  248. },
  249. xAxis: {
  250. type: 'category',
  251. boundaryGap: false,
  252. axisLabel: {
  253. interval:0,//横轴信息全部显示
  254. fontSize: fontSize,
  255. formatter: function (value, index) {
  256. return value.substr(5,5);
  257. }
  258. },
  259. nameTextStyle: {
  260. fontSize: fontSize
  261. },
  262. axisLine:{
  263. lineStyle:{
  264. color:'#b5e1fc',
  265. width:2
  266. }
  267. },
  268. data: xData,
  269. splitLine: {
  270. show: false
  271. },
  272. },
  273. yAxis: {
  274. type: 'value',
  275. axisPointer: {
  276. snap: true
  277. },
  278. scale: true,
  279. minInterval: 1,
  280. boundaryGap: ['10%', '30%'],
  281. axisLine: {
  282. "lineStyle": {
  283. "color": "#b5e1fc",
  284. "width": window.screen.width > 3000 ? 2 : 1
  285. }
  286. },
  287. axisLabel:{
  288. fontSize: fontSize
  289. },
  290. nameTextStyle: {
  291. fontSize: fontSize
  292. },
  293. },
  294. dataZoom: [{//给x轴设置滚动条
  295. // show: false,
  296. start: dataZoom_end,
  297. end: 100,
  298. type: 'slider',
  299. zoomLock: true,
  300. },{ //下面这个属性是内容区域配置
  301. start: dataZoom_end,
  302. end: 100,
  303. type: 'inside',
  304. zoomLock: true,
  305. }],
  306. series: seriesData
  307. };
  308. //删除旧的图标数据重新渲染
  309. $("#lineChart").removeAttr("_echarts_instance_");
  310. lineCharts.setOption(options);
  311. window.addEventListener("resize", function () {
  312. setTimeout(function () {
  313. lineCharts.resize();
  314. }, 500)
  315. });
  316. }
  317. function getStartDate(type){
  318. //type: 1-周, 2-月, 3-年
  319. var now = new Date(),
  320. endDate = new Date();
  321. switch(parseInt(type)){
  322. case 1:
  323. endDate.setDate(now.getDate()- 6);
  324. break;
  325. case 2:
  326. endDate.setMonth(now.getMonth() - 1);
  327. break;
  328. case 3:
  329. endDate.setFullYear(now.getFullYear() - 1);
  330. break;
  331. }
  332. return endDate.format("yyyy-MM-dd")+" 00:00:00";
  333. }
  334. function getEndDate(){
  335. var now = new Date();
  336. return now.format("yyyy-MM-dd")+ " 23:59:59";
  337. }
  338. function getTimeName(type){
  339. switch(parseInt(type)){
  340. case 1:
  341. return "一周";
  342. break;
  343. case 2:
  344. return "一月";
  345. break;
  346. case 3:
  347. return "一年";
  348. break;
  349. }
  350. }
  351. })();