zentaolist.customsearch.html.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace zin;
  3. $fnGenerateCustomSearchItem = function ($index, $searchConfig, $form) use ($lang, $config)
  4. {
  5. list($andor, $field, $operator, $value) = $form;
  6. $isFirst = $index === 0;
  7. $searchFields = $searchConfig['fields'];
  8. $searchParams = $searchConfig['params'];
  9. $fields = array_keys($searchFields);
  10. $field = empty($field) ? reset($fields) : $field;
  11. $operator = empty($operator) ? $searchParams[$field]['operator'] : $operator;
  12. $control = $searchParams[$field]['control'];
  13. $valueItems = $searchParams[$field]['values'];
  14. $isPicker = false;
  15. if($control === 'select')
  16. {
  17. $isPicker = true;
  18. $control = 'picker';
  19. }
  20. return formRow
  21. (
  22. setClass('flex gap-x-2'),
  23. setID('row' . $index),
  24. formGroup
  25. (
  26. setID('andor' . $index),
  27. setClass(array('search-andor', 'hidden' => $isFirst)),
  28. set::width('22'),
  29. set::name('andor[]'),
  30. set::control(array('required' => true)),
  31. set::items($lang->search->andor),
  32. set::value($andor)
  33. ),
  34. formGroup
  35. (
  36. setID('field' . $index),
  37. setClass('search-field'),
  38. set::width($isFirst ? '56' : '32'),
  39. set::label($isFirst ? $lang->doc->customSearch : null),
  40. set::name("field[]"),
  41. set::control(array('required' => true)),
  42. set::items($searchFields),
  43. set::value($field)
  44. ),
  45. formGroup
  46. (
  47. setID('operator' . $index),
  48. setClass('search-operator'),
  49. set::width('20'),
  50. set::name("operator[]"),
  51. set::control(array('required' => true)),
  52. set::items($lang->search->operators),
  53. set::value($operator)
  54. ),
  55. formGroup
  56. (
  57. setID('value' . $index . $control),
  58. setClass('search-value'),
  59. set::width('60'),
  60. set::name("value[]"),
  61. set::control(array('type' => $control)),
  62. set::value($value),
  63. $isPicker ? set::items($valueItems) : null
  64. ),
  65. btnGroup
  66. (
  67. btn(set(array('type' => 'ghost', 'icon' => 'plus', 'data-index' => $index, 'class' => 'search-add'))),
  68. btn(set(array('type' => 'ghost', 'icon' => 'minus', 'data-index' => $index, 'class' => array('search-remove', 'hidden' => $isFirst))))
  69. )
  70. );
  71. };
  72. $fnGenerateCustomSearch = function ($searchConfig) use ($lang, $config, $settings, $fnGenerateCustomSearchItem)
  73. {
  74. $this->loadModel('product');
  75. $this->loadModel('search');
  76. $items = array();
  77. $condition = zget($settings, 'condition', '');
  78. $isCustom = $condition === 'customSearch';
  79. foreach($settings['field'] as $index => $field)
  80. {
  81. $andor = $settings['andor'][$index];
  82. $operator = $settings['operator'][$index];
  83. $value = $settings['value'][$index];
  84. $items[] = $fnGenerateCustomSearchItem($index, $searchConfig, array($andor, $field, $operator, $value));
  85. }
  86. return div
  87. (
  88. setID('customSearchContent'),
  89. setClass('flex col gap-y-2', array('hidden' => !$isCustom)),
  90. $items,
  91. on::click('#customSearchContent .search-add')->do("updateCustomSearchItem(\$this, 'add')"),
  92. on::click('#customSearchContent .search-remove')->do("updateCustomSearchItem(\$this, 'remove')"),
  93. on::change('#customSearchContent .search-field')->do("updateCustomSearch(\$this)")
  94. );
  95. };