certificate.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. var _this;
  2. var nowTime = new Date().getTime();
  3. var periodChart, typeChart;
  4. new Vue({
  5. el: '#app',
  6. data: function() {
  7. return {
  8. statisLi: [{"name":"证书总数", "value":0, "colr":"#008dd4"},
  9. {"name":"正常期限", "value":0, "colr":"#00d42a"},
  10. {"name":"即将到期", "value":0, "colr":"#d1d400"},
  11. {"name":"已过期", "value":0, "colr":"#d40000"}],
  12. tableData: [],
  13. warmList:[],
  14. queryParams: {
  15. pageNum: 1,
  16. pageSize: 9999,
  17. orderByColumn: "certificateEffectiveDate",
  18. isAsc: "descending"
  19. }
  20. }
  21. },
  22. created() {
  23. _this = this;
  24. },
  25. mounted:function(){
  26. periodChart = echarts.init(document.getElementById('periodChart'));
  27. typeChart = echarts.init(document.getElementById('typeChart'));
  28. _this.getList();
  29. },
  30. methods: {
  31. getList(){
  32. getCertificateList(_this.queryParams).then((response) => {
  33. let _obj = response.rows;
  34. let dataList = [0, 0, 0, 0, 0], _warm = [];
  35. let carDistr = [{"name":"船舶证书","value":0},
  36. {"name":"船员证书","value":0}];
  37. _obj.map((item,index)=>{
  38. if(isNaN(item.certificateEffectiveDate) && !isNaN(Date.parse(item.certificateEffectiveDate))){
  39. let time = _this.getDaysBetween(nowTime, item.certificateEffectiveDate);
  40. item.nextTime = time;
  41. if (time > 365) {
  42. dataList[1] += 1;
  43. } else if (time > 31 && time < 366) {
  44. dataList[2] += 1;
  45. } else if (time > -1 && time < 32) {
  46. dataList[3] += 1;
  47. _warm.push(item);
  48. } else if (time < 0) {
  49. _warm.push(item);
  50. dataList[4] += 1;
  51. }
  52. }else{
  53. dataList[0] += 1;
  54. item.nextTime = "长期";
  55. }
  56. if (item.certificateCategory == 1) {
  57. carDistr[0].value += 1;
  58. } else{
  59. carDistr[1].value += 1;
  60. }
  61. });
  62. let _arr = _this.statisLi;
  63. _arr[0].value = _obj.length;
  64. _arr[1].value = dataList[0] + dataList[1] + dataList[2];
  65. _arr[2].value = dataList[3];
  66. _arr[3].value = dataList[4];
  67. _this.statisLi = _arr;
  68. _this.tableData = _obj;
  69. _this.warmList = _warm;
  70. periodChart.setOption(_this.periodOption(dataList));
  71. typeChart.setOption(_this.typeOption(carDistr));
  72. })
  73. },
  74. periodOption(_data){
  75. let option = {
  76. tooltip: {
  77. trigger: 'axis',
  78. axisPointer: {
  79. type: 'shadow'
  80. }
  81. },
  82. grid: {
  83. top: '8%',
  84. left: '0%',
  85. right: '0%',
  86. bottom: '3%',
  87. containLabel: true
  88. },
  89. xAxis: {
  90. type: 'category',
  91. data: ['长期','>365天', '32-365天', '<32天', '已过期'],
  92. axisLine: {
  93. lineStyle: {
  94. color: '#ddd'
  95. }
  96. },
  97. },
  98. yAxis: {
  99. type: 'value',
  100. axisLine: {
  101. show: false,
  102. },
  103. splitLine: {
  104. show: true,
  105. lineStyle: {
  106. color: '#5f5f5f'
  107. }
  108. },
  109. axisLabel: {
  110. formatter: function() {
  111. return "";
  112. }
  113. },
  114. },
  115. series: [{
  116. data: _data,
  117. name: '实时数据',
  118. type: 'bar',
  119. barWidth: '45%',
  120. itemStyle: {
  121. label: {
  122. color: '#ddd'
  123. },
  124. color: function(params) {
  125. var colorList = [
  126. ['#00d42a', '#00d42a'],
  127. ['#00d42a', '#00d42a'],
  128. ['#d1d400', '#d1d400'],
  129. ['#d1d400', '#d1d400'],
  130. ['#d40000', '#d40000']
  131. ];
  132. var index = params.dataIndex;
  133. if (params.dataIndex >= colorList.length) {
  134. index = params.dataIndex - colorList.length;
  135. }
  136. return new echarts.graphic.LinearGradient(0, 0, 0, 1,
  137. [{
  138. offset: 0,
  139. color: colorList[index][0]
  140. },
  141. {
  142. offset: 1,
  143. color: colorList[index][1]
  144. }
  145. ]);
  146. }
  147. },
  148. label: {
  149. show: true,
  150. position: 'top',
  151. color: '#ddd',
  152. formatter: function(params) {
  153. var list =["个","个", "个", "个", "个"];
  154. var index = params.dataIndex;
  155. if (params.dataIndex >= list.length) {
  156. index = params.dataIndex - list.length;
  157. }
  158. return _data[index] + list[index]
  159. }
  160. }
  161. }]
  162. };
  163. return option;
  164. },
  165. typeOption(_data){
  166. let option = {
  167. tooltip: {
  168. trigger: "item",
  169. formatter: "{a} <br/>{b} : {c} 个({d}%)"
  170. },
  171. legend: {
  172. top: "bottom",
  173. textStyle: {
  174. color: "#ddd"
  175. }
  176. },
  177. series: [{
  178. name: "证书分布",
  179. type: "pie",
  180. radius: '50%',
  181. center: ["50%", "40%"],
  182. itemStyle: {
  183. label: {
  184. formatter: '{d}%'
  185. }
  186. },
  187. data: _data,
  188. animationEasing: "cubicInOut",
  189. animationDuration: 1000
  190. }],
  191. }
  192. return option;
  193. },
  194. getDaysBetween(date1, date2) {
  195. var days = "";
  196. var endDate = new Date(date2.replace(/-/g,'/')).getTime();
  197. days = parseInt((endDate - date1) / (1*24 * 60 * 60 * 1000));
  198. return days;
  199. }
  200. }
  201. })