mobile.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. define(['core', 'tpl'], function (core, tpl) {
  2. var modal = {location: {lat: '0', lng: '0'}};
  3. modal.init = function (params) {
  4. modal.initNotice();
  5. modal.initSwiper();
  6. modal.initLocation();
  7. modal.initAudio();
  8. $("form").submit(function () {
  9. $(this).find("input[name='keywords']").blur();
  10. });
  11. };
  12. modal.initNotice = function () {
  13. if ($(".fui-notice").length > 0) {
  14. $(".fui-notice").each(function () {
  15. var _this = $(this);
  16. var speed = _this.data('speed') * 1000;
  17. setInterval(function () {
  18. var length = _this.find("li").length;
  19. if (length > 1) {
  20. _this.find("ul").animate({marginTop: "-1rem"}, 500, function () {
  21. $(this).css({marginTop: "0px"}).find("li:first").appendTo(this)
  22. })
  23. }
  24. }, speed)
  25. })
  26. }
  27. };
  28. modal.initSwiper = function () {
  29. if($('[data-toggle="timer"]').length>0){
  30. require(['../addons/ewei_shopv2/plugin/seckill/static/js/timer.js'],function(timerUtil){
  31. timerUtil.initTimers();
  32. });
  33. }
  34. if ($(".swiper").length > 0) {
  35. require(['swiper'], function (modal) {
  36. $(".swiper").each(function () {
  37. var obj = $(this);
  38. var ele = $(this).data('element');
  39. var container = ele + " .swiper-container";
  40. var view = $(this).data('view');
  41. var btn = $(this).data('btn');
  42. var free = $(this).data('free');
  43. var space = $(this).data('space');
  44. var callback = $(this).data('callback');
  45. var slideTo = $(this).data('slideto');
  46. var options = {
  47. pagination: container + ' .swiper-pagination',
  48. slidesPerView: view,
  49. paginationClickable: true,
  50. autoHeight: true,
  51. nextButton: container + ' .swiper-button-next',
  52. prevButton: container + ' .swiper-button-prev',
  53. spaceBetween: space > 0 ? space : 0,
  54. //preventClicks : false,
  55. preventLinksPropagation : true,
  56. onSlideChangeEnd: function (swiper) {
  57. if (swiper.isEnd && callback) {
  58. if (callback == 'seckill') {
  59. location.href = core.getUrl('seckill');
  60. }
  61. }
  62. }
  63. };
  64. if (!btn) {
  65. delete options.nextButton;
  66. delete options.prevButton;
  67. $(container).find(".swiper-button-next").remove();
  68. $(container).find(".swiper-button-prev").remove()
  69. }
  70. if (free) {
  71. options.freeMode = true
  72. }
  73. var swiper = new Swiper(container, options);
  74. if(slideTo){
  75. swiper.slideTo(slideTo, 0, false);
  76. }
  77. });
  78. })
  79. }
  80. };
  81. modal.initLocation = function () {
  82. if ($(".merchgroup[data-openlocation='1']").length > 0) {
  83. var geoLocation = new BMap.Geolocation();
  84. window.modal = modal;
  85. geoLocation.getCurrentPosition(function (result) {
  86. if (this.getStatus() == BMAP_STATUS_SUCCESS) {
  87. modal.location.lat = result.point.lat;
  88. modal.location.lng = result.point.lng;
  89. modal.initMerch()
  90. } else {
  91. FoxUI.toast.show("位置获取失败!");
  92. return
  93. }
  94. }, {enableHighAccuracy: true})
  95. }
  96. };
  97. modal.initMerch = function () {
  98. $(".merchgroup").each(function () {
  99. var _this = $(this);
  100. var item = _this.data('itemdata');
  101. if (!item || !item.params.openlocation) {
  102. return
  103. }
  104. core.json('diypage/getmerch', {
  105. lat: modal.location.lat,
  106. lng: modal.location.lng,
  107. item: item
  108. }, function (result) {
  109. if (result.status == 1) {
  110. var list = result.result.list;
  111. if (list) {
  112. _this.empty();
  113. $.each(list, function (id, merch) {
  114. var thumb = merch.thumb ? merch.thumb : '../addons/ewei_shopv2/plugin/diypage/static/images/default/logo.jpg';
  115. var html = '';
  116. html = '<div class="fui-list jump">';
  117. html += '<a class="fui-list-media" href="' + core.getUrl("merch", {merchid: merch.id}) + '" data-nocache="true"><img src="' + thumb + '"/></a>';
  118. html += '<a class="fui-list-inner" href="' + core.getUrl("merch", {merchid: merch.id}) + '" data-nocache="true">';
  119. html += '<div class="title" style="color: ' + item.style.titlecolor + ';">' + merch.name + '</div>';
  120. if (merch.desc) {
  121. html += '<div class="subtitle" style="color: ' + item.style.textcolor + ';">' + merch.desc + '</div>'
  122. }
  123. if (merch.distance && item.params.openlocation) {
  124. html += '<div class="subtitle" style="color: ' + item.style.rangecolor + '; font-size: 0.6rem"><i class="icon icon-dingwei1" style="color: ' + item.style.rangecolor + '; font-size: 0.6rem;"></i>距离您: ' + merch.distance + 'km</div>'
  125. }
  126. html += '</a>';
  127. html += '<a class="fui-remark jump" style="padding-right: 0.2rem; height: 2rem; width: 2rem; text-align: center; line-height: 2rem;" href="' + core.getUrl("merch/map", {merchid: merch.id}) + '" data-nocache="true">';
  128. html += '</a>';
  129. html += '</div>';
  130. _this.append(html)
  131. });
  132. _this.show()
  133. }
  134. }
  135. }, true, true)
  136. })
  137. };
  138. modal.initAudio = function () {
  139. if ($(".play-audio").length > 0) {
  140. $(".play-audio").each(function () {
  141. var _this = $(this);
  142. var autoplay = _this.data('autoplay');
  143. var audio = _this.find("audio")[0];
  144. var duration = audio.duration;
  145. if(!isNaN(duration)){
  146. var time = modal.formatSeconds(duration);
  147. _this.find(".time").text(time).show();
  148. }
  149. if (autoplay) {
  150. //modal.playAudio(_this)
  151. }
  152. $(_this).click(function () {
  153. if (!audio.paused) {
  154. modal.stopAudio(_this)
  155. } else {
  156. modal.playAudio(_this)
  157. }
  158. })
  159. })
  160. }
  161. };
  162. modal.playAudio = function (_this) {
  163. _this.siblings().find("audio").each(function () {
  164. var __this = $(this).closest(".play-audio");
  165. modal.stopAudio(__this)
  166. });
  167. var audio = _this.find("audio")[0];
  168. var duration = audio.duration;
  169. if(!isNaN(duration)){
  170. var time = modal.formatSeconds(duration);
  171. _this.find(".time").text(time).show();
  172. }
  173. audio.play();
  174. _this.find(".horn").addClass('playing');
  175. if (audio.paused) {
  176. _this.find(".speed").css({width: '0px'})
  177. }
  178. var timer = setInterval(function () {
  179. var currentTime = audio.currentTime;
  180. if (currentTime >= duration) {
  181. modal.stopAudio(_this);
  182. clearInterval(timer)
  183. }
  184. var _thiswidth = _this.outerWidth();
  185. var _width = (currentTime / duration) * _thiswidth;
  186. _this.find(".speed").css({width: _width + 'px'})
  187. }, 1000)
  188. };
  189. modal.stopAudio = function (_this) {
  190. var audio = _this.find("audio")[0];
  191. if (audio) {
  192. var stop = _this.data('pausestop');
  193. if (stop) {
  194. audio.currentTime = 0
  195. }
  196. audio.pause();
  197. _this.find(".horn").removeClass('playing')
  198. }
  199. };
  200. modal.formatSeconds = function (value) {
  201. var theTime = parseInt(value);
  202. var theTime1 = 0;
  203. var theTime2 = 0;
  204. if (theTime > 60) {
  205. theTime1 = parseInt(theTime / 60);
  206. theTime = parseInt(theTime % 60);
  207. if (theTime1 > 60) {
  208. theTime2 = parseInt(theTime1 / 60);
  209. theTime1 = parseInt(theTime1 % 60)
  210. }
  211. }
  212. var result = "" + parseInt(theTime) + "''";
  213. result = "" + parseInt(theTime1) + "'" + result;
  214. if (theTime2 > 0) {
  215. result = "" + parseInt(theTime2) + "'" + result
  216. }
  217. return result
  218. };
  219. return modal
  220. });