var site = 'http://'+location.hostname+'/'; if(location.hostname=='www.mecan.net') site = 'https://www.mecan.net/yunpeijian/'; $(function () { /** 云配件产品格子展示 */ $("#ypj .pls li").each(function () { $(this).hover(function () { $(this).children(".pop").show(); $(this).children(".pop").children(".btn").show(); }, function () { if ($(this).find(".close").length > 0) { car2($(this).find(".close")); } else { car2($(this)); } $(this).children(".pop").hide(); $(this).children(".pop").children(".btn").hide(); }) }); //产品详细图片 $(".pro .img a").each(function (index, element) { $(this).click(function () { var img = $(this).children("img"); var pimg = $(this).parents(".img"); $(".pro .img a").removeclass("sel"); $(this).addclass("sel"); var url = img.attr("data_url"); urlarr = url.split(','); var photo_id = urlarr[0]; url = urlarr[1]; var pid=urlarr[2]; //$('#a1').attr('href', 'pro.php?act=big_photo&photo_id='+photo_id+'&pid='+pid); //$('#a1').attr('href', 'javascript:;'); pimg.find(".bimg").attr("src", url); pimg.find(".bimg").attr("data_url", photo_id+',1'); // $('#a1').css('background-image',"url("+url+")"); alert(psi.children(".i").children("img").attr("src")); }) }); //选择产品属性 $(".prosel a").each(function (index, element) { $(this).click(function () { $(this).parent("p").children("a").removeclass("sel"); $(this).addclass("sel"); }) }); //选择购物车 $(".selcarli .selcarval").click(function () { }) //取消加入购物车 $(".shopcar .close").click(function () { $(".shopcar,.box").fadeout(); }) $(".xunjiabox .close").click(function () { $(".xunjiabox,.box").fadeout(); }) /** 添加至购物清单 */ $(".saveshoplist").each(function () { var url = window.location.pathname; url=url.split('/'); var urlname = url[1]; if(location.hostname=='www.mecan.net') urlname = url[2]; var pid = ''; var ppid=''; var priceid=''; $(this).click(function () { if (urlname == 'product') { addshopcar(); } else { car1($(this)); } ppid = $(this).attr('name').split('_'); pid=ppid[0]; priceid=ppid[1]; if ($('.lbtn').html() == '保存') { $('.lbtn').click(function () { var list_id = $('input:radio[name=list_id' + pid + ']:checked').val(); var list_name = $('input[name=list_name' + pid + ']').val(); if((list_id==0 || list_id=='') && list_name=='' ){alert("请输入清单的名单");exit;} $.ajax({ type: 'post', url: site+'shopcar.php', cache: 'false', data: 'pid=' + pid +'&priceid='+ priceid + '&list_id=' + list_id + '&list_name=' + list_name+'&num=1', success: function (data) { if (urlname == 'product') { $(".shopcar,.box").hide(); } else { $(".shopcar").hide(); } window.location.reload(); } }) }) } else { $.ajax({ type: 'post', url: site+'shopcar.php', cache: 'false', data: 'pid=' + pid + '&priceid='+ priceid + '&num=1', success: function (data) { // flag=1; // alert(flag); //window.location.reload(); } }) } }) }); $(".pop .shopcar .close").each(function (index, element) { $(this).click(function () { car2($(this)); }) }); $(".addnewcar .seladd").each(function (index, element) { var tt = $(this); var pp = $(this).parent(); var inp = $(this).next(); tt.change(function () { if (pp.find("input:checked").length > 0) { inp.focus(); } }) inp.focus(function () { tt.attr("checked", true); }) }) //添加产品数量 $(".pronum").each(function (index, element) { var add = $(this).children(".add"); var less = $(this).children(".less"); var inp = $(this).children("input[name=num" + index + "]"); var price = $(this).children("input[name=price" + index + "]").val(); var priceid = $(this).children("input[name=priceid" + index + "]").val(); var oldnum = $(this).children("input[name=oldnum" + index + "]"); var total = $(this).children("input[name=total]"); var sum = 0; var oldnum1; var total1; var i = 0; var list_id = $(this).children("input[name=l_id]").val(); var pid = $(this).children("input[name=pid" + index + "]").val(); inp.keydown(function (e) { var curkey = e.which; if (curkey == 13) { inp.click(); return false; } }); add.click(function () { var num = parseint(inp.val()); inp.val(num + 1); total1 = $(".pronum").children("input[name=total]").val(); sum = parseint(total1) + price * 1; $(".pronum").children("input[name=oldnum" + index + "]").val(num + 1); //alert($(".pronum").children("input[name=oldnum]").val()); $(".pronum").children("input[name=total]").val(sum); $('#tprice').html(sum); //i=1; // alert(priceid); snum = $(".pronum").children("input[name=oldnum" + index + "]").val(); $.ajax({ type: 'post', url: site+'shopcar.php', cache: 'false', data: 'pid=' + pid + '&list_id=' + list_id + '&num=' + snum + '&priceid=' + priceid, success: function (data) { //i=0; //window.location.reload(); } }) }) less.click(function () { var num = parseint(inp.val()); if (num == 0) { inp.val(0) } else { inp.val(num - 1); total1 = $(".pronum").children("input[name=total]").val(); sum = parseint(total1) - price * 1; $(".pronum").children("input[name=oldnum" + index + "]").val(num - 1); $('#tprice').html(sum); $(".pronum").children("input[name=total]").val(sum); snum = $(".pronum").children("input[name=oldnum" + index + "]").val(); $.ajax({ type: 'post', url: site+'shopcar.php', cache: 'false', data: 'pid=' + pid + '&list_id=' + list_id + '&num=' + snum + '&priceid=' + priceid, success: function (data) { //i=0; //window.location.reload(); } }) } }) inp.change(function () { var num = parseint(inp.val()); if (num >= 0) { oldnum1 = $(".pronum").children("input[name=oldnum" + index + "]").val(); total1 = $(".pronum").children("input[name=total]").val(); sum = parseint(total1) - price * oldnum1 + price * num; $(".pronum").children("input[name=oldnum" + index + "]").val(num); $('#tprice').html(sum); $(".pronum").children("input[name=total]").val(sum); snum = $(".pronum").children("input[name=oldnum" + index + "]").val(); $.ajax({ type: 'post', url: site+'shopcar.php', cache: 'false', data: 'pid=' + pid + '&list_id=' + list_id + '&num=' + snum + '&priceid=' + priceid, success: function (data) { //i=0; //window.location.reload(); } }) } else { alert("数量必须大于等于0"); oldnum1 = $(".pronum").children("input[name=oldnum" + index + "]").val(); $(".pronum").children("input[name=num" + index + "]").val(oldnum1); } }) }) }) function car1(t) { var pp = t.parents(".pop"); var car = t.parent().next(); var lnk = pp.children(".lnk"); var btn = t.parent(".btn"); if (car.find(".bt").length > 0) { lnk.css("height", "198px"); } else { lnk.css("height", "265px"); } car.show(); btn.hide(); } function car2(t) { if (t.find(".shopcar").length > 0) { var car = t.find(".shopcar"); var pp = car.parent(".pop"); var lnk = pp.children(".lnk"); var btn = car.prev(); } else { var car = t.parents(".shopcar"); var pp = car.parent(".pop"); var lnk = pp.children(".lnk"); var btn = car.prev(); } $(".shopcar").hide(); lnk.css("height", "320px"); btn.show(); } //加入购物车 function addshopcar() { $(".shopcar,.box").fadein(); } //询价 function xunjia(id,uid,priceid,content_status){ $("#pid").val(id); $("#priceid").val(priceid); if(uid==0){ login1('2'); //登录 $("#loginform").submit(function(){ $(this).ajaxsubmit(function(data){//data是php执行后反馈的值 if(data==2){ window.location.reload(); //$("#loginbox").fadeout(); // $(".xunjiabox,.box").fadein(); } else if(data=='failed'){ alert('手机或密码不正确!'); } }) return false;//注:这种方式下,一定要加上这个 }) }else{ if(content_status==2 && priceid==''){alert("请选择价格项目!"); return false;} $(".xunjiabox,.box").fadein(); } } function tijiao(){ var desc=$('#desc').val(); var pid=$('#pid').val(); var priceid=$('#priceid').val(); $.post(site+'pro.php',{act:'save_xunjia',pid:pid,desc:desc,priceid:priceid},function(data){ if(data){ alert("发送询价成功!"); $('#desc').val(''); $(".xunjiabox,.box").fadeout(); } }) }