<!-- #include file="include/con_shop.asp" -->
<%
dim id,shop_session
shop_session=trim(request.cookies(joekoe_cms.web_cookies)("bag_"&n_sort))
id=trim(request.querystring("id"))
tit="我的购物车"

'response.cookies(joekoe_cms.web_cookies)("bag_"&n_sort)=""

call web_head(0,0,0,0,0)
call shop_load(0,0,0)
'----------------------------左边 开始----------------------------
call shop_left()
call shop_left_nsort(0)
'----------------------------左边 结束----------------------------
call web_center(0)
'----------------------------中间 开始----------------------------
if isnumeric(id) then
  call shop_bag_add(id)
end if

select case action
case "chk"
  call shop_bag_chk()
case "clear"
  call shop_bag_clear()
end select

call shop_bag_type()

response.write ukong
'----------------------------中间 结束----------------------------
call shop_end()
call web_end(0,0)

sub shop_bag_chk()
  dim sdim,sel_id,nnum
  sel_id=trim(request.form("sel_id"))
  sel_id=replace(sel_id,", ",",")
  sdim=split(sel_id,",")
  shop_session=""
  for i=0 to ubound(sdim)
    if joekoe_cms.int_true(sdim(i)) then
      nnum=trim(request.form("sel_num"&sdim(i)))
      if joekoe_cms.int_true(nnum)=false then nnum=1
      shop_session=shop_session&","&sdim(i)&"$"&nnum
    end if
  next
  erase sdim
  if left(shop_session,1)="," then shop_session=right(shop_session,len(shop_session)-1)
  response.cookies(joekoe_cms.web_cookies)("bag_"&n_sort)=shop_session
  response.write vbcrlf&joekoe_cms.js_put("alert(""成功更改了"&tit&"内所选的"&val_name&"！"");",1)
end sub

sub shop_bag_clear()
  shop_session=""
  response.cookies(joekoe_cms.web_cookies)("bag_"&n_sort)=shop_session
  response.write vbcrlf&joekoe_cms.js_put("alert(""成功清空了"&tit&"内所选的"&val_name&"！"");",1)
end sub

sub shop_bag_add(aid)
  sql="select top 1 name from shop_product where hidden=1 and id="&aid
  set rs=joekoe_cms.exec(sql,1)
  if rs.eof then
    response.write vbcrlf&joekoe_cms.js_put("alert("""&val_name&"（ID："&aid&"）不存在！"");",1)
  else
    if instr(","&shop_session&"$",","&aid&"$")<1 then
      shop_session=shop_session&","&aid&"$1"
      if left(shop_session,1)="," then shop_session=right(shop_session,len(shop_session)-1)
      response.cookies(joekoe_cms.web_cookies)("bag_"&n_sort)=shop_session
      response.write vbcrlf&joekoe_cms.js_put("alert(""成功添加"&val_name&"（名称："&rs("name")&"，ID："&aid&"）到"&tit&"内！"");",1)
    end if
  end if
end sub

sub shop_bag_type()
  dim sdim,ssum,nid,nnum,price,price_now,discount,name,ds
  ssum=0
  ds=" disabled"
  sdim=split(shop_session,",")
%>
<table cellspacing=1 cellpadding=4 class=table>
<tr class=bg><td colspan=7 height=30 align=center><font class=red>以下是您所选购的<%response.write val_name%>清单</font></td></tr>
<tr height=22 align=center> 
<td width='6%' class=td>选</td>
<td width='38%' class=td><%response.write val_name%>名称</td>
<td width='10%' class=td>数量</td>
<td width='13%' class=td>原价（<%response.write val_unit%>）</td>
<td width='8%' class=td>折扣</td>
<td width='13%' class=td>现价（<%response.write val_unit%>）</td>
<td width='12%' class=td>网币支付</td>
</tr>
<form name=shop_bag_frm action='shop_bag.asp?action=chk' method=post>
<%
  for i=0 to ubound(sdim)
    nid=left(sdim(i),instr(sdim(i),"$")-1)
    nnum=right(sdim(i),len(sdim(i))-instr(sdim(i),"$"))
    if isnumeric(nid) and joekoe_cms.int_true(nnum) then
      sql="select top 1 name,serial,price,discount,is_emoney,emoney from shop_product where hidden=1 and id="&nid
      set rs=joekoe_cms.exec(sql,1)
      if not rs.eof then
        name=joekoe_cms.code_html(rs("name"),1,0)
        price=fm_price(rs("price"),1)
        discount=rs("discount")
        price_now=fm_price(price*(discount/100),1)
        discount=fm_discount(discount)
        ssum=ssum+price_now*nnum
%>
<tr class=bg_td align=center>
<td><input type=checkbox name=sel_id value='<%response.write nid%>' checked class=bg_td></td>
<td align=left><a href='###' alt='<%response.write val_name%>编号：<%response.write rs("serial")%><br>点击浏览<%response.write val_name%>详细信息' onclick="javascript:open_view('shop_view.asp?id=<%response.write nid%>',1);"><%response.write name%></a></td>
<input type=hidden name=tmp_num<%response.write nid%> value='<%response.write nnum%>'>
<td><input type=text name=sel_num<%response.write nid%> size=4 value='<%response.write nnum%>' onKeyUp="javascript:shop_checknum(sel_num<%response.write nid%>,tmp_num<%response.write nid%>);" style="text-align: right"></td>
<td align=right><%response.write price%></td>
<td>
<%
        if discount=fm_discount(100) then
          response.write "<font class=gray>"&discount&"</font>"
        else
          response.write "<font class=red2>"&discount&"</font>"
        end if
%>
</td>
<td align=right><font class=blue><%response.write price_now%></font></td>
<td>
<%
        if rs("is_emoney") then
          response.write rs("emoney")
        else
          response.write "<font class=gray>不可用</font>"
        end if
%>
</td>
</tr>
<%
        ds=""
      end if
      rs.close
    end if
  next
%>
<tr class=bg_tds><td colspan=7 height=30 align=right>
<%
  if ds="" then
    response.write "您所选购的"&val_name&"总的有效金额：<font class=red>"&fm_price(ssum,1)&"</font>&nbsp;"&val_unit
  else
    response.write "您目前还没有选购"&val_name
  end if
%>
&nbsp;</td></tr>
<tr class=bg_td><td colspan=7 align=center height=40>
  <table border=0>
  <tr>
  <td><input type=submit value='确认更改'<%response.write ds%>></td>
  <td width=5></td>
  <td><input type=button value='继续购物' onclick="javascript:location.href='shop.asp';"></td>
  <td width=5></td>
  <td><input type=button value='清空购物车' onclick="javascript:shop_clear();"<%response.write ds%>></td>
  <td width=5></td>
  <td><input type=button value='去收银台' onclick="javascript:location.href='shop_pay.asp';"<%response.write ds%>></td>
  </tr>
  </table>
</td></tr>
<tr class=bg_td><td colspan=7 align=center><font class=red>注意：改变商品数量和减少商品种类需按“确认更改”按钮</font></td></tr>
</form>
</table>
<%
  erase sdim
end sub
%>