search_goods.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. $(function(){
  2. /* 筛选事件 */
  3. $('span[dstype="span_filter"]').click(function(){
  4. _i = $(this).find('i');
  5. location.assign($(this).find('i').attr('data-uri'));
  6. return false;
  7. });
  8. $("#search_by_price").click(function(){
  9. replaceParam('price', $(this).siblings("input:first").val() + '-' + $(this).siblings("input:last").val());
  10. return false;
  11. });
  12. // 筛选的下拉展开
  13. $(".select").hover(function () {
  14. $(this).addClass("over").next().css("display", "block");
  15. }, function () {
  16. $(this).removeClass("over").next().css("display", "none");
  17. });
  18. $(".option").hover(function () {
  19. $(this).css("display", "block");
  20. }, function () {
  21. $(this).css("display", "none");
  22. });
  23. $('.list_pic').find('dl').on('mouseout', function () {
  24. $(this).find('.slide-show').hide();
  25. });
  26. $('.slide_tiny').on('mouseover', function () {
  27. small_image = $(this).attr('dstype');
  28. $(this).parents('.slide-show').find('img:first').attr('src', small_image);
  29. });
  30. // 加入购物车
  31. $('a[dstype="add_cart"]').click(function() {
  32. var _parent = $(this).parent(), thisTop = _parent.offset().top, thisLeft = _parent.offset().left;
  33. animatenTop(thisTop, thisLeft), !1;
  34. eval('var data_str = ' + $(this).attr('data-param'));
  35. addcart(data_str.goods_id, 1, '');
  36. });
  37. // 立即购买
  38. $('a[dstype="buy_now"]').click(function(){
  39. eval('var data_str = ' + $(this).attr('data-param'));
  40. $("#goods_id").val(data_str.goods_id+'|1');
  41. $("#buynow_form").submit();
  42. });
  43. // 图片切换效果
  44. $('.goods-pic-scroll-show').find('a').mouseover(function(){
  45. $(this).parents('li:first').addClass('selected').siblings().removeClass('selected');
  46. var _src = $(this).find('img').attr('src');
  47. _src = _src.replace('_60.', '_240.');
  48. $(this).parents('.goods-content').find('.goods-pic').find('img').attr('src', _src);
  49. });
  50. // 品牌按首字母切换
  51. $('ul[dstype="ul_initial"] > li').mouseover(function(){
  52. $(this).addClass('current').siblings().removeClass('current');
  53. if ($(this).attr('data-initial') == 'all') {
  54. $('ul[dstype="ul_brand"] > li').show();
  55. return;
  56. }
  57. $('ul[dstype="ul_brand"] > li').hide();
  58. $('ul[dstype="ul_brand"] > li[data-initial="'+$(this).attr('data-initial')+'"]').show();
  59. });
  60. // 品牌显示筛选
  61. $('span[dstype="brand_show"]').click(
  62. function(){
  63. if(!$('ul[dstype="ul_initial"]').is(':visible')){
  64. $('ul[dstype="ul_initial"]').show();
  65. $('ul[dstype="ul_brand"] > li').show();
  66. $(this).html('<i class="iconfont">&#xe738;</i>收起');
  67. }else{
  68. $('ul[dstype="ul_initial"]').hide();
  69. $('ul[dstype="ul_brand"] > li:gt(13)').hide();
  70. $('ul[dstype="ul_brand"] > li:lt(14)').show();
  71. $(this).html('<i class="iconfont">&#xe73a;</i>更多');
  72. }
  73. }
  74. );
  75. });
  76. function animatenTop(thisTop, thisLeft) {
  77. var CopyDiv = '<div id="box" style="top:' + thisTop + "px;left:" + thisLeft + 'px" ></div>', topLength = $("#rtoolbar_cart").offset().top, leftLength = $("#rtoolbar_cart").offset().left;
  78. $("body").append(CopyDiv), $("body").children("#box").animate({
  79. "width": "0",
  80. "height": "0",
  81. "margin-top":"0",
  82. "top": topLength,
  83. "left": leftLength,
  84. "opacity": 0
  85. }, 1000, function() {
  86. $(this).remove();
  87. });
  88. }
  89. function setcookie(name,value){
  90. var Days = 30;
  91. var exp = new Date();
  92. exp.setTime(exp.getTime() + Days*24*60*60*1000);
  93. document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
  94. }
  95. /* 替换参数 */
  96. function replaceParam(key, value, arg)
  97. {
  98. if(!arguments[2]) arg = 'string';
  99. var params = PURL;
  100. var found = false;
  101. for (var i = 0; i < params.length; i++)
  102. {
  103. param = params[i];
  104. arr = param.split('=');
  105. pKey = arr[0];
  106. // 如果存在分页,跳转到第一页
  107. if (pKey == 'curpage')
  108. {
  109. params[i] = 'curpage=1';
  110. }
  111. if(arg == 'string'){
  112. if (pKey == key)
  113. {
  114. params[i] = key + '=' + value;
  115. found = true;
  116. }
  117. }else{
  118. for(var j = 0; j < key.length; j++){
  119. if(pKey == key[j]){
  120. params[i] = key[j] + '=' + value[j];
  121. found = true;
  122. }
  123. }
  124. }
  125. }
  126. if (!found)
  127. {
  128. if (arg == 'string'){
  129. value = transform_char(value);
  130. params.push(key + '=' + value);
  131. }else{
  132. for(var j = 0; j < key.length; j++){
  133. params.push(key[j] + '=' + transform_char(value[j]));
  134. }
  135. }
  136. }
  137. location.assign(SITEURL + '/index.php?' + params.join('&'));
  138. }
  139. /* 删除参数 */
  140. function dropParam(key, id, arg)
  141. {
  142. if(!arguments[2]) arg = 'string';
  143. var params = location.search.substr(1).split('&');
  144. for (var i = 0; i < params.length; i++)
  145. {
  146. param = params[i];
  147. arr = param.split('=');
  148. pKey = arr[0];
  149. if(arg == 'string'){
  150. if (pKey == key)
  151. {
  152. params.splice(i, 1);
  153. }
  154. }else if(arg == 'del'){
  155. pVal = arr[1].split(',');
  156. for (var j=0; j<pVal.length; j++){
  157. if(pKey == key && pVal[j] == id){
  158. pVal.splice(j, 1);
  159. params.splice(i, 1, pKey+'='+pVal);
  160. }
  161. }
  162. }else{
  163. for(var j = 0; j < key.length; j++){
  164. if(pKey == key[j]){
  165. params.splice(i, 1);i--;
  166. }
  167. }
  168. }
  169. }
  170. location.assign(SITEURL + '/index.php?' + params.join('&'));
  171. }