VmSearchItem.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. using VberAdmin.Web.Models.Input;
  2. namespace VberAdmin.Web.Models.Search;
  3. public class VmSearchItem : VmInput
  4. {
  5. public VmSearchItem(string name, string displayName) : base(name, displayName)
  6. {
  7. FieldType = FType.S;
  8. ExpType = EType.Contains;
  9. InputType = VmInputType.Default;
  10. SetOther();
  11. }
  12. public VmSearchItem(string name, string displayName, bool isOnlyView) : this(name, displayName)
  13. {
  14. IsOnlyView = isOnlyView;
  15. }
  16. public VmSearchItem(string name, string displayName, string options, bool isAddBlank = false, bool isTree = false) : this(name, displayName)
  17. {
  18. WithSelect(options, isAddBlank, isTree);
  19. }
  20. public VmSearchItem(string name, string displayName, FType fieldType, EType expType = EType.Contains) : this(name, displayName)
  21. {
  22. _hasSetFiled = true;
  23. FieldType = fieldType;
  24. if (FieldType != FType.S)
  25. {
  26. ExpType = ExpType == EType.Contains ? EType.Equal : expType;
  27. }
  28. SetOther();
  29. }
  30. #region 字段属性
  31. public VmSearch Search { get; set; }
  32. public string SearchId => Search?.Id ?? "";
  33. /// <summary>
  34. /// 不参与参与后台查询,只前台显示
  35. /// </summary>
  36. public bool IsOnlyView { get; set; }
  37. /// <summary>
  38. /// Date
  39. /// </summary>
  40. public VmInput InputItem { get; set; }
  41. /// <summary>
  42. /// Date
  43. /// </summary>
  44. public VmInputDate DateItem { get; set; }
  45. public VmInputDateRange DateRangeItem { get; set; }
  46. /// <summary>
  47. /// Select
  48. /// </summary>
  49. public VmInputSelect SelectItem { get; set; }
  50. public VmInputRadio RadioItem { get; set; }
  51. public VmInputSwitch SwitchItem { get; set; }
  52. public VmInputCheckBox CheckBoxItem { get; set; }
  53. /// <summary>
  54. /// 字段类型
  55. /// </summary>
  56. public FType FieldType { get; set; }
  57. /// <summary>
  58. /// 表达式类型
  59. /// </summary>
  60. public EType ExpType { get; set; }
  61. #endregion 字段属性
  62. public VmSearchItem WithOnlyView()
  63. {
  64. IsOnlyView = true;
  65. return this;
  66. }
  67. public VmSearchItem WithFieldType(FType fieldType, EType expType = EType.Contains)
  68. {
  69. FieldType = fieldType;
  70. if (FieldType != FType.S)
  71. {
  72. ExpType = ExpType == EType.Contains ? EType.Equal : expType;
  73. }
  74. _hasSetFiled = true;
  75. SetOther();
  76. return this;
  77. }
  78. public VmSearchItem WithExpType(EType expType)
  79. {
  80. ExpType = expType;
  81. if (FieldType != FType.S)
  82. {
  83. ExpType = ExpType == EType.Contains ? EType.Equal : expType;
  84. }
  85. _hasSetFiled = true;
  86. SetOther();
  87. return this;
  88. }
  89. private bool _hasSetFiled;
  90. private void SetOther()
  91. {
  92. if (!_hasSetFiled)
  93. {
  94. Other += SearchDataOption;
  95. }
  96. }
  97. private string SearchDataOption => $" data-search-keyWord=\"advance\" data-search-filed=\"{Name}\" data-search-exp-type=\"{(int)ExpType}\" data-search-filed-type=\"{(int)FieldType}\"";
  98. #region Select
  99. /// <summary>
  100. /// Select
  101. /// </summary>
  102. /// <param name="options"></param>
  103. /// <param name="addBlank"></param>
  104. /// <param name="isTree"></param>
  105. /// <param name="isMultiple"></param>
  106. /// <param name="other"></param>
  107. /// <returns></returns>
  108. public VmSearchItem WithSelect(string options, bool addBlank = false, bool isTree = false, bool isMultiple = false, string other = "")
  109. {
  110. InputType = VmInputType.Select;
  111. ExpType = EType.Equal;
  112. SelectItem = new VmInputSelect(Name, DisplayName, options, addBlank, isTree, isMultiple)
  113. { Other = other + SearchDataOption };
  114. return this;
  115. }
  116. public VmSearchItem WithSelect(VmInputSelect select)
  117. {
  118. InputType = VmInputType.Select;
  119. ExpType = EType.Equal;
  120. SelectItem = select;
  121. SelectItem.Other += SearchDataOption;
  122. return this;
  123. }
  124. ///// <summary>
  125. ///// AjaxSelect
  126. ///// </summary>
  127. ///// <param name="codeKey"></param>
  128. ///// <param name="modalId"></param>
  129. ///// <param name="clear"></param>
  130. ///// <param name="takeCount"></param>
  131. ///// <returns></returns>
  132. //public VmInputSelectAjax WithAjaxSelect(string codeKey, string modalId, string clear = "", int takeCount = 10)
  133. //{
  134. // return new VmInputSelectAjax(Name, DisplayName, codeKey, modalId, clear, takeCount);
  135. //}
  136. #endregion Select
  137. #region Date
  138. public new VmSearchItem WithDate()
  139. {
  140. InputType = VmInputType.Date;
  141. DateItem = new VmInputDate(Name, DisplayName) { Other = SearchDataOption };
  142. return this;
  143. }
  144. public new VmSearchItem WithDateTime()
  145. {
  146. InputType = VmInputType.Date;
  147. DateItem = new VmInputDateTime(Name, DisplayName) { IsOnlyTime = true, Other = SearchDataOption };
  148. return this;
  149. }
  150. public VmSearchItem WithDate(VmInputDate date)
  151. {
  152. InputType = VmInputType.Date;
  153. date.Other = SearchDataOption;
  154. DateItem = date;
  155. return this;
  156. }
  157. public VmSearchItem WithDateTime(VmInputDateTime date)
  158. {
  159. InputType = VmInputType.Date;
  160. date.Other = SearchDataOption;
  161. DateItem = date;
  162. return this;
  163. }
  164. public new VmSearchItem WithDateRange()
  165. {
  166. InputType = VmInputType.Date;
  167. DateItem = new VmInputDateRange(Name, DisplayName) { Other = SearchDataOption };
  168. return this;
  169. }
  170. public new VmSearchItem WithDateTimeRange()
  171. {
  172. InputType = VmInputType.DateTime;
  173. DateItem = new VmInputDateTimeRange(Name, DisplayName) { IsOnlyTime = true, Other = SearchDataOption };
  174. return this;
  175. }
  176. public VmSearchItem WithDateRange(VmInputDateRange date)
  177. {
  178. InputType = VmInputType.Date;
  179. date.Other = SearchDataOption;
  180. DateItem = date;
  181. return this;
  182. }
  183. public VmSearchItem WithDateTime(VmInputDateTimeRange date)
  184. {
  185. InputType = VmInputType.Date;
  186. date.Other = SearchDataOption;
  187. DateItem = date;
  188. return this;
  189. }
  190. #endregion Date
  191. #region CheckBox & Radio & Switch
  192. /// <summary>
  193. /// CheckBox (name,value , name,value 成对设置)
  194. /// </summary>
  195. /// <param name="items">name,value , name,value 成对设置</param>
  196. /// <returns></returns>
  197. public new VmSearchItem WithCheckBox(params string[] items)
  198. {
  199. InputType = VmInputType.CheckBox;
  200. CheckBoxItem = new VmInputCheckBox(Name, DisplayName) { Other = SearchDataOption }.WithItems(items);
  201. return this;
  202. }
  203. /// <summary>
  204. /// Radio (name,value , name,value 成对设置)
  205. /// </summary>
  206. /// <param name="items"></param>
  207. /// <returns></returns>
  208. public new VmSearchItem WithRadio(params string[] items)
  209. {
  210. InputType = VmInputType.RadioBox;
  211. RadioItem = new VmInputRadio(Name, DisplayName).WithItems(items);
  212. RadioItem.Items.ForEach(item => { item.Other = SearchDataOption; });
  213. return this;
  214. }
  215. /// <summary>
  216. /// Radio (name,value , name,value 成对设置)
  217. /// </summary>
  218. /// <param name="items"></param>
  219. /// <returns></returns>
  220. public new VmSearchItem WithSwitch(params string[] items)
  221. {
  222. InputType = VmInputType.Switch;
  223. SwitchItem = new VmInputSwitch(Name, DisplayName) { Other = SearchDataOption }.WithItems(items);
  224. return this;
  225. }
  226. #endregion CheckBox & Radio & Switch
  227. #region 配合查询模态框使用
  228. /// <summary>
  229. /// 需展示的字段ID
  230. /// 如 名称 等(隐藏编号),名称不参与查询,编号参与查询
  231. /// </summary>
  232. public string ShowId { get; set; }
  233. //private string _targetFormId;
  234. //public string TargetFormId => _targetFormId.NotEmpty() ? _targetFormId : SearchId.Empty() ? "vber_search" : SearchId;
  235. public VmSearchItem WithQueryIcon(string modalId, string target = null, string clear = null, string showId = null)
  236. {
  237. base.WithQueryIcon(modalId, target, clear);
  238. ShowId = showId;
  239. if (showId != null)
  240. {
  241. IsHidden = true;
  242. }
  243. return this;
  244. }
  245. #endregion 配合查询模态框使用
  246. }