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.
119 lines
2.9 KiB
119 lines
2.9 KiB
<?php
|
|
|
|
namespace App\Admin\Actions\Metrics;
|
|
|
|
use Dcat\Admin\Admin;
|
|
use Dcat\Admin\Widgets\Metrics\Donut;
|
|
|
|
class Shipping extends Donut
|
|
{
|
|
protected $labels = ['站内配送', '用户自提', '配送占比', '自提占比'];
|
|
protected $shipping;
|
|
|
|
public function __construct($shipping)
|
|
{
|
|
|
|
$this->shipping = $shipping;
|
|
parent::__construct($title = null, $icon = null);
|
|
}
|
|
|
|
public function init()
|
|
{
|
|
parent::init(); // TODO: Change the autogenerated stub
|
|
$color = Admin::color();
|
|
$colors = [$color->primary(), $color->alpha('blue2', 0.5)];
|
|
//$this->title('<small>配送数据</small>');
|
|
$this->height = 152;
|
|
$this->chartLabels($this->labels);
|
|
// 设置图表颜色
|
|
$this->chartColors($colors);
|
|
}
|
|
|
|
/**
|
|
* 渲染模板
|
|
*
|
|
* @return string
|
|
*/
|
|
public function render()
|
|
{
|
|
$this->fill();
|
|
return parent::render(); // TODO: Change the autogenerated stub
|
|
}
|
|
|
|
/**
|
|
* 写入数据.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function fill()
|
|
{
|
|
$total = array_sum($this->shipping);
|
|
$s3 = $this->shipping[0]>0?sprintf("%.1f", ($this->shipping[0] / $total) * 100) . '%':'0%';
|
|
$s4 = $this->shipping[0]>0?sprintf("%.1f", ($this->shipping[1] / $total) * 100) . '%':'0%';
|
|
// 图表数据
|
|
|
|
$this->withChart($this->shipping);
|
|
|
|
$this->withContent($this->shipping[0], $this->shipping[1], $s3, $s4);
|
|
}
|
|
|
|
/**
|
|
* 设置图表数据.
|
|
*
|
|
* @param array $data
|
|
*
|
|
* @return $this
|
|
*/
|
|
public function withChart(array $data)
|
|
{
|
|
return $this->chart([
|
|
'series' => $data
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 设置卡片头部内容.
|
|
*
|
|
* @param mixed $desktop
|
|
* @param mixed $mobile
|
|
*
|
|
* @return $this
|
|
*/
|
|
protected function withContent($s1, $s2, $s3, $s4)
|
|
{
|
|
$blue = Admin::color()->alpha('blue2', 0.5);
|
|
|
|
$style = 'margin-bottom: 8px';
|
|
$labelWidth = 120;
|
|
|
|
return $this->content(
|
|
<<<HTML
|
|
<div class="d-flex pl-1 pr-1 " style="{$style}">
|
|
<div style="width: {$labelWidth}px">
|
|
<i class="fa fa-circle text-primary"></i> {$this->labels[0]}
|
|
</div>
|
|
<div>{$s1}</div>
|
|
</div>
|
|
<div class="d-flex pl-1 pr-1" style="{$style}">
|
|
<div style="width: {$labelWidth}px">
|
|
<i class="fa fa-circle" style="color: $blue"></i> {$this->labels[1]}
|
|
</div>
|
|
<div>{$s2}</div>
|
|
</div>
|
|
|
|
<div class="d-flex pl-1 pr-1 pt-1" style="{$style}">
|
|
<div style="width: {$labelWidth}px">
|
|
<i class="fa fa-circle text-primary"></i> {$this->labels[2]}
|
|
</div>
|
|
<div>{$s3}</div>
|
|
</div>
|
|
<div class="d-flex pl-1 pr-1" style="{$style}">
|
|
<div style="width: {$labelWidth}px">
|
|
<i class="fa fa-circle" style="color: $blue"></i> {$this->labels[3]}
|
|
</div>
|
|
<div>{$s4}</div>
|
|
</div>
|
|
HTML
|
|
);
|
|
}
|
|
}
|