You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

237 lines
8.9 KiB

  1. window.onload = function() {
  2. httpBaseInfo();
  3. $('#div_body').removeClass('ui_hide');
  4. }
  5. function httpBaseInfo() {
  6. $.ajax({
  7. type: "post",
  8. url: $$.base_api + 'home/home/home-list',
  9. dataType: 'json',
  10. success: function(res_data) {
  11. $$.ZZLog(res_data);
  12. if(res_data.flag == false) {
  13. $$.alert(res_data.msg);
  14. } else {
  15. replaceBaseInfo(res_data.data);
  16. }
  17. },
  18. error: function() {
  19. alert($$.infoApiError);
  20. }
  21. });
  22. // var temp_lunbo = "";
  23. //轮播
  24. // for(var i = 0, j = 3; i < j; i++) {
  25. // // var str = data.recomList[i].toUrl;
  26. // temp_lunbo += '<div class="swiper-slide"><img to_url="https://m.simpletour.com/mobile/gateway/wechat/line/detail/2" style="width: 100%;" src="images/banner.png"; /></div>'
  27. // }
  28. // $(".swiper-wrapper").html(temp_lunbo);
  29. //轮播空间swiper
  30. // var swiper = new Swiper('.swiper-container', {
  31. // pagination: '.swiper-pagination',
  32. // loop: true,
  33. // paginationClickable: true,
  34. // centeredSlides: true,
  35. // autoplay: 2000,
  36. // autoplayDisableOnInteraction: false,
  37. // onTouchEnd: function(swiper) {
  38. // if(Math.abs(swiper.touches.currentX - swiper.touches.startX) < 3) {
  39. // location.href = $('.swiper-container img').eq(swiper.activeIndex).attr('to_url');
  40. // }
  41. // }
  42. // updateFormElements : true,//当内嵌图像加载完成之后 会重新初始化对象
  43. // followFinger: false
  44. // });
  45. // $("img.lazy-load").lazyload({
  46. // threshold: -120,
  47. // effect: "fadeIn"
  48. // }); 
  49. // $(".lazy-load").lazyload({
  50. // threshold: -70,
  51. // effect: "fadeIn"
  52. // })
  53. window.tabbar.init({ index: 0, }, function(n) {
  54. console.log(n);
  55. });
  56. }
  57. //替换数据
  58. function replaceBaseInfo(data) {
  59. //轮播
  60. var banner_list = data.banner_list;
  61. var temp_banner = '';
  62. banner_list.forEach(function(dict, index) {
  63. temp_banner += '<div class="swiper-slide"><img to_url="' + dict.toUrl + '" style="height:1.48rem" src="' + dict.img + '"; /></div>'
  64. });
  65. $(".swiper-wrapper").html(temp_banner);
  66. var swiper = new Swiper('.swiper-container', {
  67. pagination: '.swiper-pagination',
  68. loop: true,
  69. paginationClickable: true,
  70. centeredSlides: true,
  71. autoplay: 2000,
  72. autoplayDisableOnInteraction: false,
  73. onTouchEnd: function(swiper) {
  74. if(Math.abs(swiper.touches.currentX - swiper.touches.startX) < 3) {
  75. location.href = $('.swiper-container img').eq(swiper.activeIndex).attr('to_url');
  76. }
  77. }
  78. });
  79. //热门目的地
  80. var hot_area_list = data.hot_area;
  81. var temp_hot_area = '';
  82. hot_area_list.forEach(function(dict, index) {
  83. temp_hot_area += '<div class="ub-f1 tx-c hot_area" area_id=' + dict.area_id + '>' + dict.area_name + '</div>';
  84. })
  85. $('.hot_area_info').html(temp_hot_area);
  86. $('.hot_area').on('click', function() {
  87. var area_id = $(this).attr('area_id');
  88. $$.ZZLog(area_id);
  89. });
  90. //主分类
  91. $('.sigle_cms').on('click', function() {
  92. var cms_id = $(this).attr('cms_id');
  93. $$.ZZLog(cms_id);
  94. });
  95. //广告
  96. $('.ad').attr('data-original', data.ad.img);
  97. $('.ad').attr('to_url', data.ad.toUrl);
  98. $('.ad').on('click', function() {
  99. var to_url = $(this).attr('to_url');
  100. $$.ZZLog(to_url);
  101. });
  102. //猜你喜欢
  103. var like_list = data.like.like_list;
  104. var temp_like = '';
  105. like_list.forEach(function(dict, index) {
  106. // if (index == 1) {
  107. // dict.show_img = 'http://img.zhizhuchuxing.cn/wechat/ad1.jpg';
  108. // }else if(index == 2){
  109. // dict.show_img = 'http://h5.sztoda.cn/static/img/loveLetter/teacher/teacher4.jpg';
  110. // }else{
  111. // dict.show_img = 'http://h5.sztoda.cn/static/img/loveLetter/teacher/teacher3.jpg';
  112. // }
  113. var t_star = dict.star;
  114. var star = parseFloat(t_star).toFixed(1);
  115. var star_integer = parseInt(star);
  116. var star_flt = star - star_integer;
  117. //全星
  118. var star_o_s = '';
  119. for (var i = 0; i < star_integer; i++) {
  120. star_o_s+='<div class="ub-f1 star" style="width: 0.1rem;height: 0.1rem;background-image: url(images/home/staro.png);margin: 0.01rem;background-repeat:no-repeat;background-size:100% 100%"></div>';
  121. }
  122. //判断是否填充半星
  123. if (star_integer<5 && star_flt > 0) {
  124. star_o_s+='<div class="ub-f1 star" style="width: 0.1rem;height: 0.1rem;background-image: url(images/home/starh.png);margin: 0.01rem;background-repeat:no-repeat;background-size:100% 100%"></div>'
  125. }
  126. //判断是否还要填充空星
  127. var star_e = 5 - star;
  128. if(star_e >= 1){
  129. star_o_s += '<div class="ub-f1 star" style="width: 0.1rem;height: 0.1rem;background-image: url(images/home/stare.png);margin: 0.01rem;background-repeat:no-repeat;background-size:100% 100%"></div>'
  130. }
  131. // '<div class="ub-f1 star" style="width: 0.1rem;height: 0.1rem;background-image: url(images/home/stare.png);margin: 0.01rem;background-repeat:no-repeat;background-size:100% 100%"></div>' +
  132. // '<div class="ub-f1 star" style="width: 0.1rem;height: 0.1rem;background-image: url(images/home/stare.png);margin: 0.01rem;background-repeat:no-repeat;background-size:100% 100%"></div>' +
  133. // '<div class="ub-f1 star" style="width: 0.1rem;height: 0.1rem;background-image: url(images/home/stare.png);margin: 0.01rem;background-repeat:no-repeat;background-size:100% 100%"></div>' +
  134. // '<div class="ub-f1 star" style="width: 0.1rem;height: 0.1rem;background-image: url(images/home/stare.png);margin: 0.01rem;background-repeat:no-repeat;background-size:100% 100%"></div>' +
  135. // '<div class="ub-f1 star" style="width: 0.1rem;height: 0.1rem;background-image: url(images/home/stare.png);margin: 0.01rem;background-repeat:no-repeat;background-size:100% 100%"></div>' +
  136. temp_like += '<div style="background-color: #ffffff;margin-bottom: 0.05rem;" pro_cate_id=' + dict.pro_cate_id + '>' +
  137. '<div style="padding: 0.08rem;" class="ub">' +
  138. '<img class="lazy-load" src="images/home/productloading.png" data-original="' + dict.show_img + '" style="width: 1rem;height: 1rem;"/>' +
  139. '<div class="ub-f1 ub ub-ver" style="padding-left: 0.08rem;">' +
  140. '<div class="ulev1" style="color: #2d2e3a;">' + dict.pro_cate_name + '</div>' +
  141. '<div style="padding: 0.08rem 0;">' +
  142. '<span style="padding: 0.04rem 0.15rem;background-color: #e9ebee;border-radius: 0.5rem;color: #2d2e3a;">' + dict.category_name + '</span><span></span>' +
  143. '</div>' +
  144. '<div class="ub ub-ae ub-f1">' +
  145. '<div class="ub ub-ver">' +
  146. '<div class="ub">' +
  147. '<div class="ulev0" style="line-height: 1.0;color: #686872;">评分' + dict.star + '</div>' +
  148. '<div class="ub-f1 ub ub-ac star_ary" style="padding-left: 0.03rem;" star=' + dict.star + '>' +
  149. star_o_s +
  150. '</div>' +
  151. '</div>' +
  152. '<div style="color: #686872;">月销' + dict.sales_count + '单</div> ' +
  153. '</div>' +
  154. '<div class="ub-f1 tx-r ub ub-ver ub-ae">' +
  155. '<div class="ub ub-ae" style="line-height: 1;text-decoration: line-through;text-decoration-color:#96969c;color: #96969c;">原价' + dict.original_price + '元</div>' +
  156. '<div style="color: #686872;"><span class="ulev3" style=" color: #cc3333;">¥' + dict.show_price + '</span>起</div>' +
  157. '</div>' +
  158. '</div>' +
  159. '</div>' +
  160. '</div>' +
  161. '</div>';
  162. })
  163. $('.like_list').html(temp_like);
  164. // var t_star = $('.star_ary').attr('star');
  165. // var star = parseFloat(t_star).toFixed(1);
  166. // var star_integer = parseInt(star);
  167. // var star_flt = star - star_integer;
  168. // for(var i = 0; i < star_integer; i++) {
  169. // console.log($('.star_ary').children().eq(i).c);
  170. // $('.star_ary').children().eq(i).css('background-image', 'url(images/home/staro.png)');
  171. // }
  172. //精品推荐
  173. var recommon_list = data.recommon.recommon_list;
  174. var temp_recommon = '';
  175. var one = '';
  176. recommon_list.forEach(function(dict, index) {
  177. if(index % 2 == 0) {
  178. var left_html = getHtmlByDict(dict);
  179. one += '<div class="ub" style="margin-bottom: 0.05rem;">';
  180. one += left_html;
  181. one += '<div style="width: 0.05rem;"></div>';
  182. } else {
  183. var right_html = getHtmlByDict(dict);
  184. one += right_html;
  185. one += '</div>';
  186. temp_recommon += one;
  187. one = '';
  188. }
  189. });
  190. $('.recommon_info').html(temp_recommon);
  191. $(".lazy-load").lazyload({
  192. threshold: -70,
  193. effect: "fadeIn"
  194. })
  195. }
  196. function getHtmlByDict(dict) {
  197. if(dict.show_img == '') {
  198. dict.show_img = 'images/home/product02loading.png';
  199. }
  200. var html = '<div class="ub-f1 ub" style="background-color: #FFFFFF;width: 1%;" pro_cate_id=' + dict.pro_cate_id + '>' +
  201. '<div class="ub ub-ver ub-f1" style="padding: 0.08rem;">' +
  202. '<img class="lazy-load" src="images/home/product02loading.png" data-original=' + dict.show_img + ' style="width: 1.69rem;height: 0.9rem;" />' +
  203. '<div class="ulev1" style="padding-top: 0.08rem;overflow: hidden;text-overflow:ellipsis;white-space: nowrap;color: #2d2e3a;">' + dict.pro_cate_name + '</div>' +
  204. '<div class="ub ub-ae ub-f1 ui_p_t10">' +
  205. '<div style="color: #96969c;text-decoration: line-through;text-decoration-color:#96969c;">原价' + dict.original_price + '元</div>' +
  206. '<div class="ub-f1 tx-r" style="color: #686872;">' +
  207. '<span class="ulev3" style="color: #cc3333;">¥' + dict.show_price + '</span>起' +
  208. '</div>' +
  209. '</div>' +
  210. '</div>' +
  211. '</div>'
  212. return html;
  213. }
  214. //查询产品
  215. function goToSearch() {
  216. window.location.href = './prod_search.html';
  217. }