BatchCopy.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Distributor\Actions;
  3. use Dcat\Admin\Grid\BatchAction;
  4. use Illuminate\Http\Request;
  5. use App\Distributor\Forms\ImportProduct;
  6. use Dcat\Admin\Widgets\Modal;
  7. //批量复制导入,最终在form importProduct
  8. class BatchCopy extends BatchAction
  9. {
  10. protected $title = '产品导入';
  11. /**
  12. * 重写弹出的表单
  13. * @return Modal|string
  14. */
  15. public function render()
  16. {
  17. // 实例化表单类
  18. $form = ImportProduct::make();
  19. return Modal::make()
  20. ->lg()
  21. ->title($this->title)
  22. ->body($form)
  23. // 因为此处使用了表单异步加载功能,所以一定要用 onLoad 方法
  24. // 如果是非异步方式加载表单,则需要改成 onShow 方法
  25. ->onShow($this->getModalScript())
  26. ->button($this->title);
  27. }
  28. /**
  29. * 填充选择的产品ID
  30. * @return string
  31. */
  32. protected function getModalScript()
  33. {
  34. // 弹窗显示后往隐藏的id表单中写入批量选中的行ID
  35. return <<<JS
  36. // 获取选中的ID数组
  37. var key = {$this->getSelectedKeysScript()}
  38. $('#product_ids').val(key);
  39. JS;
  40. }
  41. }