﻿function ShowPinyinLpList(obj,cityId){
obj.value=obj.value.trim();
if(obj.value.trim()!='')
{
if($('lpList').className!='lpList450'){$('lpList').style.display='none';}
AjaxHelper.Updater('wm/Panel_KeyPlList','lpList','&localKey='+obj.value+'&cityId='+cityId,function(){$('lpList').className='lpList450';$('lpList').style.display='block';});
}
else{
$('lpList').style.display='none';
}
}


function ShowAllLpList(cityId)
{
   if($('lpList').className!='lpList620'){$('lpList').style.display='none';}
    AjaxHelper.Updater('wm/Panel_AllLpList','lpList','&cityId='+cityId,function(){ $('lpList').className='lpList620'; $('lpList').style.display='block';});
    
}

function SetArea(cityId,parentId){
AjaxHelper.Updater('wm/Panel_AllLpList','lpList','&cityId='+cityId+'&parentId='+parentId);
}

function SetPinyin(cityId,parentId,pinyinKey){
AjaxHelper.Updater('wm/Panel_AllLpList','lpList','&cityId='+cityId+'&parentId='+parentId+'&pinyinKey='+pinyinKey);
}

function SetAddress()
{
    $('divlocalSet').style.display='block';

}

//
function SetAddressType(type,cityId,localId)
{

AjaxHelper.Updater('wm/Panel_UserInfo','wmUserInfo','&addresstype='+type+'&cityId='+cityId);
if(localId>0){
 $('Div_localdictList').innerHTML='<div style="text-align:center;font-size:13px;height:100px;line-height:100px;color:red" ><img src="/images/loading.gif" />正加载数据...</div>'
AjaxHelper.Updater('wm/Panel_localdictList','Div_localdictList','&localId='+localId);
}

}

function getInputdivListData(obj,cityId)
{
   var keyType='';
    if(obj.value!=''){
        if(isPinYin(obj.value)){
            keyType='pinyin';
        }
        else{
             keyType='chinese';
        }
        
          $('inputdivList').style.display='none';
            Web9eat.Web.UI.Ajax.BaseAjax.getLocaldictList(obj.value,keyType,cityId,function(res){
                   
                     if(res.value!=''){
                 
                                 $('inputdivList').style.display='block';
                             $('inputdivListData').innerHTML='';
                             var localdict=res.value;
                             var arr_localdict=localdict.split('|');
                             var localdictlist='';
                             var arr_localdict_length=arr_localdict.length-1
                             if(arr_localdict_length>10)
                             {
                              $('inputdivListData').style.height='220px';
                              $('inputdivListData').style.overflowY='scroll'
                              }
                             else{
                                 var height=20*(arr_localdict_length);
                                  $('inputdivListData').style.height=height+'px';
                                 $('inputdivListData').style.overflowY='auto';
                             }
                              for(var i=0;i<arr_localdict_length;i++){
                              var arr_localItem=arr_localdict[i].split(',');
                                localdictlist+='<a href="javascript:void(0)" onclick="setInputdivListData('+arr_localItem[2]+',\''+arr_localItem[0]+'\')"  >'+arr_localItem[0]+'['+arr_localItem[1]+']</a>'
                              }

                              $('inputdivListData').innerHTML=localdictlist;
                     }
                     else
                     {
                           $('inputdivList').style.display='none';
                     }
             
             });   
   
    }
    else{
     $('inputdivList').style.display='none';
    }
}

function setInputdivListData(localId,localName){
    $('txtLocalName').value=localName;
    $('inputdivList').style.display='none';
}

