//author: 声色视觉
//webSite: www.softboyo.cn
//blog.sina.com/k3man
//2021-05
$(function(){getshopingcar();GetAD();$("#postbtn").click(function(){0==$("#total").text()?msgbox("\u8d2d\u7269\u8f66\u6ca1\u6709\u53ef\u7ed3\u7b97\u7684\u5546\u54c1\u3002",2):""==$("#tel").val()?(msgbox("\u624b\u673a\u53f7\u7801\u4e0d\u80fd\u4e3a\u7a7a",2),$("#tel").focus()):isPhoneNo($("#tel").val())?postdb():msgbox("\u624b\u673a\u53f7\u7801\u6709\u8bef\uff0c\u5c06\u5f71\u54cd\u60a8\u7684\u7b7e\u6536\u3002",2)});$(":button").click(function(){var a=this.value,b=this.id.split("_")[1],c=$("#count_"+b).val();"+"==a?c=Number(c)+1:1<Number(c)?c=Number(c)-1:(delcardb(b),delelement(b));$("#count_"+b).val(c);modifycar(b)})});function getshopingcar(){var a=readcardb(),b="",c=0,d='\x3ctr\x3e\x3ctd\x3e\x3ch5\x3e,\x3c/h5\x3e\x3c/td\x3e\x3c/tr\x3e\x3ctr\x3e\x3ctd\x3e\uffe5\uff1a,\x3c/td\x3e\x3c/tr\x3e\x3ctr\x3e\x3ctd\x3e\x3cinput type\x3d"button" value\x3d"-" class\x3d"btn-lg" id\x3d"les_,"\x3e\x3cinput type\x3d"text" class\x3d"container2";text-align: center" id\x3d"count_," value\x3d"," readonly\x3d"readonly"\x3e\x3cinput type\x3d"button" value\x3d"+" class\x3d"btn-lg" id\x3d"add_,"\x3e\x3chr\x3e\x3c/td\x3e\x3c/tr\x3e'.split(",");for(key in a)b+=d[0]+a[key].goods+d[1]+a[key].price+d[2]+a[key].pid+d[3]+a[key].pid+d[4]+a[key].quant+d[5]+a[key].pid+d[6],c+=a[key].quant*a[key].price;$("#total").text(c.toFixed(2));$("#carinfo").html(b)}function GetAD(){var a=[],b="";a[0]='\x3cdiv class\x3d"blog-slider__item swiper-slide"\x3e\x3cdiv class\x3d"blog-slider__img"\x3e\x3cimg src\x3d"assets/img/';a[1]='"\x3e\x3c/div\x3e\x3cdiv class\x3d"blog-slider__content"\x3e\x3cspan class\x3d"blog-slider__code"\x3e';a[2]='\x3c/span\x3e\x3cdiv class\x3d"blog-slider__title"\x3e';a[3]='\x3c/div\x3e\x3cdiv class\x3d"blog-slider__text"\x3e';a[4]='\x3c/div\x3e\x3ca class\x3d"class\x3d\x26quot;blog-slider__button" id\x3d"payad_';a[5]='" href\x3d"#"\x3e\u70b9\u6b64\u5f00\u59cb\u6545\u4e8b\x3c/a\x3e\x3c/div\x3e\x3c/div\x3e';GetBackstage("Carousel",function(c){c=c[0];for(key in c.id)b+=a[0]+c.pic[key]+a[1]+c.phrase[key]+a[2]+c.title[key]+a[3]+c.direction[key]+a[4]+c.id[key]+a[5];$(".blog-slider__wrp").html(b+'\x3cdiv class\x3d"blog-slider__pagination"\x3e\x3c/div\x3e');Initi()})}function Initi(){new Swiper(".blog-slider",{spaceBetween:30,effect:"fade",loop:!0,autoplay:{delay:5E3},mousewheel:{invert:!1},pagination:{el:".blog-slider__pagination",clickable:!0}})}function postdb(){var a=GetDateTime(),b=0,c=0;opercar=readcardb();goodsList={main:[],Detail:[]};for(key in opercar)goodsList.Detail.push({oid:a,pid:opercar[key].pid,quant:opercar[key].quant,price:opercar[key].price}),b+=opercar[key].quant*opercar[key].price,c+=opercar[key].quant;goodsList.main.push({oid:a,totalqua:c,totalprice:b,phone:$("#tel").val(),address:$("#addres").val(),notes:$("#notes").val()});postBackstage("trade",goodsList,function(c){"error"===c?msgbox("\u8fde\u63a5\u9519\u8bef\uff0c\u8bf7\u7a0d\u5019\u518d\u8bd5",0):gotopay(a,b)})}function gotopay(a,b){var c=100*parseFloat(b),c=JSON.stringify({orderId:a,money:c});wx.miniProgram.navigateTo({url:"../wePay/wePay?payDataStr\x3d"+c})}function delcardb(a){var b=readcardb();for(key in b)b[key].pid===a&&(b.splice(key,1),writeCardb(b))}function modifycar(a){var b=readcardb(),c=0;for(key in b)b[key].pid===a&&(b[key].quant=parseInt($("#count_"+a).val())),c+=b[key].price*b[key].quant;writeCardb(b);$("#total").text(c.toFixed(2))}function delelement(a){var b=$("#les_"+a).parent().parent();b.hide(1E3,function(){b.prev().remove();b.prev().remove();b.remove()})}function DelCarDB(){0<Number($("#total").text())&&$.cookie("cakecar",null,{expires:-1});$("#total").text("0.00");$("#carinfo").hide(1E3,function(){$("#carinfo").remove()})};