diy.layer.js 4.8 KB

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