123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328 |
- var productId = mobile.getUrlVars('productId');
- var qty = mobile.getUrlVars('qty');
- var list=[];
- var addrlist=[];
- var arr=[];
- var userCard=[];
- 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 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/userAddressAdd.jsp';
- });
- $("#inrange").on("tap",'li',function(){
- var item = addrlist[$(this).index()];
- $('#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>');
- $('#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/save',{
- productId:productId,
- addressId:addressId,
- deliveryDate:deliveryDate,
- deliveryTime:deliveryTime,
- userMsg:userMsg,
- qty:qty
- },function(json){
- if(json.data){
- history.replaceState(null, "", base+"/mobile/userOrder.jsp");
- if(json.data.flag=="1"){
- location.href=base+"/mobile/userOrderDetail.jsp?id="+json.data.id;
- }else{
- location.href=base+"/mobile/userOrderPay.jsp?id="+json.data.id;
- }
- }else{
- layer.open({content:'提交失败,请重试',time:3});
- }
- });
- });
-
- $("#card").on("tap",'li',function(){
- location.href=base+"/mobile/userCard.jsp";
- });
- });
- function getProduct(){
- mobile.ajaxPost(base+'/userCart/getListForOrder',{productId:productId,qty:qty},function(json){
- var sumPrice=0;
- var totalPrice=0;
- if(json.data&&json.data.length>0){
- list = json.data;
- var html= [];
- var flag=false;
- $.each(json.data,function(id,item){
- html.push('<li class="mui-table-view-cell">');
- html.push('<div class="mui-pull-left product-img">');
- html.push('<img src="'+imgUrl+item.product_main_img+'">');
- html.push('</div>');
- html.push('<div class="mui-media-body pl10">');
- html.push('<p class="product-title">'+item.product_name+'</p>');
- html.push('<p class="product-price items">');
- html.push('<em class="item fs16"><b>¥</b>'+item.product_price+'</em>');
- html.push('<span class="color2">x'+item.product_qty+'</span>');
- html.push('</p>');
- html.push('</div>');
- html.push('</li>');
- sumPrice+=parseFloat(item.product_price)*item.product_qty;
- if(item.user_card_num>0){
- flag=true;
- }
- if(item.card_num&&item.user_card_num>=item.card_num*item.product_qty){
- $("#card").append('<li class="mui-table-view-cell">'+
- '<a class="mui-navigate-right">'+
- '<p class="color1">'+
- '<span class="pr15">水票</span>'+
- '<span class="color2">'+item.card_name+'<span class="color-red"> x'+(item.card_num*item.product_qty)+'</span></span>'+
- '</p>'+
- '</a>'+
- '</li>');
- }else{
- totalPrice+=parseFloat(item.product_price)*item.product_qty;
- }
- });
- if($("#card li").length==0){
- if(flag){
- $("#card").append('<li class="mui-table-view-cell">'+
- '<a class="mui-navigate-right">'+
- '<p class="color1">'+
- '<span class="pr15">水票</span>'+
- '<span class="color2">水票不足</span>'+
- '</p>'+
- '</a>'+
- '</li>');
- }else{
- $("#card").append('<li class="mui-table-view-cell">'+
- '<a class="mui-navigate-right">'+
- '<p class="color1">'+
- '<span class="pr15">水票</span>'+
- '<span class="color2">没有可用的水票</span>'+
- '</p>'+
- '</a>'+
- '</li>');
- }
- }
- $("#card").removeClass("mui-hidden");
- $('#product').html(html.join(''));
- $('#sumPrice .product-price').html('<em class="fs16"><b>¥</b>'+mobile.toDecimal(sumPrice)+'</em>');
- $('#payPrice').html('<em class="fs16"><b>¥</b>'+mobile.toDecimal(totalPrice)+'</em>');
- $('.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('<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<=10*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");
- }
- });
- }
- 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+''
- }
- }
|