_QueryModal.cshtml 15 KB

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