_QueryModal.cshtml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. @using System.Linq;
  2. @using Abp.Extensions
  3. @using ContractService.Helpers
  4. @using ContractService.Views.Shared.Modals
  5. @using ContractService.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.SearchBindFun;
  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_table_@(Model.ModalId)" 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 id="table_@(modalId)" 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" 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 = $("#table_@(modalId)"), _searchList_@(modalId) = [], _searchKeyWord_@(modalId) = "";
  138. $("#@(modalId)").off('shown.bs.modal').on('shown.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: 550,
  172. onDblClickRow: DbClickRow_@(modalId),
  173. queryParams: QueryParams_@(modalId),
  174. multipleSelect:@(Model.IsMultiple?"true":"false"),
  175. onLoadSuccess: function() {
  176. setTimeout(function() {$@(modalId)_table.bootstrapTable('resetView');},500);
  177. }
  178. });
  179. }
  180. function QueryParams_@(modalId)(params) {
  181. SearchList_@(modalId)();
  182. return {
  183. MaxResultCount: params.limit,
  184. SkipCount: params.offset,
  185. sort: params.sort,
  186. sortOrder: params.order,
  187. SearchList: _searchList_@modalId,
  188. KeyField: "@(tField)",
  189. FieldType: "@(tFType)",
  190. ExpType: "@(tExpType)",
  191. KeyWords: _searchKeyWord_@modalId
  192. };
  193. }
  194. function SearchList_@(modalId)() {
  195. _searchList_@modalId = [];
  196. if (@(isAddBind)) {
  197. _searchList_@(modalId).push(@(searBindFunc));
  198. }
  199. $("#@modalId form").find(".KeyWords").each(function() {
  200. var $this = $(this), keyWords = $this.val();
  201. if (keyWords) {
  202. _searchList_@(modalId).push({
  203. KeyWords: keyWords,
  204. KeyField: $this.data('field'),
  205. FieldType: $this.data('ftype'),
  206. ExpType: $this.data('etype')
  207. });
  208. }
  209. });
  210. }
  211. function Clear_@(modalId)() {
  212. Submit_@(modalId)(false, true);
  213. }
  214. function Submit_@(modalId)(rows, isClear) {
  215. //console.log('@(modalId)submit', rows, isClear);
  216. @{
  217. string str;
  218. if (string.IsNullOrEmpty(submit))
  219. {
  220. str = " var $target,value='', rows =rows|| $" + modalId + "_table.iwbTable(\"getSelections\"),name='';\r\n";
  221. str += "if (rows) {\r\n";
  222. int i = 0;
  223. foreach (var targetFields in Model.TargetFields)
  224. {
  225. str += "if(!isClear){\r\n";
  226. if (Model.IsMultiple)
  227. {
  228. str += "value='';\r\n";
  229. str += "rows.forEach(function(row) {\r\n";
  230. str += "value += (value===''?'':',')+(row." + Model.OriginFields[i] + " ? row." + Model.OriginFields[i] + ":'');\r\n";
  231. str += "});\r\n";
  232. }
  233. else
  234. {
  235. str += "var row=Array.isArray(rows)? rows[0]:rows;\r\n ";
  236. str += "value = row && row." + Model.OriginFields[i] + " ? row." + Model.OriginFields[i] + ":'';\r\n";
  237. if (!string.IsNullOrEmpty(Model.AjaxSelectNameField))
  238. {
  239. str += "name = row && row." + Model.AjaxSelectNameField + " ? row." + Model.AjaxSelectNameField + ":'';\r\n";
  240. }
  241. }
  242. str += "}\r\n";
  243. str += "console.log('" + modalId + "',value,'"+ string.Join(",", targetFields) + "');\r\n";
  244. foreach (var targetFiled in targetFields)
  245. {
  246. str += "\r\n$target = $(window.queryModalTarget + ' " + targetFiled + "');\r\n";
  247. str += "if ($target) {\r\n";
  248. str += "$target.val(value);\r\nif ($target.is('select')) {\r\nif($target.hasClass('ajax-select'))\r\n{if(isClear){$target.trigger('change');}else{ window.ChangAjaxSelectValue($target,value,name);}\r\n}else\r\n{$target.trigger('change');} \r\n} \r\n}\r\n";
  249. }
  250. i++;
  251. }
  252. str += " } else\r\n" +
  253. "{\r\n" +
  254. "abp.message.warn(abp.localization.localize(\"ChooseOneToOp\"));\r\n" +
  255. "}\r\n";
  256. }
  257. else
  258. {
  259. str = submit + "(row);\r\n";
  260. }
  261. }
  262. @Html.Raw(str)
  263. $("#@modalId").modal('hide');
  264. }
  265. function DbClickRow_@(modalId)(row) {
  266. row = row || {};
  267. @{
  268. str = Model.IsMultiple ? "" : string.IsNullOrEmpty(dbClick) ? "Submit_" + modalId + "(row)" : dbClick + "(row);";
  269. }
  270. @Html.Raw(str)
  271. }
  272. @*function ClickRow_@(modalId)() {
  273. "use strict";
  274. @{
  275. str = "";
  276. if (!string.IsNullOrEmpty(click))
  277. {
  278. str = click + "();";
  279. }
  280. }
  281. @Html.Raw(str)
  282. }*@
  283. </script>
  284. <!-- QUERY-MODAL-SCRIPT @(Model.ModalId) END-->
  285. }
  286. <!-- QUERY-MODAL @(Model.ModalId) END-->