var exchangeId = mobile.getUrlVars('exchangeId'); var qty = mobile.getUrlVars('qty'); var list=[]; var addrlist=[]; var arr=[]; var hours=[{ "text": "09:00-11:00", "value": "09:00-11:00" }, { "text": "11:00-13:00", "value": "11:00-13:00" }, { "text": "13:00-15:00", "value": "13:00-15:00" },{ "text": "15:00-17:00", "value": "15:00-17:00" },{ "text": "17:00-19:00", "value": "17:00-19:00" }]; var cityData = [{ value: '110000', text: '北京市', children: [{ value: "110101", text: "东城区" }] }] var begin; var end; mui.init(); mui.ready(function(){ getProduct(); getAddressList(); initHours(); var options={ "type": "hour", "customData": { "h": arr }, "labels": ["年", "月", "日", "时段"], "beginDate":begin, "endDate":end }; var picker = new mui.PopPicker({ layer: 2 }); picker.setData(arr); $("#deliveryTime").on("tap",function(){ picker.show(function(items) { $("#deliveryTime").val(items[0].value + " " + items[1].text); }); }); $("#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/userAddress.jsp'; }); $("#inrange").on("tap",'li',function(){ var item = addrlist[$(this).index()]; $('#addr').html('
  • '+ '

    '+item.consignee+''+item.mobile+'

    '+ '

    '+mobile.nullToSpace(item.district)+mobile.nullToSpace(item.address)+mobile.nullToSpace(item.house_num)+'

  • '); $('#addrList').removeClass('mui-active'); }); $("#saveOrder").on("tap",function(){ var addressId = $('#addr').find('li').attr('data-id'); var timeStr = $('#deliveryTime').val(); var userMsg = $('#userMsg').val(); if(!addressId){ layer.open({content:'请选择送水地址',time:3}); return; } if(!timeStr){ layer.open({content:'请选择送水时间',time:3}); return; } var deliveryDate = timeStr.substring(0,10); var deliveryTime = timeStr.substring(11,timeStr.length); mobile.ajaxPost(base+'/userOrder/saveIntegral',{ exchangeId:exchangeId, addressId:addressId, deliveryDate:deliveryDate, deliveryTime:deliveryTime, userMsg:userMsg, qty:qty },function(json){ if(json.data){ history.replaceState(null, "", base+"/mobile/userOrder.jsp?orderStatus=20"); location.href=base+"/mobile/userOrderDetail.jsp?id="+json.data; }else{ layer.open({content:'提交失败,请重试',time:3}); } }); }); }); function getProduct(){ mobile.ajaxPost(base+'/productExchange/getListForOrder',{exchangeId:exchangeId,qty:qty},function(json){ var sumPrice=0; if(json.data&&json.data.length>0){ list = json.data; var html= []; $.each(json.data,function(id,item){ html.push('
  • '); html.push('
    '); html.push(''); html.push('
    '); html.push('
    '); html.push('

    '+item.product_name+'

    '); html.push('

    '); html.push(''+item.exchange_integral+'积分'); html.push('x'+item.product_qty+''); html.push('

    '); html.push('
    '); html.push('
  • '); sumPrice+=parseInt(item.exchange_integral)*item.product_qty }); $('#product').html(html.join('')); $('#sumPrice .product-price').html(''+mobile.toDecimal(sumPrice)+'积分'); $('#payPrice').html(''+mobile.toDecimal(sumPrice)+''); $('.mui-content').removeClass('mui-hidden'); }else{ $('.mui-content').empty(); mobile.tip('.mui-content','暂无可结算商品'); $('.mui-bar-tab').hide(); $('.mui-content').removeClass('mui-hidden'); } }); } //获取地址列表 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('
  • '); html.push(''); html.push('

    '); html.push(''+item.consignee+''); html.push(''+item.mobile+''); html.push('

    '); if(item.is_default=='1'){ html.push('

    [默认] '); }else{ html.push('

    '); } html.push(''+mobile.nullToSpace(item.district)+mobile.nullToSpace(item.address)+mobile.nullToSpace(item.house_num)+'

    '); html.push('
    '); html.push('
  • '); 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<=10*1000){ addrlist.push(item); $("#inrange").append(html.join("")); }else{ $("#outrange").append(html.join("")); } }); }else{ $('#addr').html('
  • '+ '

    选择送水地址

  • '); $('#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('
  • '+ '

    '+item.consignee+''+item.mobile+'

    '+ '

    '+mobile.nullToSpace(item.district)+mobile.nullToSpace(item.address)+mobile.nullToSpace(item.house_num)+'

  • '); } if($("#outrange li").length!=0){ $("#outrange").removeClass("mui-hidden"); $("#outrangelbl").removeClass("mui-hidden"); } }); } function initHours(){ var h = new Date().getHours(); console.info(h); var m = new Date().getMinutes(); console.info(m); if(h>0&&h<9){ var children = []; var obj = new Object(); obj.value = new Date().format("yyyy-MM-dd"); obj.text = new Date().format("MM月dd日") + " "+mobile.getWeek(new Date())+" 今天"; children = hours; obj.children = children; arr.push(obj); }else if (h>=9&&h<11){ var children = []; var obj = new Object(); obj.value = new Date().format("yyyy-MM-dd"); obj.text = new Date().format("MM月dd日") + " "+mobile.getWeek(new Date())+" 今天"; var o = new Object(); o.text = full(h)+":"+full(m)+"-"+full(h+2)+":"+full(m); o.value = full(h)+":"+full(m)+"-"+full(h+2)+":"+full(m); children.push(o); children.push(hours[2]); children.push(hours[3]); children.push(hours[4]); obj.children = children; arr.push(obj); }else if(h>=11&&h<13){ var children = []; var obj = new Object(); obj.value = new Date().format("yyyy-MM-dd"); obj.text = new Date().format("MM月dd日") + " "+mobile.getWeek(new Date())+" 今天"; var o = new Object(); o.text = full(h)+":"+full(m)+"-"+full(h+2)+":"+full(m); o.value = full(h)+":"+full(m)+"-"+full(h+2)+":"+full(m); children.push(o); children.push(hours[3]); children.push(hours[4]); obj.children = children; arr.push(obj); }else if(h>=13&&h<15){ var children = []; var obj = new Object(); obj.value = new Date().format("yyyy-MM-dd"); obj.text = new Date().format("MM月dd日") + " "+mobile.getWeek(new Date())+" 今天"; var o = new Object(); o.text = full(h)+":"+full(m)+"-"+full(h+2)+":"+full(m); o.value = full(h)+":"+full(m)+"-"+full(h+2)+":"+full(m); children.push(o); children.push(hours[4]); obj.children = children; arr.push(obj); var children = []; obj = new Object(); obj.value = mobile.addDate(new Date(),1).format("yyyy-MM-dd"); obj.text = mobile.addDate(new Date(),1).format("MM月dd日") + " "+mobile.getWeek(mobile.addDate(new Date(),1))+" 明天"; children = hours; obj.children = children; arr.push(obj); }else if(h>=15&&h<17){ var children = []; var obj = new Object(); obj.value = new Date().format("yyyy-MM-dd"); obj.text = new Date().format("MM月dd日") + " "+mobile.getWeek(new Date())+" 今天"; var o = new Object(); o.text = full(h)+":"+full(m)+"-"+full(h+2)+":"+full(m); o.value = full(h)+":"+full(m)+"-"+full(h+2)+":"+full(m); children.push(o); obj.children = children; arr.push(obj); var children = []; obj = new Object(); obj.value = mobile.addDate(new Date(),1).format("yyyy-MM-dd"); obj.text = mobile.addDate(new Date(),1).format("MM月dd日") + " "+mobile.getWeek(mobile.addDate(new Date(),1))+" 明天"; children = hours; obj.children = children; arr.push(obj); }else if(h>=17){ var children = []; var obj = new Object(); obj.value = mobile.addDate(new Date(),1).format("yyyy-MM-dd"); obj.text = mobile.addDate(new Date(),1).format("MM月dd日") + " "+mobile.getWeek(mobile.addDate(new Date(),1))+" 明天"; children = hours; obj.children = children; arr.push(obj); } } function full(i){ if(i<10){ return '0'+i; }else{ return i+'' } }