edit.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. (function () {
  2. var page = {
  3. isScroll: true,
  4. init: function ($page) {
  5. var _html = '<div id="lr_modulelist_finish" >完成</div>';
  6. $page.parent().find('.f-page-backbtn').html("取消");
  7. $page.parent().find('.f-page-header').addClass('lr-modulelistedit-header').append(_html);
  8. renlian.clientdata.get('module', {
  9. callback: function (data) {
  10. var map = {};
  11. var TypeMap = {};
  12. $.each(data, function (_index, _item) {
  13. map[_item.F_Id] = _item;
  14. TypeMap[_item.F_Type] = TypeMap[_item.F_Type] || [];
  15. TypeMap[_item.F_Type].push(_item);
  16. });
  17. // 加载我的应用
  18. renlian.myModule.get(data, function (myModules) {
  19. var $appbox = $page.find('#lr_modulelist_edit_mymodule');
  20. var myMap = {};
  21. $.each(myModules, function (_index, _id) {
  22. var item = map[_id];
  23. if (item) {
  24. var _html = '\
  25. <div class="appitem myappitem" data-value="'+ item.F_Id + '">\
  26. <div><i class="'+ item.F_Icon + '"></i></div>\
  27. <span>'+ item.F_Name + '</span>\
  28. <div class="operation minus">-</div>\
  29. </div>';
  30. var _$html = $(_html);
  31. _$html[0].item = item;
  32. $appbox.append(_$html);
  33. myMap[_id] = "1";
  34. }
  35. });
  36. // 加载全部应用
  37. var $app = $page.find('.lr-modulelist-page');
  38. $.each(TypeMap, function (_type, _modules) {
  39. var _html = '\
  40. <div class="lr-app-panel" data-app="'+ _type + '">\
  41. <div class="title" ></div>\
  42. <div class="content"></div>\
  43. </div>';
  44. $app.append(_html);
  45. var $content = $app.find('[data-app="' + _type + '"] .content');
  46. renlian.clientdata.get('dataItem', {
  47. code: 'function',
  48. key: _type,
  49. callback: function (data, op) {
  50. $app.find('[data-app="' + op.key + '"] .title').text(data.text);
  51. }
  52. });
  53. $.each(_modules, function (_index, _item) {
  54. var __html = '\
  55. <div class="appitem" data-value="'+ _item.F_Id + '">\
  56. <div><i class="'+ _item.F_Icon + '"></i></div>\
  57. <span>'+ _item.F_Name + '</span>' + (myMap[_item.F_Id] ? ' <div class="operation minus">-</div>' :' <div class="operation plus">+</div>') +'\
  58. </div>';
  59. var __$html = $(__html);
  60. __$html[0].item = _item;
  61. $content.append(__$html);
  62. });
  63. });
  64. });
  65. }
  66. });
  67. $page.delegate('.appitem', 'tap', function () {
  68. var $this = $(this);
  69. var Id = $this.attr('data-value');
  70. if ($this.hasClass('myappitem')) {
  71. $this.remove();
  72. $page.find('[data-value="' + Id + '"] .operation').removeClass('minus').addClass('plus').text('+');
  73. }
  74. else {
  75. if ($this.find('.operation').hasClass('minus')) {// 去掉我的应用
  76. $this.find('.operation').removeClass('minus').addClass('plus').text('+');
  77. $page.find('#lr_modulelist_edit_mymodule .appitem[data-value="' + Id + '"]').remove();
  78. }
  79. else {// 添加我的应用
  80. var len = $page.find('#lr_modulelist_edit_mymodule .appitem').length;
  81. if (len >= 11) {
  82. renlian.layer.toast('最多添加11个应用');
  83. }
  84. else {
  85. $this.find('.operation').removeClass('plus').addClass('minus').text('-');
  86. var _html = '<div class="appitem myappitem" data-value="' + Id + '">' + $this.html() + '</div>';
  87. $page.find('#lr_modulelist_edit_mymodule').append(_html);
  88. }
  89. }
  90. }
  91. });
  92. // 注册完成按钮
  93. $page.parent().find('#lr_modulelist_finish').on('tap', function () {
  94. var list = [];
  95. $page.find('#lr_modulelist_edit_mymodule .appitem').each(function () {
  96. var id = $(this).attr('data-value');
  97. list.push(id);
  98. });
  99. renlian.storage.set("mymoduleData", list);
  100. renlian.httppost(config.webapi + "renlian/adms/function/mylist/update", String(list), (res) => {
  101. });
  102. renlian.nav.closeCurrent();
  103. });
  104. }
  105. };
  106. return page;
  107. })();