function btnSetLocalNameSubmit(obj,addresstype,cityId)
{
   $('btnSetLocalName').disabled=true;
  Web9eat.Web.UI.Ajax.BaseAjax.setLocalAddress(addresstype,$F('txtLocalName'),cityId,function(res){
  $('btnSetLocalName').disabled=false;
                     if(res.value!=null)
                     {              
                       if(parseInt(res.value)>=0){
                         $('Div_localdictList').innerHTML='<div style="text-align:center;font-size:13px;height:100px;line-height:100px;color:red" ><img src="/images/loading.gif" />正加载数据...</div>'
                        AjaxHelper.Updater('wm/Panel_localdictList','Div_localdictList','&localId='+res.value,SetAddressType(addresstype,cityId));
                        }
                        else if(res.value=='-1')
                        {
                         alert('数据库里未找到您输入的楼盘，请重试输入周边的楼盘!');return;
                        }
                     }
                     else
                     {
                           location.href='/wm/';
                     }
             
             });   

}



//外卖订单提交
function WmOrderSumbit(companyId,flag)
{



if($F('txtCheckedCpCount')=='0'){alert('未选择菜单，不能提交定单！');return;}
if(parseInt($F('txtAmountSum'))<parseInt($('sendAmount').innerHTML)){
    if(!confirm('当前的金额未达到起送金额，是否继续提交？'))return;
}
  var address='';
  var arr_radaddress=document.getElementsByName("radAddress");
  var addresstype='';
  for(var i=0;i<arr_radaddress.length;i++)
  {
    if(arr_radaddress[i].checked){
    addresstype=arr_radaddress[i].value;
    break;
    }
  }
  if(arr_radaddress.length>0)//已配置地址
  {
    if(i==arr_radaddress.length){
    alert('请选择地址类型!');arr_radaddress[0].focus();return;}
    else{
        if(addresstype=='其它'&&$F('txtLocalName')=='')
        {
           alert('请输入所在的楼盘!');$('txtLocalName').focus();return;
        }
    }
  }
  else//未配置地址
  {
    if($F('txtLocalName')==''){alert('请输入所在的楼盘!');$('txtLocalName').focus();return;}
  }  
  if($F('txtAddress')==''){alert('请输入详细的配送地址!');$('txtAddress').focus();return;}
  if($F('txtName')==''){alert('请输入联系人!');$('txtName').focus();return;}
  if($F('txtTel')==''){alert('请输入电话或手机号码!');$('txtTel').focus();return;}
  if($F('txtSendDate')==''){alert('请输入配送的日期!');$('txtSendDate').focus();return;}
  if($F('txtSendTime')==''){alert('请输入配送的时间!');$('txtSendTime').focus();return;}
  $('btnResevation').disabled=true;  
 //alert(companyId+","+$F('txtAddress')+","+$F('txtName')+","+$F('txtTel')+","+$F('txtSendDate')+' '+$F('txtSendTime')+","+$F('txtRemarks')+","+addresstype+","+$('ddAreaValue')+","+$('ddTypeValue')+","+$('txtLocalName'));
 
 
 //return;

 if(flag==0)
 {
     if(Web9eat.Web.UI.Ajax.BaseAjax.IsLogin().value=='0'){
     if(!confirm('您当前未登录，是否继续提交定单?')){ShowLoginWin();return;}
     }
     else{
        $('btnResevation').disabled=false;
     }
 }


      Web9eat.Web.UI.Ajax.CompanyAjax.WmOrderSubmit(companyId,$F('txtAddress'),$F('txtName'),$F('txtTel'),$F('txtSendDate')+' '+$F('txtSendTime'),$F('txtRemarks'),addresstype,$F('ddAreaValue'),$F('ddTypeValue'),$F('txtLocalName'),flag,function(res){
      var result=res.value;
        $('btnResevation').disabled=false;
     
        if(result=="1"){
                alert('您已经外卖定单已经提交成功！'); 
               location.reload();
        }    
        else if(result=="2"){
            var str='对不起！你的地址可能不在商家配送范内，是否重新选择地址，按“是”返回重新输入地址，按“否”提交成功！';
            if(confirm(str)){
                   return;
            }
            else{
                WmOrderSumbit(companyId,1);
            }
           
        } 
        else{
            alert("数据库操作失败");
        }
    });
  

}