123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369 |
- var id=mobile.getUrlVars("id");
- var order;
- var money = 0;
- var product;
- var orderDate=[];
- var addrlist=[];
- mui.init();
- mui.ready(function(){
- getById();
- $("#product").on("tap","li",function(e){
- location.href=base+"/mobile/productDetail.jsp?id="+$(this).attr("data-id");
- });
- $("#pay").on("tap",".mui-input-row",function(e){
- var list = $(this).find("input[type='radio']");
- list.each(function(){
- this.checked = true;
- });
- });
- $("#pay-btn").on("tap",function(e){
- var i=-1;
- $('input[type="radio"]').each(function(){
- if(this.checked){
- i = $(this).parent().index();
- }
- });
- if(i==1){
- if(parseFloat(money)<parseFloat(order.order_amt)){
- layer.open({content: "余额不足",time: 3});
- return;
- }
- mobile.ajaxPost(base+'/userOrder/moneyPay',{id:id},function(json){
- if(json.success){
- layer.open({content: '支付成功',time: 3});
- setTimeout(function() {
- window.location.reload();
- }, 1000);
- }else{
- layer.open({content: json.msg,time: 3});
- }
- });
- }else{
- var addressId = $('#addr').find('li').attr('data-id');
- if(!addressId&&product.is_delivery=="1"){
- layer.open({content:'请选择收货地址',time:3});
- return;
- }
- mobile.ajaxPost(base+'/userOrder/pay',{id:id,addressId:addressId},function(json){
- if(json.success){
- var data=json.data;
- if (typeof WeixinJSBridge == "undefined"){
- if( document.addEventListener ){
- document.addEventListener('WeixinJSBridgeReady', onBridgeReady(data), false);
- }else if (document.attachEvent){
- document.attachEvent('WeixinJSBridgeReady', onBridgeReady(data));
- document.attachEvent('onWeixinJSBridgeReady', onBridgeReady(data));
- }
- }else{
- onBridgeReady(data);
- }
- }else{
- layer.open({content: json.msg,time: 3});
- }
- });
- }
- });
- $("#use-btn").on("tap",function(e){
- if($("#password").val()==""){
- layer.open({content:'请输入核销密码',time:3});
- return;
- }
- mobile.ajaxPost(base+'/userOrder/useOrder',{id:id,password:$("#password").val(),useNum:$('.mui-input-numbox').val()},function(json){
- if(json.success){
- layer.open({content:'核销成功',time:1});
- setTimeout(function() {
- location.reload();
- }, 1000);
- }else{
- layer.open({content: json.msg,time: 3});
- }
- });
- });
- $("#order-btn").on("tap",function(e){
- if($("#order_date").val()==""){
- layer.open({content:'请选择预约日期',time:3});
- return;
- }
- mobile.ajaxPost(base+'/userOrder/orderDate',{id:id,productId:product.id,orderDate:$("#order_date").val()},function(json){
- if(json.success){
- layer.open({content: "预约成功,请在"+$("#order_date").val()+"当天使用",time: 2});
- setTimeout(function() {
- location.reload();
- }, 2000);
- }else{
- layer.open({content: json.msg,time: 3});
- }
- });
- });
- $("#comment .icon-chucuo1").on("click",function(){
- $("#comment").remove();
- });
- $("#comment .main").on("tap",function(){
- location.href=base+"/mobile/index.jsp";
- });
- $("#comment .comment").on("tap",function(){
- location.href=base+"/mobile/userOrderComment.jsp?id="+order.id;
- });
- $("#reorder-btn").on("tap",function(e){
- var html=[];
- html.push('<select id="orderDate" style="border: 1px solid rgba(0, 0, 0, .2)!important;">');
- $.each(orderDate, function (id,item) {
- html.push('<option value="'+item+'">'+item+'</option>');
- });
- html.push('</select>');
- mui.alert(html.join(""), '选择预约日期', function() {
- if($("#orderDate").val()==""){
- layer.open({content:'请选择预约日期',time:3});
- return;
- }
- mobile.ajaxPost(base+'/userOrder/orderDate',{id:id,productId:product.id,orderDate:$("#orderDate").val()},function(json){
- if(json.success){
- layer.open({content: "预约成功,请在"+$("#orderDate").val()+"当天使用",time: 2});
- setTimeout(function() {
- location.reload();
- }, 2000);
- }else{
- layer.open({content: json.msg,time: 3});
- }
- });
- });
- });
- $("#addr").on("tap",function(){
- $('#addrList').addClass('mui-active');
- });
- $("#addrList").on("tap",'.mui-icon-left-nav',function(){
- $('#addrList').removeClass('mui-active');
- });
- $("#addrList").on("tap",'.mui-btn-link',function(){
- location.href=base+'/mobile/userAddressAdd.jsp';
- });
- });
- function getById(){
- mobile.ajaxPost(base+'/userOrder/getById',{id:id},function(json){
- order = json.data;
- product = order.list[0];
- if (product.is_delivery=="1") {
- getAddressList();
- $("#addr").show();
- }
- var html= [];
- $.each(order.list,function(id,item){
- html.push('<li class="mui-table-view-cell mui-media" data-id="'+item.id+'">');
- html.push('<div class="product-img mui-pull-left">');
- html.push('<img src="'+imgUrl+item.product_main_img+'">');
- if(item.order_hour<=0){
- html.push('<span class="img-icon">免预约</span>')
- }
- html.push('</div>');
- html.push('<div class="mui-media-body pl10">');
- html.push('<p class="product-merchant mui-ellipsis">'+item.merchant_name+'</p>');
- html.push('<p class="product-title mui-ellipsis-2">'+item.product_name+'</p>');
- html.push('<p class="product-price items">');
- html.push('<em class="item"><b>¥</b>'+item.product_price+'<span class="del-line color3 ml5">'+item.product_old_price+'元</span></em>');
- html.push('<span class="color2 fs14">x'+item.product_qty+'</span></p>');
- html.push('</div>');
- html.push('</li>');
- });
- if(order.order_status=="10"){
- $('#pay_amt').prev().html('需付款');
- $('#title').html('待付款');
- $('#pay_amt').html('<em class="fs16"><b>¥</b>'+order.order_amt+'</em>');
- $("#pay").removeClass("mui-hidden");
- var interval= setInterval(function() {
- var leftTime = (new Date(order.create_time.replace(/-/g, "/"))) - (new Date()) + 5*60*1000;
- var days = parseInt(leftTime / 1000 / 60 / 60 / 24 , 10); //计算剩余的天数
- var hours = parseInt(leftTime / 1000 / 60 / 60 % 24 , 10); //计算剩余的小时
- var minutes = parseInt(leftTime / 1000 / 60 % 60, 10);//计算剩余的分钟
- var seconds = parseInt(leftTime / 1000 % 60, 10);//计算剩余的秒数
- hours = checkTime(hours);
- minutes = checkTime(minutes);
- seconds = checkTime(seconds);
- if(leftTime<0){
- $(".left-time").html("订单失效,请重新下单");
- location.href=base+"/mobile/productDetail.jsp?id="+order.list[0].id;
- }else{
- $(".left-time").html("请在" + minutes+"分"+seconds+"秒内付款,否则订单会失效");
- }
- }, 1000);
- getMoney();
- }else if(order.order_status=="20"){
- if (product.order_num&&!order.order_date){
- getOrderDate();
- $("#order").removeClass("mui-hidden");
- $('#pay_amt').prev().html('已付款');
- $('#title').html('待预约');
- $('#pay_amt').html('<em class="fs16"><b>¥</b>'+mobile.nullToZore(order.pay_amt)+'</em>');
- if (product.product_type!='30'){
- if(new Date(product.use_time.replace(/-/g, "/"))>new Date()){
- $(".use_time").html("请在"+product.use_time+"前使用");
- }else{
- $(".use_time").html("使用时间已截止");
- }
- }
- }else{
- $("#tip").removeClass("mui-hidden");
- $("#use").removeClass("mui-hidden");
- $('#pay_amt').prev().html('已付款');
- $('#title').html('待使用');
- $('#pay_amt').html('<em class="fs16"><b>¥</b>'+mobile.nullToZore(order.pay_amt)+'</em>');
- if (product.product_type!='30'){
- if(new Date(product.use_time.replace(/-/g, "/"))>new Date()){
- if (order.order_date){
- $(".use_time").html("请在"+order.order_date+"当天使用");
- $("#reorder-btn").removeClass("mui-hidden");
- getOrderDate();
- }else{
- $(".use_time").html("请在"+product.use_time+"前使用");
- }
- }else{
- $(".use_time").html("使用时间已截止");
- }
- }
- var nbox = mui('.mui-numbox').numbox();
- nbox.options["max"]=product.surplus_qty;
- $('#surplus-qty').html("<span class='color-red'>剩余"+product.surplus_qty+"份</span>");
- if (product.product_qty>1){
- $('#use-num').show();
- $('#surplus-qty').show();
- }
- }
- }else if(order.order_status=="30"){
- $('#pay_amt').prev().html('已付款');
- $('#title').html('交易成功');
- $('#pay_amt').html('<em class="fs16"><b>¥</b>'+mobile.nullToZore(order.pay_amt)+'</em>');
- if(order.comment_flag!="1"){
- $(".integral").html(parseInt(order.pay_amt)+"积分");
- $("#comment").removeClass("mui-hidden");
- }
- }else{
- $('#title').html('订单失效');
- }
- if(order.order_type=="10"){
- $("#sumPrice").removeClass("mui-hidden");
- }else if(order.order_type=="20"){
- $("#sumIntegral").removeClass("mui-hidden");
- }
- $('.mui-content').removeClass('mui-hidden');
- $('#product').html(html.join(''));
- });
- }
- //获取余额
- function getMoney() {
- mobile.ajaxPost(base + '/userMoney/getMoney', {}, function(json) {
- money = json.data;
- $('#money').html("¥"+json.data);
- },"");
- }
- //获取余额
- function getOrderDate() {
- mobile.ajaxPost(base + '/userOrder/getOrderDate', {productId: product.id}, function(json) {
- if (json.data&&json.data.length>0){
- orderDate = json.data;
- $.each(json.data, function (id,item) {
- $("#order_date").append('<option value="'+item+'">'+item+'</option>');
- })
- }
- },"");
- }
- function onBridgeReady(json){
- WeixinJSBridge.invoke(
- 'getBrandWCPayRequest',
- json,
- function(res){
- if(res.err_msg == "get_brand_wcpay_request:ok" ) {
- queryOrder();
- }else{
- layer.open({content: '支付失败',time: 3});
- }
- }
- );
- }
- function queryOrder(){
- mobile.ajaxPost(base+'/userOrder/queryOrder',{id:id},function(json){
- if(json.success){
- var data=json.data;
- if(data.trade_state=="SUCCESS"){
- layer.open({content: '支付成功',time: 3});
- setTimeout(function() {
- window.location.reload();
- }, 1000);
- }else{
- layer.open({content: '支付失败',time: 3});
- }
- }else{
- layer.open({content: json.msg,time: 3});
- }
- });
- }
- function checkTime(i){ // 将0-9的数字前面加上0,例1变为01
- if(i<10) {
- i = "0" + i;
- }
- return i;
- }
- //获取地址列表
- function getAddressList() {
- mobile.ajaxPost(base + '/userAddress/getList', {}, function(json) {
- if(json.data&&json.data.length){
- $.each(json.data,function(id,item){
- var html = [];
- html.push('<li class="mui-table-view-cell">');
- html.push('<a class="mui-navigate-right">');
- html.push('<p class="color1">');
- html.push('<span class="mr15">'+item.consignee+'</span>');
- html.push('<span class="phone">'+item.mobile+'</span>');
- html.push('</p>');
- if(item.is_default=='1'){
- html.push('<p class="color2 mui-ellipsis-2 pr15"><span class="main-color">[默认] </span>');
- }else{
- html.push('<p class="color2 mui-ellipsis-2 pr15">');
- }
- html.push(''+mobile.nullToSpace(item.district)+mobile.nullToSpace(item.address)+mobile.nullToSpace(item.house_num)+'</p>');
- html.push('</a>');
- html.push('</li>');
- var map = new BMap.Map("allmap");
- var pointA = new BMap.Point(item.longitude,item.latitude);
- var pointB = new BMap.Point(117.950, 28.463);
- var distance = parseInt(map.getDistance(pointA,pointB));
- if(distance<=10000*1000){
- addrlist.push(item);
- $("#inrange").append(html.join(""));
- }else{
- $("#outrange").append(html.join(""));
- }
- });
- }else{
- $('#addr').html('<li class="mui-table-view-cell"><a class="mui-navigate-right">'+
- '<p class="color1">选择收货地址</p></a></li>');
- $('#addrList .mui-table-view').html('');
- mobile.tip('#addrList .mui-content','暂无收货地址');
- }
- if($("#inrange li").length!=0){
- $("#inrange").removeClass("mui-hidden");
- var item = addrlist[0];
- $('#addr').html('<li class="mui-table-view-cell" data-id="'+item.id+'"><a class="mui-navigate-right">'+
- '<p class="color1"><span class="mr15">'+item.consignee+'</span><span class="phone">'+item.mobile+'</span></p>'+
- '<p class="color2 mui-ellipsis-2">'+mobile.nullToSpace(item.district)+mobile.nullToSpace(item.address)+mobile.nullToSpace(item.house_num)+'</p></a></li>');
- }
- if($("#outrange li").length!=0){
- $("#outrange").removeClass("mui-hidden");
- $("#outrangelbl").removeClass("mui-hidden");
- }
- });
- }
|