_QueryModal.cshtml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. @using System.Linq;
  2. @using Abp.Extensions
  3. @using ShwasherSys
  4. @using ShwasherSys.Views.Shared.New.Query
  5. @model QueryViewModel
  6. @{
  7. string modalId = Model.ModalId ?? "";
  8. string submit = Model.SubmitEventName ?? "";
  9. //string click = Model.ItemClickEventName ?? "";
  10. string dbClick = Model.ItemDbClickEventName ?? "";
  11. string width = Model.ModalWidth > 0 ? "min-width:" + Model.ModalWidth + "px" : "";
  12. QueryTreeSearch treeSearch = Model.QueryTreeSearch;
  13. string tField = "", selectUrl = "", tSelectFiledName = "";
  14. int tFType = 0; int tExpType = 0;
  15. if (treeSearch != null)
  16. {
  17. tField = treeSearch.Field;
  18. tFType = treeSearch.FType;
  19. tExpType = treeSearch.EType;
  20. selectUrl = treeSearch.SelectUrl;
  21. tSelectFiledName = treeSearch.SelectFieldName;
  22. }
  23. string searBindFunc = Model.SearchBindFunc;
  24. string isAddBind = "false";
  25. if (!searBindFunc.IsNullOrEmpty())
  26. {
  27. isAddBind = "true";
  28. }
  29. }
  30. <!-- QUERY-MODAL @(Model.ModalId) START-->
  31. <style>
  32. .query-modal.KeyWords {
  33. text-decoration: none;
  34. }
  35. </style>
  36. <section>
  37. <div class="modal fade query-modal" id="@modalId" role="dialog" tabindex="-1" aria-hidden="true">
  38. <div class="modal-dialog" role="document" style="@width">
  39. <div class="modal-content">
  40. <div class="modal-header">
  41. <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><span aria-hidden="true">&times;</span></button>
  42. <h4 class="modal-title">
  43. <span>@Html.Raw(Model.ModalName)</span>
  44. </h4>
  45. </div>
  46. <div class="modal-body container-fluid" style="padding: 5px">
  47. <div id="tree-box" class="row">
  48. @{
  49. string colClass = "col-md-12";
  50. if (treeSearch != null)
  51. {
  52. colClass = "col-md-9";
  53. <div class="col-md-3" style="padding-right: 0;">
  54. <div style="height: 100%; padding: 5px 0;">
  55. <div id="treeView_@modalId" class="iwb-treeView"></div>
  56. </div>
  57. </div>
  58. }
  59. }
  60. <div class="@colClass" style="">
  61. <div class="table-box iwb-bootstrap-table">
  62. <div class="btn-toolbar row" id="query_tableTool" role="toolbar" aria-label="Toolbar with button groups">
  63. <div class="col-sm-12 pull-left" style="padding: 0">
  64. <form>
  65. @if (Model.QueryItems != null && Model.QueryItems.Any())
  66. {
  67. string colMd = Model.QueryItems.Count(a => a.IsSearch) > 2 ? "col-md-4" : "col-md-6";
  68. int i = 0;
  69. foreach (var item in Model.QueryItems)
  70. {
  71. if (item.IsSearch)
  72. {
  73. i++;
  74. int fieldType = (int)item.FieldType, expType = (int)item.ExpType;
  75. <div class="@colMd">
  76. <div class="input-group">
  77. <input type="text" class="form-control" id="Q-KeyWords-@i" name="KeyWords-@i" placeholder="@(L("PlaceholderHeader"))@(item.Name)">
  78. @*<input type="hidden" id="Q-KeyField-@i" name="KeyField-@i" value="@item.Key">
  79. <input type="hidden" id="Q-FieldType-@i" name="FieldType-@i" value="@filedType">
  80. <input type="hidden" id="Q-ExpType-@i" name="ExpType-@i" value="@expType">*@
  81. <input id="@(modalId)-@(item.Key)" name="@(modalId)-@(item.Key)" class="form-control KeyWords" data-field="@(item.Key)" data-ftype="@(fieldType)" data-etype="@(expType)" placeholder="@(L("SearchPlaceholder"))" autocomplete="off" type="text" />
  82. <span class="input-group-addon search-icon" onclick="@(modalId)Refresh()">
  83. <i class="iconfont icon-search"></i>
  84. </span>
  85. </div>
  86. </div>
  87. }
  88. }
  89. }
  90. </form>
  91. </div>
  92. </div>
  93. <table data-url="@Model.QueryUrl"
  94. data-striped="true" data-id-field="id" data-unique-id="id"
  95. data-method="get"
  96. data-side-pagination="server"
  97. data-content-type="application/x-www-form-urlencoded; charset=UTF-8"
  98. data-cache="false"
  99. data-pagination="true" data-page-size="10" data-page-number="1" data-page-list="[10,20,50]" data-pagination-detail-h-align="right" data-pagination-h-align="left"
  100. data-query-params="QueryParams_@(modalId)"
  101. data-response-handler="ResponseHandler"
  102. data-click-to-select="true"
  103. data-single-select="true">
  104. <thead>
  105. <tr class="row">
  106. @if (Model.QueryItems != null && Model.QueryItems.Any())
  107. {
  108. <th data-field="state" data-checkbox="true"></th>
  109. foreach (var item in Model.QueryItems)
  110. {
  111. var formatter = string.IsNullOrEmpty(item.Formatter) ? "" : "data-formatter=\"" + item.Formatter + "\"";
  112. <th data-align="center" data-field="@item.Key" @Html.Raw(formatter)>@item.Name</th>
  113. }
  114. }
  115. </tr>
  116. </thead>
  117. </table>
  118. </div>
  119. </div>
  120. </div>
  121. </div>
  122. <div class="modal-footer" style="text-align: center;padding-top: 10px">
  123. <button type="button" class="btn btn-sm btn-default waves-effect" data-dismiss="modalProduct" style="min-width: 100px;" onclick="Clear_@(modalId)()">@(L("Clear"))</button>
  124. <button type="button" class="btn btn-sm save-btn waves-effect" style="min-width: 100px;" onclick="Submit_@(modalId)()">@(L("OK"))</button>
  125. </div>
  126. </div>
  127. </div>
  128. </div>
  129. </section>
  130. @using (Html.BeginScripts())
  131. {
  132. <script>
  133. //$(function() {
  134. //});
  135. var $@(modalId)_table = $("#@modalId table"), _searchList_@modalId = [], _searchKeyWord_@modalId = "";
  136. $("#@modalId").off('show.bs.modal').on('show.bs.modal', function () {
  137. $("#@modalId form").find(".key").val("");
  138. if ("@(tField)" && "@(tField)".length > 0){
  139. $('#treeView_@modalId').iwbTreeView({
  140. url: '@(selectUrl)',
  141. onNodeSelected: function(e, d) {
  142. _searchKeyWord_@(modalId) = d["@(tSelectFiledName)"];
  143. console.log("_searchKeyWord_", _searchKeyWord_@(modalId));
  144. $@(modalId)_table.iwbTable('refresh', true);
  145. },
  146. onNodeUnselected: function() {
  147. _searchKeyWord_@(modalId) = "";
  148. $@(modalId)_table.iwbTable('refresh', true);
  149. },
  150. table:$@(modalId)_table
  151. });
  152. }
  153. @(modalId)Search();
  154. });
  155. function @(modalId)Refresh() {
  156. $@(modalId)_table.iwbTable('refresh', true);
  157. }
  158. function @(modalId)Search() {
  159. $@(modalId)_table.iwbTable("destroy");
  160. SearchList_@(modalId)();
  161. LoadTable({
  162. table: $@(modalId)_table,
  163. height: 500,
  164. onDblClickRow: DbClickRow_@(modalId),
  165. queryParams: QueryParams_@(modalId)
  166. });
  167. }
  168. function QueryParams_@(modalId)(params) {
  169. SearchList_@(modalId)();
  170. return {
  171. MaxResultCount: params.limit,
  172. SkipCount: params.offset,
  173. sort: params.sort,
  174. sortOrder: params.order,
  175. SearchList: _searchList_@modalId,
  176. KeyField: "@(tField)",
  177. FieldType: "@(tFType)",
  178. ExpType: "@(tExpType)",
  179. KeyWords: _searchKeyWord_@modalId
  180. };
  181. }
  182. function SearchList_@(modalId)() {
  183. _searchList_@modalId = [];
  184. if (@(isAddBind)) {
  185. _searchList_@(modalId).push(@(searBindFunc));
  186. }
  187. $("#@modalId form").find(".KeyWords").each(function() {
  188. var $this = $(this), keyWords = $this.val();
  189. if (keyWords) {
  190. searchList.push({
  191. KeyWords: keyWords,
  192. KeyField: $this.data('field'),
  193. FieldType: $this.data('ftype'),
  194. ExpType: $this.data('etype')
  195. });
  196. }
  197. });
  198. }
  199. function Clear_@(modalId)() {
  200. Submit_@(modalId)(false, true);
  201. }
  202. function Submit_@(modalId)(row, isClear) {
  203. console.log('@(modalId)submit', row,isClear);
  204. @{
  205. string str;
  206. if (string.IsNullOrEmpty(submit))
  207. {
  208. str = " var $target,value, row =row|| $" + modalId + "_table.bootstrapTable(\"getSelections\")[0];\r\n";
  209. str += "if (row) {\r\n";
  210. int i = 0;
  211. foreach (var targetFields in Model.TargetFields)
  212. {
  213. str += "value = row." + Model.OriginFields[i] + " ? row." + Model.OriginFields[i] + ":'';\r\n";
  214. foreach (var targetFiled in targetFields)
  215. {
  216. str += @"$target = $(window.queryModalTarget + ' " + targetFiled + "');\r\n";
  217. str += "if ($target) {\r\n";
  218. str += "value= isClear?'':value\r\n";
  219. str += "$target.val(value);try{if ($target.is('select')) {$target.select2();}}catch (e) {} }\r\n";
  220. }
  221. i++;
  222. }
  223. str += " } else\r\n" +
  224. "{\r\n" +
  225. "abp.message.warn(abp.localization.localize(\"ChooseOneToOp\"));\r\n" +
  226. "}\r\n";
  227. }
  228. else
  229. {
  230. str = submit + "(row);\r\n";
  231. }
  232. }
  233. @Html.Raw(str)
  234. $("#@modalId").modal('hide');
  235. }
  236. function DbClickRow_@(modalId)(row) {
  237. row = row || {};
  238. @{
  239. str = string.IsNullOrEmpty(dbClick) ? "Submit_" + modalId+ "(row)" : dbClick + "(row);";
  240. }
  241. @Html.Raw(str)
  242. }
  243. @*function ClickRow_@(modalId)() {
  244. "use strict";
  245. @{
  246. str = "";
  247. if (!string.IsNullOrEmpty(click))
  248. {
  249. str = click + "();";
  250. }
  251. }
  252. @Html.Raw(str)
  253. }*@
  254. </script>
  255. }
  256. <!-- QUERY-MODAL @(Model.ModalId) END-->