<!--#include file="conn.asp"-->
<%
action=Request("action")
%>

<%
'切换地址
deliveryAddressId=Request("deliveryAddressId")
if action="listExpressAndPrice" then
	set rsp=server.CreateObject("adodb.recordset")
	rsp.open "select * from com_Uadd where id="&deliveryAddressId,conn,1,1
	provinceId=rsp("provinceId")
	rsp.close
	set rsp=nothing
%>
{"result":"success","data":{"isExist":true,"expressList":[
<%
set rszf=server.CreateObject("adodb.recordset")
rszf.open "select * from com_songhuo where type=0 and sh=1 order by pid asc",conn,1,1
set subject=rszf("subject")
set subid=rszf("id")
i=1
do while not rszf.eof
	set rsp=server.CreateObject("adodb.recordset")
	rsp.open "select * from com_china where id="&provinceId,conn,1,1
%>
{"expressId":"<%=subid%>","expressName":"<%=subject%>","adjustPrice":<%=Formatnumber(rsp("sh"&subid),1,-1,-1,0)%>,"price":<%=rsp("sh"&subid)%>}<%if i < rszf.recordcount then%>,<%end if%>
<%
	rsp.close
	set rsp=nothing
i=i+1
rszf.movenext
loop
rszf.close
set rszf=nothing
%>
]}}
<%
end if
%>


<%
'删除地址
deliveryAddressId=Request("deliveryAddressId")
if action="deleteUserDeliveryAddress" then
conn.execute("delete from com_Uadd where id="&deliveryAddressId)
response.write("{""result"":""success""}")
'response.write("{""errorCode"":""2001""}")
end if
%>

<%
'添加地址
if action="addUserDeliverAddress" then

areaString=Request("areaString")
receiverName=Request("receiverName")
provinceId=Request("provinceId")
cityId=Request("cityId")
countyId=Request("countyId")
address=Request("address")
postCode=Request("postCode")
mobile=Request("mobile")
telephone=Request("telephone")
isDefault=Request("isDefault")

if telephone<>"" then
	num = InStr(telephone,"-")
	if num > 0 then
	telephone=split(telephone,"-") 
	end if
end if

set rs=server.CreateObject("adodb.recordset")
rs.open "select * from [com_Uadd]",conn,1,3
rs.addnew
rs("UserID")=session("UserID")
rs("receiverName")=receiverName
rs("provinceId")=provinceId
rs("cityId")=cityId
if countyId<>"" then
rs("countyId")=countyId
end if
rs("address")=address
rs("postCode")=postCode
if Request("telephone")<>"" then
	if num<1 then
		rs("splitPhone2")=telephone
	else
		rs("splitPhone1")=telephone(0) 
		rs("splitPhone2")=telephone(1) 	
	end if
end if
'rs("splitPhone3")=request("splitPhone3")
rs("mobile")=mobile
if isDefault=1 then
 set rsis=server.CreateObject("adodb.recordset")
 sql="select isDefault from com_Uadd where UserID="&session("UserID")&" order by isDefault desc"
 rsis.open sql,conn,1,3
 if not rsis.bof or not rsis.eof then
 rsis("isDefault")=0
 rsis.update
 end if
 rsis.close
 set rsis=nothing
rs("isDefault")=1
else
rs("isDefault")=0
end if
rs.update
addid=rs("id")
rs.close
set rs=nothing
%>
{"result":"success","data":{"ecmDeliveryAddress":{"id":"<%=addid%>","address":"<%=address%>","cityId":"<%=cityId%>","countyId":"<%=countyId%>","createdStamp":1395108790691,"isDefault":1,"lastUpdatedStamp":1395108790691,"mobile":"<%=mobile%>","postCode":"<%=postCode%>","provinceId":"<%=provinceId%>","receiverName":"<%=receiverName%>","areaString":"<%=replace(areaString,"请选择","")%>","ecmUser":{"id":"<%=session("UserID")%>","gender":0,"loginTimes":0}}}}
<%end if%>

<%if action="calculateExpressPrice" then%>
{"result":"success"}
<%end if%>