diy.followbar.js 5.4 KB

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