SearchFormViewModal.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Web.Mvc;
  4. namespace ShwasherSys.Models.Layout
  5. {
  6. public class SearchFormViewModal
  7. {
  8. public SearchFormViewModal(List<SearchItem> searchItems,string formId="search-form", bool isSingle = false)
  9. {
  10. SearchItems = searchItems;
  11. IsSingle = isSingle;
  12. FormId = formId;
  13. }
  14. public SearchFormViewModal(List<SearchItem> searchItems, bool isSingle )
  15. {
  16. SearchItems = searchItems;
  17. IsSingle = isSingle;
  18. FormId = "search-form";
  19. }
  20. public bool IsSingle { get; set; }
  21. public string FormId { get; set; }
  22. public List<SearchItem> SearchItems { get; set; }
  23. }
  24. public class SearchItem
  25. {
  26. public SearchItem(string field, string displayName, FiledType filedType = FiledType.S, ExpType expType = ExpType.Contains,string value="", string formId = "",string showField="")
  27. {
  28. Field = field;
  29. DisplayName = displayName;
  30. FiledType = filedType;
  31. ExpType = expType;
  32. if (FiledType != FiledType.S)
  33. {
  34. ExpType = ExpType == ExpType.Contains ? ExpType.Equal : expType;
  35. }
  36. SelectItems = new List<SearchItemSelect>();
  37. Value = value;
  38. FormId = formId;
  39. ShowField = showField;
  40. }
  41. public string FormId { get; set; }
  42. public string Field { get; set; }
  43. public string DisplayName { get; set; }
  44. public string SearchModalId { get; set; }
  45. public FiledType FiledType { get; set; }
  46. public ExpType ExpType { get; set; }
  47. public List<SearchItemSelect> SelectItems { get; set; }
  48. public string Value { get; set; }
  49. public string ShowField { get; set; }
  50. public string SelectItemStr
  51. {
  52. get
  53. {
  54. if (!SelectItems.Any())
  55. {
  56. return "";
  57. }
  58. string str = "";
  59. foreach (var searchItemSelect in SelectItems)
  60. {
  61. str += $"\"{searchItemSelect.Filed}\":\"<option value=\\\'\\\' selected>请选择</option>";
  62. foreach (var item in searchItemSelect.Items)
  63. {
  64. str += $"<option value=\\\'{item.Value}\\\'>{item.Text}</option>";
  65. }
  66. str += "\"";
  67. }
  68. return str;
  69. }
  70. }
  71. private string _target;
  72. public string Target => !string.IsNullOrEmpty(_target) ? _target : "";
  73. public SearchItem SetSearchIcon(string modalId,string target = null)
  74. {
  75. SearchModalId = modalId;
  76. _target = target;
  77. return this;
  78. }
  79. public SearchItem SetSearchItem(List<SelectListItem> items, string filed = null,bool isAddBlank=true)
  80. {
  81. filed = filed ?? Field;
  82. SelectItems.Add(new SearchItemSelect(filed, items,isAddBlank));
  83. ExpType = ExpType == ExpType.Contains ? ExpType.Equal : ExpType;
  84. return this;
  85. }
  86. }
  87. public class SearchItemSelect
  88. {
  89. public SearchItemSelect(string filed, List<SelectListItem> items)
  90. {
  91. Filed = filed;
  92. Items = items;
  93. IsAddBlank = true;
  94. }
  95. public SearchItemSelect(string filed, List<SelectListItem> items,bool isAddBlank)
  96. {
  97. Filed = filed;
  98. Items = items;
  99. IsAddBlank = isAddBlank;
  100. }
  101. public bool IsAddBlank { get; set; }
  102. public string Filed { get; set; }
  103. public List<SelectListItem> Items { get; set; }
  104. }
  105. public enum FiledType
  106. {
  107. /// <summary>
  108. /// string
  109. /// </summary>
  110. S = 0,
  111. /// <summary>
  112. /// int
  113. /// </summary>
  114. I = 1,
  115. /// <summary>
  116. /// int?
  117. /// </summary>
  118. Inull = 2,
  119. /// <summary>
  120. /// bool
  121. /// </summary>
  122. B = 3,
  123. /// <summary>
  124. /// bool?
  125. /// </summary>
  126. Bnull = 4,
  127. /// <summary>
  128. /// Datetime
  129. /// </summary>
  130. D = 5,
  131. /// <summary>
  132. /// Datetime?
  133. /// </summary>
  134. Dnull = 6,
  135. /// <summary>
  136. /// Decimal
  137. /// </summary>
  138. Dec = 7,
  139. /// <summary>
  140. /// Decimal?
  141. /// </summary>
  142. DecNull = 8
  143. }
  144. public enum ExpType
  145. {
  146. Equal
  147. , NotEqual
  148. , Greater
  149. , Less
  150. , GreaterOrEqual
  151. , LessOrEqual
  152. , Contains
  153. , NotContains
  154. }
  155. }