您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

299 行
12 KiB

  1. var search_info = "";
  2. var current_loc = null;
  3. var longitude = ''; //经度
  4. var latitude = ''; //纬度
  5. var street = getCookie('street') ? getCookie('street') : '';
  6. var point = getCookie('point') ? getCookie('point') : '';
  7. $(document).ready(function() {
  8. ifLogin(function(flag) {
  9. $("#show_html").show();
  10. var search_h = $("#search").height();
  11. var all_h = $(document).height() - 44;
  12. var list_h = all_h - search_h;
  13. $("#prod_list").height(list_h);
  14. $("#navbar-example").height(list_h);
  15. if(street == '') {
  16. get_list();
  17. getLocation();
  18. } else {
  19. $('#dingwei').text(street);
  20. $('#dingwei').show();
  21. get_list();
  22. // getLocation();
  23. }
  24. // get_list();
  25. // getLocation();
  26. $('#search_input').on('input', function(e) {
  27. var input_text = $("#search_input").val();
  28. if(input_text != "") {
  29. $(".search_r").show();
  30. $("#go_search").show();
  31. delay(function() {
  32. get_list();
  33. }, 1500);
  34. } else {
  35. $(".search_r").hide();
  36. $("#go_search").hide();
  37. get_list();
  38. }
  39. });
  40. $('#cancel').on('click', function() {
  41. $("#search_input").val("");
  42. $(".search_r").hide();
  43. $("#go_search").hide();
  44. get_list();
  45. });
  46. $('#go_search').on('click', function() {
  47. get_list();
  48. });
  49. });
  50. //滚动监听
  51. //滚动监听
  52. // $("#prod_list").scroll(function(){
  53. //var arr = [];
  54. //$(".prod_scroll").each(function(index,dom){
  55. // var top_h=$("#search").height();
  56. // var div_h = $(dom).offset().top;
  57. //
  58. // var t=top_h-div_h;
  59. // arr.push($(dom).attr('id'));
  60. // if(t>-1 && t<=30){
  61. // var this_id_name=$(dom).attr('id');
  62. // var t = $('a[href="#'+this_id_name+'"]');
  63. //
  64. // console.log(this_id_name);
  65. // console.log('%ccoding..........................................','font-size:20px;color:red;');
  66. // $('#left_menu li').removeClass('active');
  67. // $('a[href="#'+this_id_name+'"]').parent().addClass('active');
  68. // }
  69. // if(t>=-30 && t<1){
  70. // console.log('top_h',top_h,'-----------div_h',div_h,'tttttttttt=',t);
  71. // var i = index;
  72. // if(i>0){
  73. // i = i-1;
  74. // }else{
  75. // i=0;
  76. // }
  77. // $('#left_menu li').removeClass('active');
  78. // $('a[href="#'+arr[i]+'"]').parent().addClass('active');
  79. //
  80. // }
  81. //
  82. //});
  83. //});
  84. });
  85. function get_list() {
  86. search_info = $("#search_input").val();
  87. ZZLog(point);
  88. // point = '121.321586' + ',' + '31.203112';
  89. $.ajax({
  90. url: base_api + "prod/prod/get-prod-list", //请求地址
  91. data: { where: search_info, point: point },
  92. type: "post",
  93. dataType: "json",
  94. async: false,
  95. success: function(res_data) {
  96. console.log(res_data)
  97. if(res_data.flag) {
  98. list_html(res_data.data);
  99. $('#left_menu li:first').addClass('active');
  100. $('#prod_list').animate({
  101. scrollTop: 0
  102. },
  103. 200);
  104. } else {
  105. if(codeNotLogin == res_data['code']) {
  106. location.href = res_data['url'];
  107. } else if(codeNotRegister == res_data['code']) {
  108. location.href = 'register.html';
  109. } else {
  110. alert(res_data['msg']);
  111. }
  112. }
  113. },
  114. error: function(error) {
  115. console.log(error);
  116. }
  117. });
  118. }
  119. function list_html(data) {
  120. var left_temp = "";
  121. var right_temp = "";
  122. for(var i = 0, j = data.prod_list.length; i < j; i++) {
  123. if(data.prod_list[i].cms_category_id == 2) {
  124. left_temp += '<li><a class="ui_p_a10 ulev1 text_c_80 hot lightgreen_color" href="#prod' + i + data.prod_list[i].cms_category_id + '">' + data.prod_list[i].category_name + '</a></li>'
  125. } else {
  126. left_temp += '<li><a class="ui_p_a10 ulev1 text_c_80 lightgreen_color" href="#prod' + i + data.prod_list[i].cms_category_id + '">' + data.prod_list[i].category_name + '</a></li>'
  127. }
  128. var length = data.prod_list[i].recom_arr.length;
  129. if(length > 0) {
  130. for(var h = 0; h < length; h++) {
  131. // right_temp = '<div class="info">'
  132. if(h == 0) {
  133. right_temp += '<div style="font-weight: bold;padding-top:0.02rem;padding-bottom:0.02rem;" class="text_c_2b ui_p_l12 prod_scroll" name="prod' + i + data.prod_list[i].cms_category_id + '" id="prod' + i + data.prod_list[i].cms_category_id + '">' + data.prod_list[i].category_name + '(' + data.prod_list[i].recom_arr.length + ')' + '</div>' +
  134. '<div category_id="' + data.prod_list[i].prod_arr[h].category_id + '" pro_cate_id="' + data.prod_list[i].prod_arr[h].pro_cate_id + '" class="click_prod ub ui_p_a12 lightgreen_color list_sha">' +
  135. '<div style="background-image: url(' + data.prod_list[i].prod_arr[h].show_img + ');" class="zhanwei_pic ui_m_r10"></div>' +
  136. '<div class="ub ub-f1 ub-ver ui_p_r02"> ' +
  137. '<div class="text_c_2b" style="font-size:0.13rem">' + data.prod_list[i].prod_arr[h].pro_cate_name + '</div>' +
  138. '<div class="font_gray">' + data.prod_list[i].prod_arr[h].prod_des + '</div>' +
  139. '<div class="ub ub-f1 ub-pe">' +
  140. '<div class="ub ub-f1 font_sale ub-ae" style="display:none;">已售 ' + data.prod_list[i].prod_arr[h].sales_count + '</div>' +
  141. '<div class="ub ub-pe ub-ae text_c_669" style="line-height:0.9">¥<span class="text_c_669 ulev3" style="line-height:1">' + data.prod_list[i].prod_arr[h].show_price + '</span></div>' +
  142. '</div>' +
  143. '</div>' +
  144. '</div>'
  145. } else {
  146. right_temp += '<div category_id="' + data.prod_list[i].recom_arr[h].category_id + '" pro_cate_id="' + data.prod_list[i].recom_arr[h].pro_cate_id + '" class="click_prod ub ui_p_a12 lightgreen_color list_sha">' +
  147. '<div style="background-image: url(' + data.prod_list[i].recom_arr[h].show_img + ');" class="zhanwei_pic ui_m_r10"></div>' +
  148. '<div class="ub ub-f1 ub-ver ui_p_r02"> ' +
  149. '<div class="text_c_2b" style="font-size:0.13rem">' + data.prod_list[i].recom_arr[h].pro_cate_name + '</div>' +
  150. '<div class="font_gray">' + data.prod_list[i].recom_arr[h].prod_des + '</div>' +
  151. '<div class="ub ub-f1 ub-pe">' +
  152. '<div class="ub ub-f1 font_sale ub-ae" style="display:none;">已售 ' + data.prod_list[i].recom_arr[h].sales_count + '</div>' +
  153. '<div class="ub ub-pe ub-ae text_c_669" style="line-height:0.9">¥<span class="text_c_669 ulev3" style="line-height:1">' + data.prod_list[i].recom_arr[h].show_price + '</span></div>' +
  154. '</div>' +
  155. '</div>' +
  156. '</div>'
  157. }
  158. }
  159. right_temp += '<div class="ub ub-ac ub-pc ulev0" style="color:#2b3857;padding-top:0.07rem;padding-bottom:0.07rem;border-bottom:1px solid #e5e5e5;background-color:white" name=' + data.prod_list[i].category_name + ' onclick="seeMoreList(this,' + data.prod_list[i].prod_arr.length + ',' + data.prod_list[i].recom_arr.length + ',' + i + ',' + data.prod_list[i].cms_category_id + ')">点击查看全部<img src="images/xiala.png" style="width: 0.13rem;height: 0.08rem;margin-left:0.05rem;" /></div>'
  160. right_temp += '<div class="more" style="display:none">';
  161. for(var h = 0, k = data.prod_list[i].prod_arr.length; h < k; h++) {
  162. right_temp += '<div category_id="' + data.prod_list[i].prod_arr[h].category_id + '" pro_cate_id="' + data.prod_list[i].prod_arr[h].pro_cate_id + '" class="click_prod ub ui_p_a12 lightgreen_color list_sha">' +
  163. '<div style="background-image: url(' + data.prod_list[i].prod_arr[h].show_img + ');" class="zhanwei_pic ui_m_r10"></div>' +
  164. '<div class="ub ub-f1 ub-ver ui_p_r02"> ' +
  165. '<div class="text_c_2b" style="font-size:0.13rem">' + data.prod_list[i].prod_arr[h].pro_cate_name + '</div>' +
  166. '<div class="font_gray">' + data.prod_list[i].prod_arr[h].prod_des + '</div>' +
  167. '<div class="ub ub-f1 ub-pe">' +
  168. '<div class="ub ub-f1 font_sale ub-ae" style="display:none;">已售 ' + data.prod_list[i].prod_arr[h].sales_count + '</div>' +
  169. '<div class="ub ub-pe ub-ae text_c_669" style="line-height:0.9">¥<span class="text_c_669 ulev3" style="line-height:1">' + data.prod_list[i].prod_arr[h].show_price + '</span></div>' +
  170. '</div>' +
  171. '</div>' +
  172. '</div>'
  173. }
  174. right_temp += '</div>';
  175. // right_temp += '</div>';
  176. } else {
  177. for(var h = 0, k = data.prod_list[i].prod_arr.length; h < k; h++) {
  178. if(h == 0) {
  179. right_temp += '<div style="font-weight: bold;padding-top:0.02rem;padding-bottom:0.02rem;" class="text_c_2b ui_p_l12 prod_scroll" name="prod' + i + data.prod_list[i].cms_category_id + '" id="prod' + i + data.prod_list[i].cms_category_id + '">' + data.prod_list[i].category_name + '(' + data.prod_list[i].prod_arr.length + ')' + '</div>' +
  180. '<div category_id="' + data.prod_list[i].prod_arr[h].category_id + '" pro_cate_id="' + data.prod_list[i].prod_arr[h].pro_cate_id + '" class="click_prod ub ui_p_a12 lightgreen_color list_sha">' +
  181. '<div style="background-image: url(' + data.prod_list[i].prod_arr[h].show_img + ');" class="zhanwei_pic ui_m_r10"></div>' +
  182. '<div class="ub ub-f1 ub-ver ui_p_r02"> ' +
  183. '<div class="text_c_2b" style="font-size:0.13rem">' + data.prod_list[i].prod_arr[h].pro_cate_name + '</div>' +
  184. '<div class="font_gray">' + data.prod_list[i].prod_arr[h].prod_des + '</div>' +
  185. '<div class="ub ub-f1 ub-pe">' +
  186. '<div class="ub ub-f1 font_sale ub-ae" style="display:none;">已售 ' + data.prod_list[i].prod_arr[h].sales_count + '</div>' +
  187. '<div class="ub ub-pe ub-ae text_c_669" style="line-height:0.9">¥<span class="text_c_669 ulev3" style="line-height:1">' + data.prod_list[i].prod_arr[h].show_price + '</span></div>' +
  188. '</div>' +
  189. '</div>' +
  190. '</div>'
  191. } else {
  192. right_temp += '<div category_id="' + data.prod_list[i].prod_arr[h].category_id + '" pro_cate_id="' + data.prod_list[i].prod_arr[h].pro_cate_id + '" class="click_prod ub ui_p_a12 lightgreen_color list_sha">' +
  193. '<div style="background-image: url(' + data.prod_list[i].prod_arr[h].show_img + ');" class="zhanwei_pic ui_m_r10"></div>' +
  194. '<div class="ub ub-f1 ub-ver ui_p_r02"> ' +
  195. '<div class="text_c_2b" style="font-size:0.13rem">' + data.prod_list[i].prod_arr[h].pro_cate_name + '</div>' +
  196. '<div class="font_gray">' + data.prod_list[i].prod_arr[h].prod_des + '</div>' +
  197. '<div class="ub ub-f1 ub-pe">' +
  198. '<div class="ub ub-f1 font_sale ub-ae" style="display:none;">已售 ' + data.prod_list[i].prod_arr[h].sales_count + '</div>' +
  199. '<div class="ub ub-pe ub-ae text_c_669" style="line-height:0.9">¥<span class="text_c_669 ulev3" style="line-height:1">' + data.prod_list[i].prod_arr[h].show_price + '</span></div>' +
  200. '</div>' +
  201. '</div>' +
  202. '</div>'
  203. }
  204. }
  205. }
  206. }
  207. // right_temp += '</div>';
  208. $("#left_menu").html(left_temp);
  209. $("#prod_list").html(right_temp);
  210. if(data.prod_list.length == 0) {
  211. $('#no_info').show();
  212. $('#prod_list').hide();
  213. } else {
  214. $('#no_info').hide();
  215. $('#prod_list').show();
  216. }
  217. $("#left_menu li").on("click", function() {
  218. $("#left_menu li").removeClass("active");
  219. $(this).addClass("active");
  220. });
  221. $(".click_prod").on("click", function() {
  222. var category_id = $(this).attr("category_id");
  223. var pro_cate_id = $(this).attr("pro_cate_id");
  224. setStorage("category_id", category_id);
  225. setStorage("pro_cate_id", pro_cate_id);
  226. if(category_id == "1") {
  227. window.location.href = "landmark_ticket.html?"+version;
  228. } else if(category_id == '1000') {
  229. window.location.href = 'station_ticket.html?'+version;
  230. } else {
  231. window.location.href = "scene_ticket.html?"+version;
  232. }
  233. });
  234. }
  235. $('#refresh').on('click', function() {
  236. getLocation();
  237. })
  238. //定位
  239. function getLocation() {
  240. $('#dingwei').text('正在定位……');
  241. current_loc = new BMap.Geolocation();
  242. var geoc = new BMap.Geocoder();
  243. current_loc.getCurrentPosition(function(r) {
  244. if(this.getStatus() == BMAP_STATUS_SUCCESS) {
  245. var temp_street = '';
  246. if(r.accuracy == null) {
  247. //用户决绝地理位置授权
  248. alert('用户拒绝地理位置授权');
  249. $('#dingwei').text('无法获取定位');
  250. $('.dingwei').hide();
  251. } else {
  252. longitude = r.longitude;
  253. latitude = r.latitude;
  254. point = longitude + ',' + latitude;
  255. geoc.getLocation(r.point, function(rs) {
  256. var addComp = rs.addressComponents;
  257. $('#dingwei').text(addComp.district + ' ' + addComp.street);
  258. temp_street = addComp.district + ' ' + addComp.street;
  259. $('.dingwei').show();
  260. setCookie('point', point, 'h4');
  261. setCookie('street', temp_street, 'd30');
  262. if(street != temp_street) {
  263. get_list();
  264. }
  265. });
  266. }
  267. }
  268. })
  269. }
  270. //查看更多
  271. function seeMoreList(obj, count1, count2, index, id) {
  272. $(obj).hide();
  273. $(obj).next().show();
  274. var name = $(obj).attr('name');
  275. var total = count1 + count2;
  276. $('#prod' + index + '' + id).text(name + '(' + total + ')');
  277. }