链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
3.3 KiB

5 years ago
  1. <?php
  2. namespace App\Admin\Actions\Metrics;
  3. use Dcat\Admin\Admin;
  4. use Dcat\Admin\Widgets\Metrics\Round;
  5. class Distance extends Round
  6. {
  7. protected $distance;
  8. protected $number;
  9. public function __construct($distance, $number)
  10. {
  11. $this->distance = $distance;
  12. $this->number = $number;
  13. parent::__construct($title=null, $icon=null);
  14. }
  15. /**
  16. * 初始化卡片内容
  17. */
  18. protected function init()
  19. {
  20. parent::init();
  21. $this->height = 160;
  22. $this->style('padding-top:0');
  23. $this->chartLabels(['1km以内', '1-3km', '3km以上']);
  24. }
  25. /**
  26. * 渲染模板
  27. *
  28. * @return string
  29. */
  30. public function render()
  31. {
  32. $this->fill();
  33. Admin::script($this->script());
  34. return parent::render();
  35. }
  36. public function script()
  37. {
  38. return <<<JS
  39. $('#shipping').parent().parent().parent().parent().prev().addClass('pt-0');
  40. JS;
  41. }
  42. /**
  43. * 写入数据.
  44. *
  45. * @return void
  46. */
  47. public function fill()
  48. {
  49. $this->withContent($this->distance[0], $this->distance[1],$this->distance[2]);
  50. // 图表数据
  51. $this->withChart([
  52. $this->distance[0]>0?sprintf("%.2f",($this->distance[0]/$this->number)*100):0,
  53. $this->distance[0]>0?sprintf("%.2f",($this->distance[1]/$this->number)*100):0,
  54. $this->distance[0]>0?sprintf("%.2f",($this->distance[2]/$this->number)*100):0,
  55. ]);
  56. // 总数
  57. $this->chartTotal('总数', $this->number);
  58. }
  59. /**
  60. * 设置图表数据.
  61. *
  62. * @param array $data
  63. *
  64. * @return $this
  65. */
  66. public function withChart(array $data)
  67. {
  68. return $this->chart([
  69. 'series' => $data,
  70. ]);
  71. }
  72. /**
  73. * 卡片内容.
  74. *
  75. * @param int $finished
  76. * @param int $pending
  77. * @param int $rejected
  78. *
  79. * @return $this
  80. */
  81. public function withContent($d1, $d2, $d3)
  82. {
  83. return $this->content(
  84. <<<HTML
  85. <div class="col-12 d-flex flex-column flex-wrap text-center" id="shipping" style="max-width: 220px;">
  86. <div class="chart-info d-flex justify-content-between mb-1 mt-2">
  87. <div class="series-info d-flex align-items-center">
  88. <i class="fa fa-circle-o text-bold-700 text-primary"></i>
  89. <span class="text-bold-600 ml-50">1km以内</span>
  90. </div>
  91. <div class="product-result">
  92. <span>{$d1}</span>
  93. </div>
  94. </div>
  95. <div class="chart-info d-flex justify-content-between mb-1">
  96. <div class="series-info d-flex align-items-center">
  97. <i class="fa fa-circle-o text-bold-700 text-warning"></i>
  98. <span class="text-bold-600 ml-50">1-3km</span>
  99. </div>
  100. <div class="product-result">
  101. <span>{$d2}</span>
  102. </div>
  103. </div>
  104. <div class="chart-info d-flex justify-content-between mb-1">
  105. <div class="series-info d-flex align-items-center">
  106. <i class="fa fa-circle-o text-bold-700 text-danger"></i>
  107. <span class="text-bold-600 ml-50">3km以上</span>
  108. </div>
  109. <div class="product-result">
  110. <span>{$d3}</span>
  111. </div>
  112. </div>
  113. </div>
  114. HTML
  115. );
  116. }
  117. }