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

83 lines
1.7 KiB

  1. <?php
  2. namespace App\Admin\Widgets\Charts;
  3. use Dcat\Admin\Widgets\Metrics\Card;
  4. use Illuminate\Http\Request;
  5. class OrderGoodsActivityTotalChart extends Card
  6. {
  7. /**
  8. * 活动商品总数
  9. */
  10. protected $data = [];
  11. protected $id;
  12. protected $option;
  13. public function __construct($data = [])
  14. {
  15. $this->option = $this->id = 7;
  16. $this->data = $data;
  17. parent::__construct();
  18. }
  19. protected function init()
  20. {
  21. parent::init();
  22. // 设置标题
  23. $this->title('销售总数量');
  24. // 设置下拉菜单
  25. // $this->dropdown([]);
  26. }
  27. /**
  28. * 处理请求
  29. * 如果你的图表类中包含此方法,则可以通过此方法处理前端通过ajax提交的获取图表数据的请求
  30. *
  31. * @param Request $request
  32. * @return mixed|void
  33. */
  34. public function handle(Request $request)
  35. {
  36. // dd($request);
  37. // 数据查询逻辑
  38. $data = ['total' => $this->data['total'] ?? 0 ];
  39. $this->withData($data);
  40. }
  41. /**
  42. * 这里返回需要异步传递到 handler 方法的参数
  43. *
  44. * @return array
  45. */
  46. public function parameters(): array
  47. {
  48. return [
  49. 'id' => $this->id,
  50. 'option' => $this->option,
  51. ];
  52. }
  53. public function withData($data)
  54. {
  55. $this->data = $data;
  56. }
  57. /**
  58. * 渲染卡片内容.
  59. *
  60. * @return string
  61. */
  62. public function renderContent()
  63. {
  64. $total = $this->data['total'] ?? 0 ;
  65. return <<<HTML
  66. <div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px">
  67. <h2 class="ml-1 font-large-1">{$total}</h2>
  68. </div>
  69. HTML;
  70. }
  71. }