var ProductInfo = ""; var number = ""; $(document).ready(function () { init(); }); /* * 页面初始化函数 * */ init = function () { var pid = getUrlParam("pid"), attr = getUrlParam("attr"); // num = getUrlParam("num"); if (pid === "" || attr === "") { go404Html(); } else { $(".goback").attr("href", "goods.html?pid=" + pid); getProductInfo(pid); initialize(); } } getProductInfo = function (pid) { var parameter = urlEncode(["SelectProduct", pid]); $.ajax({ type: "post", url: "/taiwan/php/index.php", data: {mode: parameter}, dataType: "json", success: function (data) { printProductInfo(data); } }); } printProductInfo = function (data) { if (data == -1 || data[0].length === 0) { go404Html(); } else { $("#PageLoading").css({"display": "none"}); $("#PageWarp").css({"display": "block"}); ProductInfo = data[0][0]; // $("#goodName").html(data[0][0].ProductIntroduce); var attr = JSON.parse(unescape(getUrlParam("attr"))); $(".m-orderItem").html(""); for (var i in attr) { if (i == 0) { $("#payment_amount").html(parseInt(attr[0].Money) * parseInt(attr[0].Number)); $("#total").html(parseInt(attr[0].Money) * parseInt(attr[0].Number)); number = attr[0].Number; ProductInfo.ProductPrice = parseInt(attr[0].Money) * parseInt(attr[0].Number); $(".number").html(attr[0].Number);//数量 } if (i != 0) { var a = '
' + '
' + '' + '
' + '
\n' + '
' + ProductInfo.ProductName + '
\n' + '
\n' + '
顏色分類: ' + attr[i]['color'] + '
' + (attr[i]['size'] ? '
ขนาด:' + attr[i]["size"] + '
' : '') + '
數量: ' + attr[0].Number + '
' + '
' + '
' + '
'; $(".m-orderItem").append(a); } } } } submit = function () { var lid = "", ordernum = orderNum(), pid = getUrlParam("pid"), pcid = escape(getUrlParam("attr")), attr = "", ppr = ProductInfo.ProductPrice, pn = number, urn = $("#UserReallyName").val().trim(), upn = $("#thaphone").val().trim(), uem = $("#UserEMail").val().trim(), pc = $("#tha_postal").val().trim(), p = $("#Province").html(), c = "", a = $("#Area").val().trim(), address = $("#Address").val().trim(), rem = $("#Remarks").val().trim(), fr = 0, am = ProductInfo.ProductPrice, pay = ProductInfo.ProductPrice, state = 1; if (urn == "") { // alert("请输入姓名"); alert("請輸入姓名"); return; } else if (upn == "") { // alert("请输入手机号码"); alert("請輸入手機號碼"); return; } /* else if (uem == "") { // alert("请输入电子邮件"); alert("請輸入電子郵件"); return; } */ else if (pc == "") { // alert("请输入邮编"); alert("請輸入郵政編碼"); return; } else if (p == "") { // alert("请输入省份"); alert("請輸入省份"); return; } else if (a == "") { // alert("请输入直辖区"); alert("請輸入直轄區"); return; } else if (address == "") { // alert("请输入详细地址"); alert("請輸入詳細地址"); return; } /* else if (rem == "") { // alert("请输入留言"); alert("請輸入留言"); return; } */ $("#PageLoading").css({"display": "block"}); $("#PageWarp").css({"display": "none"}); var parameter = urlEncode(["InsertOrder", lid, ordernum, pid, pcid, attr, ppr, pn, urn, upn, uem, pc, p, c, a, address, rem, fr, am, pay, state]); $.ajax({ type: "post", url: "/taiwan/php/index.php", data: {mode: parameter}, dataType: "json", success: function (data) { if (data != -1 && data[0].OrderId) { $("#PageLoading").css({"display": "none"}); $("#PageWarp").css({"display": "block"}); alert("購買成功!"); window.location.href = "goods.html?pid=" + getUrlParam("pid"); // insertUserIpAddress(ordernum, function () { // // }); } else { alert("對不起,您購買失敗,請聯繫客服!!!"); } } }); //facebook推广购物事件,请不要删除!!!!! fbq('track', 'Purchase', { value: ProductInfo.ProductPrice, currency: 'TWD', content_ids: ProductInfo.ProductRemarks, content_type: 'product_group' }); } /* * 获取下单用户ip地址插入数据库 * */ insertUserIpAddress = function (num, cb) { var IPAddress = ipaddress.traits.ip_address, country = ipaddress.country.names["zh-CN"], city = ipaddress.city.names["zh-CN"], parameter = urlEncode(["InsertOrderIPAddress", num, IPAddress, country, city]); $.ajax({ type: "post", url: "/taiwan/php/index.php", data: {mode: parameter}, dataType: "json", success: function (data) { if (data == 1) { cb && cb(); } } }); } /* * 根据当前时间,生成订单号 * */ orderNum = function () { var vNow = new Date(), sNow = ""; sNow += String(vNow.getFullYear()); sNow += String(vNow.getMonth() + 1); sNow += String(vNow.getDate()); sNow += String(vNow.getHours()); sNow += String(vNow.getMinutes()); sNow += String(vNow.getSeconds()); sNow += String(vNow.getMilliseconds()); return sNow;//返回订单号 } /* * 输入泰国指定的邮政编码,生成指定的泰国地址。 * */ // selectCity = function () { // $('#tha_postal').change(function () { // var id = $(this).val(); // ajaxLocked = true; // $.ajax({ // url: '/taiwan/php/Forward.php', // type: 'post', // data: {'postName': id}, // dataType: 'json', // success: function (ret) { // if (ret) { // if (ret.length != 0) { // var option = ""; // for (var i in ret) { // option += ''; // $('.regions').html(ret[0].parent_name); // $('input[name="city"]').val(ret[0].parent_name); // } // $(".tha_district").html('').append(option); // ajaxLocked = false; // } else { // alert('郵政編碼不存在!'); // $('#tha_postal').val(''); // $('.tha_district').html(''); // $('.regions').html(''); // $('input[name="city"]').val(''); // ajaxLocked = true; // } // } else { // alert('郵政編碼不存在!'); // $('#tha_postal').val(''); // $('.tha_district').html(''); // $('.regions').html(''); // $('input[name="city"]').val(''); // ajaxLocked = true; // } // }, // error: function (xhr, ajaxOptions, thrownError) { // } // }); // }); // } /* * 選擇台灣的城市 */ //province(城市類类) function provinceList() { this.length=24; this[0] = new Option("臺北市","0"); this[1] = new Option("高雄市","1"); this[2] = new Option("基隆市","2"); this[3] = new Option("新竹市","3"); this[4] = new Option("臺中市","4"); this[5] = new Option("嘉儀市","5"); this[6] = new Option("臺南市","6"); this[7] = new Option("臺北縣","7"); this[8] = new Option("宜蘭縣","8"); this[9] = new Option("桃園縣","9"); this[10] = new Option("新竹縣","10"); this[11] = new Option("苗栗縣","11"); this[12] = new Option("臺中縣","12"); this[13] = new Option("彰化縣","13"); this[14] = new Option("南投縣","14"); this[15] = new Option("雲林縣","15"); this[16] = new Option("嘉義縣","16"); this[17] = new Option("臺南縣","17"); this[18] = new Option("高雄縣","18"); this[19] = new Option("屏東縣","19"); this[20] = new Option("臺東縣","20"); this[21] = new Option("花蓮縣","21"); this[22] = new Option("澎湖縣","22"); this[23] = new Option("金門縣","23"); this[24] = new Option("連江縣","24"); return this; } //创建provincelist实例 var provinceOb=new provinceList(); //定义province、city变量,用于select元素 var province; //初始化地区下拉菜单 function initialize(privinceId){ //获取select元素 province=document.getElementById("Area"); //循环添加省份到province for(var i=0;i