QueryModalModel.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. using System;
  2. using System.Collections.Generic;
  3. using IwbZero.AppServiceBase;
  4. using ShwasherSys.Models.Layout;
  5. namespace ShwasherSys.Models.Modal
  6. {
  7. public class QueryModalModel
  8. {
  9. public QueryModalModel(string name,string url, List<QueryItem> queryItems, string originFiled,
  10. string targetFiled = null, string submitEventName = null,
  11. string modalId = "query_modal", int modalWidth = 900, string itemDbClickEventName = null,
  12. string itemClickEventName = null,string submitEx="",List<MultiSearchDto> searchDtos=null)
  13. {
  14. ModalName = name;
  15. QueryUrl = url;
  16. QueryItems = queryItems;
  17. OriginFileds = originFiled.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries);
  18. var targets = new string[OriginFileds.Length];
  19. TargetFileds=new List<string[]>();
  20. if (string.IsNullOrEmpty(targetFiled))
  21. {
  22. for (int i = 0; i < targets.Length; i++)
  23. {
  24. TargetFileds.Add(new []{ "#" + OriginFileds[i] });
  25. }
  26. }
  27. else
  28. {
  29. var targetArr= targetFiled.Split(new[] { ',' }, StringSplitOptions.None);
  30. int j = 0;
  31. for (int i = 0; i < targets.Length; i++)
  32. {
  33. if (j < targetArr.Length)
  34. {
  35. if (!string.IsNullOrEmpty(targetArr[j]))
  36. {
  37. var unitArr = targetArr[j].Split(new[] {':'}, StringSplitOptions.RemoveEmptyEntries);
  38. if (unitArr.Length>1)
  39. {
  40. if (int.TryParse(unitArr[0],out int index)&& index< OriginFileds.Length && index>=i)
  41. {
  42. for (; i < index; i++)
  43. {
  44. TargetFileds.Add(new[] { "#" + OriginFileds[i] });
  45. }
  46. AddTargetFiled(unitArr[1],i);
  47. }
  48. else
  49. {
  50. AddTargetFiled(unitArr[1],i);
  51. }
  52. }
  53. else
  54. {
  55. AddTargetFiled(targetArr[j],i);
  56. }
  57. }
  58. else
  59. {
  60. TargetFileds.Add(new[] { "#" + OriginFileds[i] });
  61. }
  62. j++;
  63. }
  64. else
  65. {
  66. TargetFileds.Add(new[] { "#" + OriginFileds[i] });
  67. }
  68. }
  69. }
  70. SubmitEventName = submitEventName;
  71. ModalId = modalId;
  72. ModalWidth = modalWidth;
  73. ItemClickEventName = itemClickEventName;
  74. ItemDbClickEventName = itemDbClickEventName ?? submitEventName;
  75. SubmitEx = submitEx;
  76. SearchList = searchDtos;
  77. }
  78. public string QueryUrl { get; set; }
  79. public List<QueryItem> QueryItems { get; set; }
  80. public string ModalId { get; set; }
  81. public string ModalName { get; set; }
  82. public int ModalWidth { get; set; }
  83. public string[] OriginFileds { get; set; }
  84. public List<string[]> TargetFileds { get; set; }
  85. public string SubmitEventName { get; set; }
  86. public string ItemClickEventName { get; set; }
  87. public string ItemDbClickEventName { get; set; }
  88. public string SubmitEx { get; set; }
  89. public List<MultiSearchDto> SearchList { get; set; }
  90. public string DefaultValueFunction { get; set; } = "QueryDefaultValueFunction";
  91. public QueryModalModel SetDefaultValueFunction(string v)
  92. {
  93. DefaultValueFunction = v;
  94. return this;
  95. }
  96. private void AddTargetFiled(string targetStr,int index)
  97. {
  98. var target = targetStr.Split(new[] { '|' }, StringSplitOptions.None);
  99. for (int i = 0; i < target.Length; i++)
  100. {
  101. target[i] =string.IsNullOrEmpty(target[i])? "#" + OriginFileds[index] : (target[i].StartsWith("#") || target[i].StartsWith("."))
  102. ? target[i]
  103. : "#" + target[i];
  104. }
  105. TargetFileds.Add(target);
  106. }
  107. }
  108. public class QueryItem
  109. {
  110. public QueryItem(string key, string name, bool isSearch = false, FiledType filedType = FiledType.S,
  111. ExpType expType = ExpType.Contains, string formatter = "",bool isSort = false)
  112. {
  113. Key = key;
  114. Name = name;
  115. IsSearch = isSearch;
  116. FiledType = filedType;
  117. ExpType = expType;
  118. Formatter = formatter;
  119. IsSort = isSort;
  120. }
  121. public string Key { get; set; }
  122. public string Name { get; set; }
  123. public string Formatter { get; set; }
  124. public bool IsSearch { get; set; }
  125. public string IsHidden { get; set; } = "";
  126. public FiledType FiledType { get; set; }
  127. public ExpType ExpType { get; set; }
  128. public bool IsSort { get; set; }
  129. public QueryItem SetHidden()
  130. {
  131. IsSearch = true;
  132. IsHidden = "style=display:none;";
  133. return this;
  134. }
  135. }
  136. public class QueryParamModel
  137. {
  138. public QueryParamModel(string targetDom,string submitEx="", List<MultiSearchDto> searchList=null,string modalId="")
  139. {
  140. SubmitEx = submitEx;
  141. TargetDom = targetDom;
  142. SearchList = searchList;
  143. ModalId = modalId;
  144. }
  145. public string ModalId { get; set; }
  146. public string TargetDom { get; set; }
  147. public string SubmitEx { get; set; }
  148. public List<MultiSearchDto> SearchList { get; set; }
  149. }
  150. }