FormHelperTrait.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace App\Module\Promotion\AdminControllers\Helper;
  3. use App\Module\Promotion\Enums\PROFIT_SOURCE_TYPE;
  4. use App\Module\Promotion\Enums\REFERRAL_CHANGE_REASON;
  5. use App\Module\Promotion\Enums\REFERRAL_CODE_STATUS;
  6. use App\Module\Promotion\Enums\REFERRAL_CODE_USAGE_STATUS;
  7. /**
  8. * 表单页辅助特性
  9. *
  10. * 提供表单页的辅助方法,如表单项的显示、格式化等。
  11. */
  12. trait FormHelperTrait
  13. {
  14. /**
  15. * 推荐码状态选择
  16. *
  17. * @param string $field 字段名
  18. * @param string $label 标签
  19. * @return \Dcat\Admin\Form\Field\Select
  20. */
  21. public function selectReferralCodeStatus(string $field = 'status', string $label = '状态')
  22. {
  23. return $this->form->select($field, $label)->options(REFERRAL_CODE_STATUS::getOptions());
  24. }
  25. /**
  26. * 推荐码使用状态选择
  27. *
  28. * @param string $field 字段名
  29. * @param string $label 标签
  30. * @return \Dcat\Admin\Form\Field\Select
  31. */
  32. public function selectReferralCodeUsageStatus(string $field = 'status', string $label = '状态')
  33. {
  34. return $this->form->select($field, $label)->options(REFERRAL_CODE_USAGE_STATUS::getOptions());
  35. }
  36. /**
  37. * 推荐关系修改原因选择
  38. *
  39. * @param string $field 字段名
  40. * @param string $label 标签
  41. * @return \Dcat\Admin\Form\Field\Select
  42. */
  43. public function selectReferralChangeReason(string $field = 'reason', string $label = '修改原因')
  44. {
  45. return $this->form->select($field, $label)->options(REFERRAL_CHANGE_REASON::getOptions());
  46. }
  47. /**
  48. * 收益来源类型选择
  49. *
  50. * @param string $field 字段名
  51. * @param string $label 标签
  52. * @return \Dcat\Admin\Form\Field\Select
  53. */
  54. public function selectProfitSourceType(string $field = 'source_type', string $label = '来源类型')
  55. {
  56. return $this->form->select($field, $label)->options(PROFIT_SOURCE_TYPE::getOptions());
  57. }
  58. /**
  59. * JSON编辑器
  60. *
  61. * @param string $field 字段名
  62. * @param string $label 标签
  63. * @return \Dcat\Admin\Form\Field\Editor
  64. */
  65. public function jsonEditor(string $field, string $label)
  66. {
  67. return $this->form->editor($field, $label)->language('json');
  68. }
  69. }