链街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.

147 lines
3.8 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
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', '3-5km','5km以上']);
  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],$this->distance[3]);
  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. $this->distance[0]>0?sprintf("%.2f",($this->distance[3]/$this->number)*100):0,
  56. ]);
  57. // 总数
  58. $this->chartTotal('订单数', $this->number);
  59. }
  60. /**
  61. * 设置图表数据.
  62. *
  63. * @param array $data
  64. *
  65. * @return $this
  66. */
  67. public function withChart(array $data)
  68. {
  69. return $this->chart([
  70. 'series' => $data,
  71. ]);
  72. }
  73. /**
  74. * 卡片内容.
  75. *
  76. * @param int $finished
  77. * @param int $pending
  78. * @param int $rejected
  79. *
  80. * @return $this
  81. */
  82. public function withContent($d1, $d2, $d3,$d4)
  83. {
  84. return $this->content(
  85. <<<HTML
  86. <div class="col-12 d-flex flex-column flex-wrap text-center" id="shipping" style="max-width: 220px;">
  87. <div class="chart-info d-flex justify-content-between mb-1 mt-2">
  88. <div class="series-info d-flex align-items-center">
  89. <i class="fa fa-circle-o text-bold-700 text-primary"></i>
  90. <span class="text-bold-600 ml-50">1km以内</span>
  91. </div>
  92. <div class="product-result">
  93. <span>{$d1}</span>
  94. </div>
  95. </div>
  96. <div class="chart-info d-flex justify-content-between mb-1">
  97. <div class="series-info d-flex align-items-center">
  98. <i class="fa fa-circle-o text-bold-700 text-warning"></i>
  99. <span class="text-bold-600 ml-50">1-3km</span>
  100. </div>
  101. <div class="product-result">
  102. <span>{$d2}</span>
  103. </div>
  104. </div>
  105. <div class="chart-info d-flex justify-content-between mb-1">
  106. <div class="series-info d-flex align-items-center">
  107. <i class="fa fa-circle-o text-bold-700 text-danger"></i>
  108. <span class="text-bold-600 ml-50">3-5km</span>
  109. </div>
  110. <div class="product-result">
  111. <span>{$d3}</span>
  112. </div>
  113. </div>
  114. <div class="chart-info d-flex justify-content-between mb-1">
  115. <div class="series-info d-flex align-items-center">
  116. <i class="fa fa-circle-o text-bold-700 text-danger"></i>
  117. <span class="text-bold-600 ml-50">5km以上</span>
  118. </div>
  119. <div class="product-result">
  120. <span>{$d4}</span>
  121. </div>
  122. </div>
  123. </div>
  124. HTML
  125. );
  126. }
  127. }