<!-- #include file="include/config.asp" -->
<%
dim id,shop_session
shop_session=trim(request.cookies(joekoe_cms.web_cookies&"_shop")("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()
'----------------------------左边 开始----------------------------
call shop_left()
call shop_left_nsort(0)
call shop_top(10,10)
'----------------------------左边 结束----------------------------
call web_center(0)
'----------------------------中间 开始----------------------------
call shop_bag_close()

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&"_shop")("bag_"&n_sort)=shop_session
  response.write vbcrlf&joekoe_cms.js_put("alert(""成功更改了"&tit&"内所选的"&web_dim(44)&"！"");",1)
end sub

sub shop_bag_clear()
  shop_session=""
  response.cookies(joekoe_cms.web_cookies&"_shop")("bag_"&n_sort)=shop_session
  response.write vbcrlf&joekoe_cms.js_put("alert(""成功清空了"&tit&"内所选的"&web_dim(44)&"！"");",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("""&web_dim(44)&"（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&"_shop")("bag_"&n_sort)=shop_session
      response.write vbcrlf&joekoe_cms.js_put("alert(""成功添加"&web_dim(44)&"（名称："&rs("name")&"，ID："&aid&"）到"&tit&"内！"");",1)
    end if
  end if
end sub

sub shop_bag_type()
  dim tmp1,sdim,ssum,nid,nnum,price,price_now,discount,name,ds
  ssum=0
  ds=" disabled"
  sdim=split(shop_session,",")
  tmp1=vbcrlf&"<tr><td colspan=7 class=bg_td height=30 align=center><font class=red>以下是您所选购的"&web_dim(44)&"清单</font></td></tr>" & _
       vbcrlf&"<tr align=center>" & _
       vbcrlf&"<td width='7%' class=trs>选择</td>" & _
       vbcrlf&"<td width='38%' class=trs>"&web_dim(44)&"名称</td>" & _
       vbcrlf&"<td width='9%' class=trs>数量</td>" & _
       vbcrlf&"<td width='13%' class=trs>原价("&web_dim(45)&")</td>" & _
       vbcrlf&"<td width='8%' class=trs>折扣</td>" & _
       vbcrlf&"<td width='13%' class=trs>现价("&web_dim(45)&")</td>" & _
       vbcrlf&"<td width='12%' class=trs>"&web_dim(9)&"支付</td>" & _
       vbcrlf&"</tr>" & _
       vbcrlf&"<form name=shop_bag_frm action='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
        tmp1=tmp1&vbcrlf&"<tr class=bg_td align=center>" & _
             vbcrlf&"<td><input type=checkbox name=sel_id value='"&nid&"' checked class=bg_td></td>" & _
             vbcrlf&"<td align=left><a href='javascript:;'  alt='"&web_dim(44)&"编号："&rs("serial")&"<br>点击浏览"&web_dim(44)&"详细信息' onclick=""javascript:open_view('view.asp?id="&nid&"',1);"">"&name&"</a></td>" & _
             vbcrlf&"<input type=hidden name=tmp_num"&nid&" value='"&nnum&"'>" & _
             vbcrlf&"<td><input type=text name=sel_num"&nid&" size=3 value='"&nnum&"' onKeyUp=""javascript:shop_checknum(sel_num"&nid&",tmp_num"&nid&");"" style=""text-align: right;"" </td>" & _
             vbcrlf&"<td align=right>"&price&"</td>" & _
             vbcrlf&"<td>"
        if discount=fm_discount(100) then
          tmp1=tmp1&"<font class=gray>"&discount&"</font>"
        else
          tmp1=tmp1&"<font class=red2>"&discount&"</font>"
        end if
        tmp1=tmp1&"</td>" & _
             vbcrlf&"<td align=right><font class=blue>"&price_now&"</font></td>" & _
             vbcrlf&"<td>"
        if rs("is_emoney") then
          tmp1=tmp1&rs("emoney")
        else
          tmp1=tmp1&"<font class=gray>不可用</font>"
        end if
        tmp1=tmp1&"</td>" & _
             vbcrlf&"</tr>"
        ds=""
      end if
      rs.close
    end if
  next
  tmp1=tmp1&vbcrlf&"<tr class=trz><td colspan=7 height=30 align=right>"
  if ds="" then
    tmp1=tmp1&"您所选购的"&web_dim(44)&"总的有效金额：<font class=red>"&fm_price(ssum,1)&"</font>&nbsp;"&web_dim(45)
  else
    tmp1=tmp1&"您目前还没有选购"&web_dim(44)
  end if
  tmp1=tmp1&"&nbsp;</td></tr>" & _
       vbcrlf&"<tr class=bg_td><td colspan=7 align=center height=40>" & _
       vbcrlf&"  <table border=0>" & _
       vbcrlf&"  <tr>" & _
       vbcrlf&"  <td><input type=submit class=btn value='确认更改'"&ds&"></td>" & _
       vbcrlf&"  <td width=5></td>" & _
       vbcrlf&"  <td><input type=button class=btn value='继续购物' onclick=""javascript:location.href='index.asp';""></td>" & _
       vbcrlf&"  <td width=5></td>" & _
       vbcrlf&"  <td><input type=button class=btn value='清空购物车' onclick=""javascript:shop_clear();"""&ds&"></td>" & _
       vbcrlf&"  <td width=5></td>" & _
       vbcrlf&"  <td><input type=button class=btn value='去收银台' onclick=""javascript:location.href='pay.asp';"""&ds&"></td>" & _
       vbcrlf&"  </tr>" & _
       vbcrlf&"  </table>" & _
       vbcrlf&"</td></tr>" & _
       vbcrlf&"<tr class=bg_td><td colspan=7 align=center><font class=red>注意：改变商品数量和减少商品种类需按“确认更改”按钮</font></td></tr>" & _
       vbcrlf&"</form>"
  erase sdim
  call shop_center_table(tit,tmp1,1,1)
end sub
%>