_SearchForm.cshtml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. @using Abp.Extensions
  2. @using ShwasherSys
  3. @using ShwasherSys.Models.Layout
  4. @model SearchFormViewModal
  5. <style>
  6. .search-unit.FieldType.ExpType.KeyWords.multi {
  7. font-size: 14px;
  8. }
  9. .search-unit .input-group-addon.search-icon {
  10. z-index: 3;
  11. font-size: 14px;
  12. min-width: 35px !important;
  13. line-height: 28px !important;
  14. height: 28px !important;
  15. border-radius: 0 3px 3px 0 !important;
  16. text-align: center !important;
  17. right: 0px !important;
  18. }
  19. </style>
  20. <div class="input-group input-group-sm hidden-sm hidden-xs hidden-sm" id="SearchBox" style="position: absolute; width: 100%; z-index: 2;max-width: 300px">
  21. <form id="SearchForm">
  22. @{
  23. var selectItemStr = "{";
  24. if (Model.SearchItems.Any())
  25. {
  26. int i = 0;
  27. if (Model.IsSingle)
  28. {
  29. <div class="search-unit" data-index="1">
  30. <select id="KeyField-1" name="KeyField-1" class="form-control KeyField" style="width: 100px !important">
  31. @foreach (var item in Model.SearchItems)
  32. {
  33. int isSelect = 0;
  34. if (!string.IsNullOrEmpty(item.SelectItemStr))
  35. {
  36. selectItemStr += (selectItemStr == "{" ? "" : ",") + item.SelectItemStr;
  37. isSelect = 1;
  38. }
  39. string selected = i == 0 ? "selected" : "";
  40. int fieldType = (int) item.FiledType;
  41. int expType = (int) item.ExpType;
  42. <option value="@item.Field" data-index="1" data-select="@isSelect" data-field="@item.Field" data-field-type="@fieldType" data-exp-type="@expType" @selected>@item.DisplayName</option>
  43. i++;
  44. }
  45. </select>
  46. <input id="FieldType-1" name="FieldType-1" class="FieldType" type="hidden" value="0" />
  47. <input id="ExpType-1" name="ExpType-1" class="ExpType" type="hidden" value="6"/>
  48. <input id="KeyWords-1" name="KeyWords-1" class="form-control pull-right KeyWords" style="width: calc(100% - 100px) !important" placeholder="请输入查询关键字..." autocomplete="off" />
  49. <span class="btn search-btn" data-type="_" onclick="BtnSearch(true)"><i class="iconfont icon-search "></i></span>
  50. </div>
  51. }
  52. else
  53. {
  54. <div class="panel-group" id="search-multi">
  55. <div class="panel panel-default">
  56. <div class="panel-heading">
  57. <h4 class="panel-title">
  58. <a data-toggle="collapse" data-parent="#search-multi" href="#collapse1" style="width:100%">点击展开多条件查询框查询</a>
  59. <span class="search-icon" onclick="BtnSearch(true)" style=""><i class="iconfont icon-search "></i></span>
  60. </h4>
  61. </div>
  62. <div id="collapse1" class="panel-collapse collapse">
  63. <div class="panel-body">
  64. @{
  65. foreach (var item in Model.SearchItems)
  66. {
  67. i++;
  68. int fieldType = (int) item.FiledType;
  69. int expType = (int) item.ExpType;
  70. string keyField = item.Field;
  71. <div class="search-unit" data-index="@i">
  72. <div class="input-group input-group-sm text-non" style="position: relative; width: 100%;">
  73. <span class="input-group-addon">@item.DisplayName</span>
  74. @*<input id="KeyField-@i" name="KeyField-@i" class="KeyField" style="display: none" value="@item.Field" />*@
  75. <input id="KeyField-@i" name="KeyField-@i" class="KeyField" style="display: none" value="@keyField" />
  76. <input id="FieldType-@i" name="FieldType-@i" class="FieldType" type="hidden" value="@fieldType" />
  77. <input id="ExpType-@i" name="ExpType-@i" class="ExpType" type="hidden" value="@expType" />
  78. @{
  79. var selectItem = item.SelectItems.FirstOrDefault(a => a.Filed == item.Field);
  80. if (selectItem != null)
  81. {
  82. <select id="KeyWords-@i" name="KeyWords-@i" class="form-control pull-right KeyWords multi" placeholder="请选择查询项..." autocomplete="off" data-placeholder="请选择查询项..." style="width: 100%">
  83. @if (selectItem.IsAddBlank)
  84. {
  85. <option value="">请选择</option>
  86. }
  87. @foreach (var sItem in selectItem.Items)
  88. {
  89. <option value="@sItem.Value">@sItem.Text</option>
  90. }
  91. </select>
  92. }
  93. else
  94. {
  95. string placeholder, classStr = "";
  96. if (item.FiledType == FiledType.I)
  97. {
  98. placeholder = "需查询的数字";
  99. classStr = "number";
  100. }
  101. else if (item.FiledType == FiledType.D || item.FiledType == FiledType.Dnull)
  102. {
  103. placeholder = "需查询的日期";
  104. classStr = "dateISO iwb-date";
  105. }
  106. else
  107. {
  108. placeholder = "查询关键字";
  109. }
  110. if (!item.ShowField.IsNullOrEmpty())
  111. {
  112. <input id="KeyWords-@i" name="KeyWords-@i" class="KeyWords multi" type="hidden" value="" />
  113. <input id="KeyWords-@item.ShowField-@i" name="KeyWords-@item.ShowField-@i" class="form-control @classStr pull-right multi" placeholder="请输入@(placeholder)..." value="" readonly="readonly" />
  114. }
  115. else
  116. {
  117. <input id="KeyWords-@i" name="KeyWords-@i" class="form-control @classStr pull-right KeyWords multi" placeholder="请输入@(placeholder)..." autocomplete="off" value="@item.Value" />
  118. }
  119. if (!string.IsNullOrEmpty(item.SearchModalId))
  120. {
  121. <div class="input-group-addon search-icon" style="width:45px" >
  122. <i class="iconfont icon-search" onclick="ShowQueryModal('@item.SearchModalId', '@item.Target');"></i>
  123. <i class="iconfont icon-delete" onclick="ClearKeyWord(this)"></i>
  124. </div>
  125. @*<div class="input-group-addon search-icon" >
  126. </div>*@
  127. }
  128. }
  129. }
  130. </div>
  131. </div>
  132. }
  133. }
  134. <span class="search-button" onclick="BtnSearch(true)" style=""><i class="iconfont icon-search "></i>查询</span>
  135. </div>
  136. </div>
  137. </div>
  138. </div>
  139. }
  140. }
  141. selectItemStr += "}";
  142. }
  143. </form>
  144. </div>
  145. @using (Html.BeginScripts())
  146. {
  147. <script>
  148. $(function () {
  149. $(".search-unit select").select2();
  150. $(".KeyField").off("change.keyfield").on("change.keyfield", function () {
  151. var $that = $(this).find("option:selected");
  152. var selectIndex = $that.data("index"),
  153. isSelect = $that.data("select"),
  154. field = $that.data("field"),
  155. expType = $that.data("exp-type"),
  156. fieldType = $that.data("field-type");
  157. changeKeyWord(selectIndex, isSelect,field, expType, fieldType);
  158. });
  159. var selectItem = @Html.Raw(selectItemStr);
  160. function changeKeyWord(index, isSelect,field,expType, fieldType) {
  161. var $index = $(".search-unit[data-index='" + index + "']");
  162. $index.find(".ExpType").val(expType);
  163. $index.find(".FieldType").val(fieldType);
  164. var str;
  165. var id = $index.find(".KeyWords").attr("id");
  166. console.log(fieldType, "-", isSelect);
  167. if (isSelect) {
  168. if (selectItem.length < 0) {
  169. return;
  170. }
  171. str = '<select id="' + id + '" name="' + id + '" class="form-control pull-right KeyWords" style="width: calc(100% - 120px) !important;" placeholder="请选择查询项..." autocomplete="off" data-placeholder="请选择查询项...">';
  172. str += selectItem[field];
  173. str += '</select>';
  174. $index.find(".KeyWords").next("span.select2").remove();
  175. $index.find(".KeyWords").remove();
  176. $index.find(".ExpType").after(str);
  177. $index.find(".KeyWords").select2();
  178. if ($index.find(".search-btn").length>0) {
  179. $index.find(".KeyWords").next().find(".select2-selection__arrow").css("right", "30px");
  180. }
  181. } else {
  182. if (fieldType === 1) {
  183. str = ' <input id="' + id + '" name="' + id + '" class="form-control number pull-right KeyWords" style="width: calc(100% - 100px) !important" placeholder="请输入需查询的数字..." autocomplete="off" />';
  184. } else if (fieldType === 5) {
  185. str = ' <input id="' + id + '" name="' + id + '" class="form-control dateISO pull-right KeyWords" style="width: calc(100% - 100px) !important" placeholder="请输入需查询的日期..." autocomplete="off" />';
  186. } else {
  187. str = '<input id="' + id + '" name="' + id + '" class="form-control pull-right KeyWords" style="width: calc(100% - 100px) !important" placeholder="请输入查询关键字..." autocomplete="off" />';
  188. }
  189. $index.find(".KeyWords").next("span.select2").remove();
  190. $index.find(".KeyWords").remove();
  191. $index.find(".ExpType").after(str);
  192. }
  193. AddSearchEvents();
  194. }
  195. });
  196. function ClearKeyWord(dom) {
  197. $(dom).closest('.search-unit').find('input[id^="KeyWords"]').val("");
  198. }
  199. </script>
  200. }