BehaviorRole.cshtml 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. @using WePlatform.Configuration
  2. @using WePlatform.Authorization
  3. @using WePlatform.Views.Shared.Modals
  4. @using WePlatform.Views.Shared.SearchForm
  5. @using WePlatform.Views.Shared.Table
  6. @{
  7. ViewBag.Title = "行为角色管理";
  8. string activeMenu = PermissionNames.PagesResourceMgBasicMgBehaviorRoleMg;
  9. string role = "<option value=\"NEW\">新建角色</option>" + ViewBag.Role, category = ViewBag.Category;
  10. ViewBag.ActiveMenu = activeMenu;
  11. var searchForm = new SearchFormViewModel(new List<SearchItem>()
  12. {
  13. new SearchItem("roleName","行为角色"),
  14. //new SearchItem("sceneCategory","场景类别").SetSelectItem(category,isTree:true),
  15. }, "search-form", false);
  16. var table = new TableViewModel(IwbConsts.ApiAppUrl + "BehaviorRole/GetAll", activeMenu, searchForm)
  17. .SetFields(new List<FieldItem>()
  18. {
  19. new FieldItem("id", "编码"),
  20. new FieldItem("roleName", "行为角色"),
  21. new FieldItem("sceneCategoryName", "场景类别",isSort:false),
  22. });
  23. }
  24. @section css{
  25. }
  26. @Html.Partial("Table/_Table", table)
  27. @section modal{
  28. <!--Main Modal-->
  29. @{
  30. var modal = new ModalViewModel("角色", new ModalBodyViewModel(new List<Input>()
  31. {
  32. new InputHide("id"),
  33. new InputHide("roleName"),
  34. new InputHide("relateNo"),
  35. new Input("role", "行为角色",other:"onchange=RoleChange(this,1)").SetSelectOptions(role),
  36. new Input("role2", "新建角色",other:"onchange=RoleChange(this)" ).SetNotRequired(),
  37. new Input("sceneCategory", "场景类别").SetSelectOptions(category,isAddBlank:false),
  38. new InputTextarea("description", "角色详情").SetNotRequired(),
  39. }));
  40. }
  41. @Html.Partial("Modals/_Modal", modal)
  42. }
  43. @section scripts
  44. {
  45. <script src="~/Content/Libs/select2/js/select2tree.js"></script>
  46. <script type="text/javascript">
  47. var $table = $('#table');
  48. $(function () {
  49. $('#role2').closest('.form-group').hide();
  50. var $exTool = $table.closest('.table-box').find('.tableTool #Tool1');
  51. $exTool.append(
  52. '<div class="ml-3"><div class="form-group row " style="margin-bottom:0;"><label class=" iwb-label iwb-label-sm mr-1 pt-1" style="color:#007bff" for="tool-sceneCategory">场景类别</label><div><div class="input-group input-group-sm"><select class="form-control" id="tool-sceneCategory" name="tool-sceneCategory" type="text" style="width:250px">@(Html.Raw(category))</select></div></div></div></div>');
  53. var root = $('#tool-sceneCategory option[parent="0"]').eq(0).attr('value');
  54. var defaultCategory = $('#tool-sceneCategory option[parent="'+root+'"]').eq(0).attr('value');
  55. //console.log(defaultCategory);
  56. $('#tool-sceneCategory').val(defaultCategory).select2tree();
  57. //$('#tool-sceneCategory').val('').select2tree();
  58. $table = LoadTable({ searchFun: CustomSearchList });
  59. var funs = window.iwbfuns || { none: function() { console.log("No type"); } };
  60. funs["btnCreate"] = function() {
  61. BtnCreate({
  62. data: { id: "" },
  63. select2tree: "sceneCategory",
  64. shownAfter: function() {
  65. $.iwbAjax4({
  66. url: abp.appUrl + "Query/GetBehaviorRoleSelectStr",
  67. success: function(res) {
  68. var str = "<option value=\"NEW\">新建角色</option>"
  69. if (res) {
  70. str += res;
  71. }
  72. $('#role').html(str);
  73. }
  74. });
  75. }
  76. });
  77. }
  78. funs["btnUpdate"] = function() {
  79. var row = $table.bootstrapTable("getSelections")[0];
  80. if (row) {
  81. BtnUpdate(
  82. {
  83. disabled: "",
  84. select2tree: "sceneCategory",
  85. shownAfter: function() {
  86. $.iwbAjax4({
  87. url: abp.appUrl + "Query/GetBehaviorRoleSelectStr",
  88. success: function (res) {
  89. var str = "<option value=\"NEW\">新建角色</option>"
  90. if (res) {
  91. str += res;
  92. }
  93. $('#role').html(str);
  94. if (res) {
  95. $('#role option').each(function() {
  96. if ($(this).text() == row.roleName) {
  97. $('#role').val($(this).attr('value'));
  98. return;
  99. }
  100. });
  101. }
  102. }
  103. });
  104. }
  105. },row);
  106. }
  107. };
  108. funs["btnDelete"] = function () {
  109. var row = $table.bootstrapTable("getSelections")[0];
  110. if (row) {
  111. MsgConfirm(abp.localization.iwbZero('DeleteConfirmContent'),
  112. abp.localization.iwbZero('DeleteConfirm'),
  113. function() {
  114. $.iwbAjax1({
  115. url: abp.appUrl + "BehaviorRole/DeleteRole?id=" + row.id + "&relateNo=" + row.relateNo,
  116. success: function () {
  117. RefreshTable();
  118. }
  119. });
  120. });
  121. }
  122. };
  123. $('#tool-sceneCategory').on('change.reTable', function() { RefreshTable("table", true); });
  124. $('#sceneCategory').on('change.reTable',
  125. function(e) {
  126. $('#tool-sceneCategory').off('change.reTable');
  127. $('#tool-sceneCategory').val($(this).val()).select2tree();
  128. $('#tool-sceneCategory').on('change.reTable', function() { RefreshTable("table", true); });
  129. });
  130. });
  131. function RoleChange(that,type) {
  132. if (type) {
  133. if ($(that).val() == "NEW") {
  134. $('#role2').closest('.form-group').show();
  135. } else {
  136. $('#role2').closest('.form-group').hide();
  137. $('#roleName').val($(that).find('option:selected').text());
  138. }
  139. } else {
  140. $('#roleName').val($(that).val());
  141. }
  142. }
  143. function CustomSearchList(searchList) {
  144. var keyWord = $('#tool-sceneCategory').val();
  145. if (keyWord) {
  146. searchList.push({
  147. KeyWords: keyWord,
  148. KeyField: "CategoryNo",
  149. FieldType: 0,
  150. ExpType: 0
  151. });
  152. }
  153. }
  154. </script>
  155. <!--格式化-->
  156. <script id="formatter-script" type="text/javascript">
  157. function TypeFormatter(v) {
  158. var name = $('#hid-type option[value="' + v + '"]').text();
  159. switch (v) {
  160. case 0:
  161. return '<span class="label label-danger">' + name + '</span>';
  162. default:
  163. return '<span class="label label-info">' + name + '</span>';
  164. }
  165. }
  166. </script>
  167. }
  168. <section style="display: none">
  169. <select id="hid-type">
  170. <option value=""></option>
  171. </select>
  172. @*@Html.DropDownList("hid-type", type)*@
  173. </section>