InquiryAssignment.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Admin\Actions\Grid;
  3. use Dcat\Admin\Actions\Response;
  4. use Dcat\Admin\Admin;
  5. use Dcat\Admin\Grid\BatchAction;
  6. use Illuminate\Http\Request;
  7. use App\Admin\Forms\InquiryAssignment as InquiryAssignmentForm;
  8. use Dcat\Admin\Widgets\Modal;
  9. class InquiryAssignment extends BatchAction
  10. {
  11. /**
  12. * 初始化操作
  13. */
  14. public function render()
  15. {
  16. $assignment = admin_trans_label('assignment');
  17. $button = '<button type="button" class="btn btn-success">'.$assignment.'</button>';
  18. // 实例化表单类
  19. return Modal::make()
  20. ->lg()
  21. ->title(admin_trans_label('inquiry_assignment'))
  22. ->body(InquiryAssignmentForm::make())
  23. //->on('click',$this->getModalScript2())
  24. ->onShow($this->getModalScript())
  25. // 因为此处使用了表单异步加载功能,所以一定要用 onLoad 方法
  26. ->button($button);
  27. }
  28. /**
  29. * 设置动作发起请求前的回调函数,返回false可以中断请求.
  30. *
  31. * @return string
  32. */
  33. public function getModalScript(){
  34. $warning = admin_trans_label('no_selected_data');
  35. return <<<JS
  36. try {
  37. var key = {$this->getSelectedKeysScript()}
  38. $('#inquiryIds').val(key);
  39. } catch (e) {
  40. Dcat.error('{$warning}');
  41. return false;
  42. }
  43. JS;
  44. }
  45. public function getSelectedKeysScript()
  46. {
  47. return "Dcat.grid.selected('{$this->parent->getName()}')";
  48. }
  49. }