SearchItem.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Web.Mvc;
  4. namespace WeApp.Views.Shared.SearchForm
  5. {
  6. public class SearchItem
  7. {
  8. public SearchItem(string field, string displayName, FieldType fieldType = FieldType.S, ExpType expType = ExpType.Contains, string searchModalId = "", string other = "", string formId = "", bool isShow = true, bool isOnlyView = false)
  9. {
  10. Field = field;
  11. DisplayName = displayName;
  12. FieldType = fieldType;
  13. ExpType = expType;
  14. SearchModalId = searchModalId;
  15. if (FieldType != FieldType.S)
  16. {
  17. ExpType = ExpType == ExpType.Contains ? ExpType.Equal : expType;
  18. }
  19. SelectItems = new List<SearchItemSelect>();
  20. DateItem = new DateItem();
  21. Other = other;
  22. FormId = formId;
  23. IsOnlyView = isOnlyView;
  24. IsShow = isShow;
  25. IsTree = false;
  26. }
  27. public string FormId { get; set; }
  28. public string Field { get; set; }
  29. public string DisplayName { get; set; }
  30. public string SearchModalId { get; set; }
  31. public string Other { get; set; }
  32. private string _target;
  33. public string Target => !string.IsNullOrEmpty(_target) ? _target : string.IsNullOrEmpty(FormId) ? "search-form" : FormId;
  34. public string Value { get; set; }
  35. public bool IsShow { get; set; }
  36. public bool IsTree { get; set; }
  37. public string ShowId { get; set; }
  38. /// <summary>
  39. /// 是否参与后台查询,只前台显示
  40. /// </summary>
  41. public bool IsOnlyView { get; set; }
  42. public FieldType FieldType { get; set; }
  43. public ExpType ExpType { get; set; }
  44. public List<SearchItemSelect> SelectItems { get; set; }
  45. public SearchItem SetSearchIcon(string modalId, string showId = null, string target = null)
  46. {
  47. SearchModalId = modalId;
  48. ShowId = showId;
  49. _target = target;
  50. return this;
  51. }
  52. public SearchItem SetValue(string value)
  53. {
  54. Value = value;
  55. return this;
  56. }
  57. public SearchItem SetDateItem(DateItem dateOption)
  58. {
  59. DateItem = dateOption;
  60. return this;
  61. }
  62. public SearchItem SetDateItem(int interval)
  63. {
  64. DateItem = new DateItem(interval);
  65. return this;
  66. }
  67. public DateItem DateItem { get; set; }
  68. public string SelectItemStr
  69. {
  70. get
  71. {
  72. if (!SelectItems.Any())
  73. {
  74. return "";
  75. }
  76. string str = "";
  77. foreach (var itemSelect in SelectItems)
  78. {
  79. str += $"\"{itemSelect.Filed}\":\"{itemSelect.ItemStrs}\"";
  80. }
  81. return str;
  82. }
  83. }
  84. public SearchItem SetSelectItem(List<SelectListItem> items, bool isAddBlank = false, bool isTree = false, string filed = null)
  85. {
  86. filed = filed ?? Field;
  87. SelectItems.Add(new SearchItemSelect(filed, items, isAddBlank));
  88. ExpType = ExpType == ExpType.Contains ? ExpType.Equal : ExpType;
  89. IsTree = isTree;
  90. return this;
  91. }
  92. public SearchItem SetSelectItem(string itemStr, bool isAddBlank = false, bool isTree = false, string filed = null)
  93. {
  94. filed = filed ?? Field;
  95. SelectItems.Add(new SearchItemSelect(filed, itemStr, isAddBlank));
  96. ExpType = ExpType == ExpType.Contains ? ExpType.Equal : ExpType;
  97. IsTree = isTree;
  98. return this;
  99. }
  100. }
  101. }