VmQuerySearch.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. namespace VberAdmin.Web.Models.Modals;
  2. public class VmQuerySearch
  3. {
  4. public readonly string _targetField;
  5. public VmQuerySearch()
  6. {
  7. ModalWidth = 900;
  8. IsSingle = true;
  9. }
  10. public VmQuerySearch(string modalId) : this()
  11. {
  12. ModalId = modalId;
  13. }
  14. /// <summary>
  15. /// <param name="modalId"></param>
  16. /// <param name="targetField">"id,name" "1:name,3:displayName" "1:name|name2,3:displayName"</param>
  17. /// <param name="originField">"id,name,name2,displayName"</param>
  18. /// </summary>
  19. public VmQuerySearch(string modalId, string targetField, string originField = null) : this(modalId)
  20. {
  21. _targetField = targetField;
  22. OriginField = originField;
  23. }
  24. public string ModalId { get; set; }
  25. public string ModalName { get; set; }
  26. public int ModalWidth { get; set; }
  27. public string TargetField
  28. {
  29. get
  30. {
  31. if (TargetFields is { Length: > 0 }) return string.Join(",", TargetFields);
  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 AND selectOption
  50. /// </summary>
  51. public Dictionary<string, string>[] SelectStrDic { get; set; }
  52. public VmQueryTreeSearch VmQueryTreeSearch { get; set; }
  53. public string SubmitEventName { get; set; }
  54. public string ItemClickEventName { get; set; }
  55. public string ItemDbClickEventName { get; set; }
  56. public bool IsSingle { get; set; }
  57. public VmQuerySearch SetModal(string modalId, string modalName = "", int width = 900)
  58. {
  59. if (!string.IsNullOrEmpty(modalId)) ModalId = modalId;
  60. ModalName = modalName;
  61. ModalWidth = width;
  62. return this;
  63. }
  64. public VmQuerySearch SetMultiple()
  65. {
  66. IsSingle = false;
  67. return this;
  68. }
  69. public VmQuerySearch SetTargetFields(params string[] targets)
  70. {
  71. TargetFields = targets;
  72. return this;
  73. }
  74. public VmQuerySearch SetAjaxSelectWithTarget(string selectName, params string[] targets)
  75. {
  76. AjaxSelectNameField = selectName;
  77. TargetFields = targets;
  78. return this;
  79. }
  80. public VmQuerySearch SetOriginField(params string[] originFields)
  81. {
  82. OriginField = string.Join(",", originFields);
  83. return this;
  84. }
  85. public VmQuerySearch SetAjaxSelectName(string name)
  86. {
  87. AjaxSelectNameField = name;
  88. return this;
  89. }
  90. public VmQuerySearch SetSearchFun(string funName)
  91. {
  92. SearchBindFun = funName;
  93. return this;
  94. }
  95. public VmQuerySearch SetSelectStrDic(params Dictionary<string, string>[] dic)
  96. {
  97. SelectStrDic = dic;
  98. return this;
  99. }
  100. /// <summary>
  101. /// 0:SubmitEventName(默认),1:ItemClickEventName,2:ItemDbClickEventName
  102. /// </summary>
  103. /// <param name="name"></param>
  104. /// <param name="type"></param>
  105. /// <returns></returns>
  106. public VmQuerySearch SetEventName(string name, int type = 0)
  107. {
  108. switch (type)
  109. {
  110. case 0:
  111. SubmitEventName = name;
  112. break;
  113. case 1:
  114. ItemClickEventName = name;
  115. break;
  116. case 2:
  117. ItemDbClickEventName = name;
  118. break;
  119. }
  120. return this;
  121. }
  122. }