diy.gotop.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. define(['jquery.ui'], function (ui) {
  2. var modal = {};
  3. modal.init = function (params) {
  4. window.tpl = params.tpl;
  5. modal.attachurl = params.attachurl;
  6. modal.gotop = params.gotop;
  7. modal.merch = params.merch;
  8. if (!modal.gotop) {
  9. modal.gotop = {
  10. params: {
  11. 'isopen': '0',
  12. 'gotoptype': '0',
  13. 'gotopclick': '0',
  14. 'imgurl': '../addons/ewei_shopv2/plugin/diypage/static/images/gotop.png',
  15. 'linkurl': '',
  16. 'iconposition': 'right bottom',
  17. 'iconclass': 'icon-top1',
  18. 'gotopheight': '300'
  19. },
  20. style: {
  21. 'iconcolor': '#ffffff',
  22. 'background': '#000000',
  23. 'opacity': '0.5',
  24. 'width': '30',
  25. 'top': '20',
  26. 'left': '10'
  27. }
  28. }
  29. }
  30. tpl.helper("imgsrc", function (src) {
  31. if (typeof src != 'string') {
  32. return ''
  33. }
  34. if (src.indexOf('http://') == 0 || src.indexOf('https://') == 0 || src.indexOf('../addons') == 0) {
  35. return src
  36. } else if (src.indexOf('images/') == 0) {
  37. return modal.attachurl + src
  38. }
  39. });
  40. modal.initItems();
  41. modal.initEditor();
  42. $(".btn-save").unbind('click').click(function () {
  43. var status = $(this).data('status');
  44. if (status) {
  45. tip.msgbox.err("正在保存,请稍候。。。");
  46. return
  47. }
  48. modal.save()
  49. })
  50. };
  51. modal.initItems = function () {
  52. var gotop = modal.gotop;
  53. gotop.merch = modal.merch;
  54. var html = tpl("tpl_show_gotop", modal.gotop);
  55. $("#phone").html(html).show()
  56. };
  57. modal.initEditor = function () {
  58. var html = tpl("tpl_edit_gotop", modal.gotop);
  59. $("#diy-editor .inner").html(html);
  60. $("#diy-editor .slider").each(function () {
  61. var decimal = $(this).data('decimal');
  62. var multiply = $(this).data('multiply');
  63. var defaultValue = $(this).data("value");
  64. if (decimal) {
  65. defaultValue = defaultValue * decimal
  66. }
  67. $(this).slider({
  68. slide: function (event, ui) {
  69. var sliderValue = ui.value;
  70. if (decimal) {
  71. sliderValue = sliderValue / decimal
  72. }
  73. $(this).siblings(".input").val(sliderValue).trigger("propertychange");
  74. $(this).siblings(".count").find("span").text(sliderValue)
  75. }, value: defaultValue, min: $(this).data("min"), max: $(this).data("max")
  76. })
  77. });
  78. $("#diy-editor").find(".diy-bind").bind('input propertychange change', function () {
  79. var _this = $(this);
  80. var bind = _this.data("bind");
  81. var bindchild = _this.data('bind-child');
  82. var bindparent = _this.data('bind-parent');
  83. var bindthree = _this.data('bind-three');
  84. var initEditor = _this.data('bind-init');
  85. var value = '';
  86. var tag = this.tagName;
  87. if (tag == 'INPUT') {
  88. var placeholder = _this.data('placeholder');
  89. value = _this.val();
  90. value = value == '' ? placeholder : value
  91. } else if (tag == 'SELECT') {
  92. value = _this.find('option:selected').val()
  93. } else if (tag == 'TEXTAREA') {
  94. value = _this.val()
  95. }
  96. value = $.trim(value);
  97. if (bindchild) {
  98. if (bindparent) {
  99. if (bindthree) {
  100. modal.gotop[bindchild][bindparent].child[bindthree][bind] = value
  101. } else {
  102. modal.gotop[bindchild][bindparent][bind] = value
  103. }
  104. } else {
  105. modal.gotop[bindchild][bind] = value
  106. }
  107. } else {
  108. modal.gotop[bind] = value
  109. }
  110. modal.initItems();
  111. if (initEditor) {
  112. modal.initEditor()
  113. }
  114. });
  115. $("#phone").mouseenter(function () {
  116. $("#diy-editor").find('.diy-bind').blur()
  117. });
  118. $("#diy-editor").show()
  119. };
  120. modal.save = function () {
  121. if (!modal.gotop) {
  122. tip.msgbox.err("数据错误,请刷新页面重试!");
  123. return
  124. }
  125. $(".btn-save").data('status', 1).text("保存中...");
  126. var posturl = biz.url("diypage/shop/gotop", null, modal.merch);
  127. $.post(posturl, {data: modal.gotop}, function (ret) {
  128. if (ret.status == 0) {
  129. tip.msgbox.err(ret.result.message);
  130. $(".btn-save").text("保存并设置").data("status", 0);
  131. return
  132. }
  133. tip.msgbox.suc("操作成功!");
  134. $(".btn-save").text("保存并设置").data("status", 0)
  135. }, 'json')
  136. };
  137. return modal
  138. });