QueryViewModel.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using System;
  2. using System.Collections.Generic;
  3. namespace ContractService.Views.Shared.Query
  4. {
  5. #region Query
  6. public class QueryViewModel
  7. {
  8. public QueryViewModel(string name, string url, string modalId, List<QueryItem> queryItems, string originField, string targetField,
  9. string ajaxSelectNameField = "", string submitEventName = null, string itemDbClickEventName = null,
  10. string itemClickEventName = null, bool isMultiple = false, QueryTreeSearch queryTreeSearch = null, string searchBindFun = "", int modalWidth = 900)
  11. {
  12. ModalName = name;
  13. QueryUrl = url;
  14. QueryItems = queryItems;
  15. SearchBindFun = searchBindFun;
  16. AjaxSelectNameField = ajaxSelectNameField;
  17. QueryTreeSearch = queryTreeSearch;
  18. OriginFields = originField.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  19. var targets = new string[OriginFields.Length];
  20. TargetFields = new List<string[]>();
  21. IsMultiple = isMultiple;
  22. if (string.IsNullOrEmpty(targetField))
  23. {
  24. for (int i = 0; i < targets.Length; i++)
  25. {
  26. TargetFields.Add(new[] { "#" + OriginFields[i] });
  27. }
  28. }
  29. else
  30. {
  31. var targetArr = targetField.Split(new[] { ',' }, StringSplitOptions.None);
  32. for (int i = 0; i < targets.Length; i++)
  33. {
  34. if (i < targetArr.Length)
  35. {
  36. if (!string.IsNullOrEmpty(targetArr[i]))
  37. {
  38. var unitArr = targetArr[i].Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
  39. if (unitArr.Length > 1)
  40. {
  41. if (int.TryParse(unitArr[0], out int index) && index < OriginFields.Length && index >= i)
  42. {
  43. for (; i < index; i++)
  44. {
  45. TargetFields.Add(new[] { "#" + OriginFields[i] });
  46. }
  47. AddTargetField(unitArr[1], i);
  48. }
  49. else
  50. {
  51. AddTargetField(unitArr[1], i);
  52. }
  53. }
  54. else
  55. {
  56. AddTargetField(targetArr[i], i);
  57. }
  58. }
  59. else
  60. {
  61. TargetFields.Add(new[] { "#" + OriginFields[i] });
  62. }
  63. }
  64. else
  65. {
  66. TargetFields.Add(new[] { "#" + OriginFields[i] });
  67. }
  68. }
  69. }
  70. SubmitEventName = submitEventName;
  71. ModalId = modalId;
  72. ModalWidth = modalWidth;
  73. ItemClickEventName = itemClickEventName;
  74. ItemDbClickEventName = itemDbClickEventName ?? submitEventName;
  75. }
  76. public string QueryUrl { get; set; }
  77. public List<QueryItem> QueryItems { get; set; }
  78. public string ModalId { get; set; }
  79. public string ModalName { get; set; }
  80. public int ModalWidth { get; set; }
  81. public string[] OriginFields { get; set; }
  82. public List<string[]> TargetFields { get; set; }
  83. public string SubmitEventName { get; set; }
  84. public string ItemClickEventName { get; set; }
  85. public string ItemDbClickEventName { get; set; }
  86. public QueryTreeSearch QueryTreeSearch { get; set; }
  87. public string SearchBindFun { get; set; }
  88. public bool IsMultiple { get; set; }
  89. public string AjaxSelectNameField { get; set; }
  90. private void AddTargetField(string targetStr, int index)
  91. {
  92. var target = targetStr.Split(new[] { '|' }, StringSplitOptions.None);
  93. for (int i = 0; i < target.Length; i++)
  94. {
  95. target[i] = string.IsNullOrEmpty(target[i]) ? "#" + OriginFields[index] : (target[i].StartsWith("#") || target[i].StartsWith("."))
  96. ? target[i]
  97. : "#" + target[i];
  98. }
  99. TargetFields.Add(target);
  100. }
  101. public QueryViewModel SetSearchFun(string funName)
  102. {
  103. SearchBindFun = funName;
  104. return this;
  105. }
  106. public QueryViewModel SetSearchTree(QueryTreeSearch searchTree)
  107. {
  108. QueryTreeSearch = searchTree;
  109. return this;
  110. }
  111. }
  112. //public class SearchBindDto
  113. //{
  114. // public string KeyField { get; set; }
  115. // public string KeyWords { get; set; }
  116. // public int FieldType { get; set; }
  117. // public int ExpType { get; set; }
  118. //}
  119. #endregion
  120. }