QuerySearchModel.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. using System.Collections.Generic;
  2. using System.Web.Mvc;
  3. namespace ContractService.Views.Shared.Query
  4. {
  5. public class QuerySearchModel
  6. {
  7. public readonly string _targetField;
  8. public QuerySearchModel()
  9. {
  10. ModalWidth = 900;
  11. IsMultiple = false;
  12. }
  13. public QuerySearchModel(string modalId) : this()
  14. {
  15. ModalId = modalId;
  16. }
  17. public QuerySearchModel(string modalId, string targetField) : this(modalId)
  18. {
  19. _targetField = targetField;
  20. }
  21. public string ModalId { get; set; }
  22. public string ModalName { get; set; }
  23. public int ModalWidth { get; set; }
  24. public string TargetField
  25. {
  26. get
  27. {
  28. if (TargetFields != null && TargetFields.Length > 0)
  29. {
  30. return string.Join(",", TargetFields);
  31. }
  32. return _targetField;
  33. }
  34. }
  35. /// <summary>
  36. /// 目标字段
  37. /// </summary>
  38. public string[] TargetFields { get; set; }
  39. /// <summary>
  40. /// 有此值会覆盖模板的默认值。正常为空!
  41. /// </summary>
  42. public string OriginField { get; set; }
  43. /// <summary>
  44. /// 配合Ajax-Select 的赋值使用,
  45. /// </summary>
  46. public string AjaxSelectNameField { get; set; }
  47. public string SearchBindFun { get; set; }
  48. /// <summary>
  49. /// filed & selectOption
  50. /// </summary>
  51. public Dictionary<string, string>[] SelectStrDic { get; set; }
  52. public QueryTreeSearch QueryTreeSearch { get; set; }
  53. /// <summary>
  54. /// filed & selectOption
  55. /// </summary>
  56. public Dictionary<string, List<SelectListItem>>[] SelectListDic { get; set; }
  57. public string SubmitEventName { get; set; }
  58. public string ItemClickEventName { get; set; }
  59. public string ItemDbClickEventName { get; set; }
  60. public bool IsMultiple { get; set; }
  61. public QuerySearchModel SetModal(string modalId, string modalName = "", int width = 900)
  62. {
  63. if (!string.IsNullOrEmpty(modalId))
  64. {
  65. ModalId = modalId;
  66. }
  67. ModalName = modalName;
  68. ModalWidth = width;
  69. return this;
  70. }
  71. public QuerySearchModel SetMultiple()
  72. {
  73. IsMultiple = false;
  74. return this;
  75. }
  76. public QuerySearchModel SetTargetFields(params string[] targets)
  77. {
  78. TargetFields = targets;
  79. return this;
  80. }
  81. public QuerySearchModel SetAjaxSelectWithTarget(string selectName, params string[] targets)
  82. {
  83. AjaxSelectNameField = selectName;
  84. TargetFields = targets;
  85. return this;
  86. }
  87. public QuerySearchModel SetOriginField(params string[] originFields)
  88. {
  89. OriginField = string.Join(",", originFields);
  90. return this;
  91. }
  92. public QuerySearchModel SetAjaxSelectName(string name)
  93. {
  94. AjaxSelectNameField = name;
  95. return this;
  96. }
  97. public QuerySearchModel SetSearchFun(string funName)
  98. {
  99. SearchBindFun = funName;
  100. return this;
  101. }
  102. public QuerySearchModel SetSelectStrDic(params Dictionary<string, string>[] dic)
  103. {
  104. SelectStrDic = dic;
  105. return this;
  106. }
  107. public QuerySearchModel SetSelectListDic(params Dictionary<string, List<SelectListItem>>[] dic)
  108. {
  109. SelectListDic = dic;
  110. return this;
  111. }
  112. /// <summary>
  113. /// 0:SubmitEventName(默认),1:ItemClickEventName,2:ItemDbClickEventName
  114. /// </summary>
  115. /// <param name="name"></param>
  116. /// <param name="type"></param>
  117. /// <returns></returns>
  118. public QuerySearchModel SetEventName(string name, int type = 0)
  119. {
  120. switch (type)
  121. {
  122. case 0:
  123. SubmitEventName = name;
  124. break;
  125. case 1:
  126. ItemClickEventName = name;
  127. break;
  128. case 2:
  129. ItemDbClickEventName = name;
  130. break;
  131. }
  132. return this;
  133. }
  134. }
  135. }