InquiryHandle.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace App\Admin\Actions\Tools;
  3. use App\Admin\Repositories\DistInquiry;
  4. use Dcat\Admin\Grid\Tools\AbstractTool;
  5. use Dcat\Admin\Widgets\Modal;
  6. use Illuminate\Http\Request;
  7. class InquiryHandle extends AbstractTool
  8. {
  9. protected $style = 'btn btn-success';
  10. /**
  11. * 按钮文本
  12. *
  13. * @return string|void
  14. */
  15. public function title()
  16. {
  17. return admin_trans_label('process');
  18. }
  19. /**
  20. * 确认弹窗,如果不需要则返回空即可
  21. *
  22. * @return array|string|void
  23. */
  24. public function confirm()
  25. {
  26. // 只显示标题
  27. // return '您确定要发送新的提醒消息吗?';
  28. // 显示标题和内容
  29. $msg = admin_trans_label('confirm_process_inquiry');
  30. return [$msg, ''];
  31. }
  32. /**
  33. * 处理请求
  34. * 如果你的类中包含了此方法,则点击按钮后会自动向后端发起ajax请求,并且会通过此方法处理请求逻辑
  35. *
  36. * @param Request $request
  37. */
  38. public function handle(Request $request)
  39. {
  40. $keys = $request->input('_key');
  41. if (is_array($keys) && count($keys) > 0) {
  42. $result = DistInquiry::distSetStatusProcessed($keys);
  43. return $this->response()->success(admin_trans_label('update_success'))->refresh();
  44. } else {
  45. return $this->response()->error('No data selected!')->refresh();
  46. }
  47. // 你的代码逻辑
  48. }
  49. public function actionScript(){
  50. $warning = admin_trans_label('no_selected_data');
  51. return <<<JS
  52. function (data, target, action) {
  53. try {
  54. var key = {$this->getSelectedKeysScript()}
  55. if (key.length === 0) {
  56. Dcat.warning('{$warning}');
  57. return false;
  58. }
  59. // 设置主键为复选框选中的行ID数组
  60. action.options.key = key;
  61. } catch (e) {
  62. Dcat.warning('{$warning}');
  63. return false;
  64. }
  65. }
  66. JS;
  67. }
  68. public function getSelectedKeysScript()
  69. {
  70. return "Dcat.grid.selected('{$this->parent->getName()}')";
  71. }
  72. }