加入购物车列表 HTML + CSS + js

HTML

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="./js/购物.js" type="module"></script>
    <link rel="stylesheet" href="./购物.css" />
  </head>
  <body>
    <div class="main">
      <span class="list">购物车列表</span>
    </div>

    <div class="container2">
      <!-- 订单列表 -->
      <div class="cart-panel">
        <div class="hd">
          <ul class="order-title">
            <li class="selecter"></li>
            <li class="product">商品名称</li>
            <li class="market-price">市场价</li>
            <li class="order-price">订购价(8折)</li>
            <li class="num">数量</li>
            <li class="operate">操作</li>
          </ul>
        </div>
        <div class="bd"></div>
      </div>
      <!-- 订单列表 end-->
      <!-- 结算 -->
      <div class="set-bar">
        <div class="set-info">
          <div class="set-stat">
            应付金额:
            <div class="price">
              <span class="price-sign">¥</span>
              <span class="price-num" id="totalMoney"></span>
            </div>
          </div>
        </div>
        <button class="btn btn-primary btn-lg" type="button" id="jiesuan">
          <a onclick="payfun()">去结算</a>
        </button>
        <button class="btn-dele" onclick="chedel()">选中删除</button>
        <button class="btn-dele1">清空购物车</button>
        <input
          type="checkbox"
          class="asd"
          value="全选"
          id="cele"
          onchange="cheupdata()"
        />
      </div>
      <!-- 结算 End -->
    </div>
  </body>
</html>

js

import {
  ranshopliat,
  deleshopliat,
  clearshop,
  selectshop,
  cartNumSub,
  removereq,
  selectAllReg,
  payReg,
} from "./api.js";
let bd = document.querySelector(".bd");
let id = localStorage.getItem("uid");
let isnone;
ran();
function ran() {
  ranshopliat(id).then((r) => {
    console.log(r.data.cart);
    let str = r.data.cart.map((v) => {
      return `
      <ul class="order-list">
      <li class="selecter">
          <i class="icon-select active"></i>
      </li>
      <li class="img-box">
      <input type="checkbox" name="" id="box"  ${
        v.is_select ? "checked" : ""
      } onclick='che(${v.goods_id})'>
          <a href="#" target="_blank">
            <img src="${v.img_small_logo}" />
          </a>
      </li>
      <li class="product">
          <a href="#" target="_blank">
            <span class="product-title" style="line-height: 40px"
              >${v.title}</span
            >
            <span class="feature"></span>
          </a>
      </li>
      <li class="market-price">
          <span class="price-sign">¥</span>
          <span class="price-num">${v.price}</span>
      </li>
      <li class="order-price">
          <span class="price-sign">¥</span>
          <span class="price-num">${v.current_price}</span>
      </li>
      <li class="num">
          <div class="number-box">
              <input type="button" class="sub-number" value="-" onclick="delran(${
                v.goods_id
              },${v.cart_number})"/>
              <input type="text" value="${v.cart_number}" class="txt-num" />
              <input type="button" class="add-number" value="+" onclick="addran(${
                v.goods_id
              },${v.cart_number})"/>
          </div>
      </li>
      <li class="operate">
          <a href="javascript:void(0)" class="delBtn" onclick="btn(${
            v.goods_id
          })">删除</a>
      </li>
  </ul>   
      `;
    });
    bd.innerHTML = str.join("");

    isnone = v.is_select.filter((item) => item.is_select == true);
    document.querySelector("#cele").checked = isnone;
    if (isnone != isnone) {
      document.querySelector("#isAll").checked = "";
    }
  });
}

let uid = localStorage.getItem("uid");
window.btn = function (goodsId) {
  deleshopliat(uid, goodsId).then((r) => {
    console.log(r);
    // location.relode();
    // history.go(0);
    ran();
  });
};

//清空购物车
let clear = document.querySelector(".btn-dele1");
clear.onclick = function () {
  let uid = localStorage.getItem("uid");
  clearshop(uid).then((r) => {
    console.log(r);
    // history.go(0);
    ran();
  });
};

//修改状态
window.che = function (id) {
  // console.log(id)
  let uid = localStorage.getItem("uid");
  selectshop(uid, id).then((r) => {
    console.log(r.data);
  });
};

//减减
window.delran = function (id, number) {
  console.log(number);
  //   let newNum = ++cartNum;
  if (number == 1) {
    let f = confirm("是否要删除");
    if (f) btn(id);
    return;
  }
  let newNum = number - 1;
  console.log(newNum);
  cartNumSub(uid, id, newNum);
  ran();
};
//加加
window.addran = function (id, number) {
  console.log(number);
  let newNum = number + 1;
  console.log(newNum);
  cartNumSub(uid, id, newNum);
  ran();
};

// 选中删除
window.chedel = function () {
  let uid = localStorage.getItem("uid");
  removereq(uid).then((r) => {
    console.log(r.data);
    document.querySelector(".asd").checked = "";
    ran();
  });
};

//全选
// let isnone;
window.cheupdata = function () {
  // console.log(11);
  // ran()
  let uid = localStorage.getItem("uid");
  isnone = !isnone;
  console.log(isnone);
  let type = isnone ? 1 : 0;
  selectAllReg(uid, type).then((r) => {
    console.log(r);
    ran();
  });
};

///结算

window.payfun = function () {
  let uid = localStorage.getItem("uid");
  console.log("结算");
  // location.href = "./结账.html";
  payReg(uid).then((r) => {
    console.log(r.data);
    // location.href = "./结账.html";
    // let a = r.data;
    alert(r.data.message);
  });
};

css

/* 重置基础样式 */
* {
	margin: 0;
	padding: 0;
}

.main {
	width: 100%;
	height: 70px;
	background-color: #ffe2e2;
	text-align: center;
  }
  .list {
	font-size: 30px;
	line-height: 70px;
	font-weight: 500;
	color: #848484;
  }
  #box {
	width: 20px;
	height: 20px;
	/* word-wrap: 200px; vertical-align: auto; */
	margin-right: 50px;
  }
  .asd {
	float: right;
	width: 30px;
	height: 30px;
	margin: 20px;
  }
.container2 a {
	color: #333333;
	text-decoration: none;
}
 
.container2 a:hover {
	color: darksalmon;
}
 
/* 订单列表 */
.container2 {
	width: 990px;
	border-top: 1px solid #E9ECF0;
	margin: 20px auto 120px;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
.container2 .cart-panel {
	margin-bottom: 20px;
	border: 1px solid #d9d9d9;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
.cart-panel .hd {
	height: 46px;
	margin: 0;
	padding: 0 20px;
	list-style: none;
	background-color: #ebebeb;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
.cart-panel .order-title {
	margin: 0;
	padding: 0;
	list-style: none;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
.cart-panel .order-title:before,
.cart-panel .order-title:after {
	content: " ";
	display: table;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
.cart-panel .order-title li.selecter {
	width: 36px;
	height: 40px;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
.cart-panel .order-title li {
	font-family: tahoma, arial, 'Hiragino Sans GB', '\5FAE\8F6F\96C5\9ED1', sans-serif;
	font-weight: bold;
	display: inline-block;
	float: left;
	padding: 10px 0;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
.cart-panel .order-title li.product {
	width: 432px;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;

}
 
.cart-panel .order-title li.market-price,
.cart-panel .order-title li.order-price,
.cart-panel .order-title li.num,
.cart-panel .order-title li.operate {
	text-align: center;
	width: 120px;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
 
 
 
.cart-panel .bd {

	margin: 0;
	padding: 0 20px;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
.cart-panel .order-list:first-child {
	border-top: none;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
.cart-panel .order-list {
	font-size: 12px;
	margin: 0;
	padding: 15px 0;
	list-style: none;
	border-top: 2px dotted #d9d9d9;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
.cart-panel .order-list:before,
.cart-panel .order-list:after {
	content: " ";
	display: table;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
.cart-panel .order-list:after {
	clear: both;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
.cart-panel .order-list .selecter {
	width: 36px;
	height: 88px;
	text-align: left;
	cursor: pointer;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
.cart-panel .order-list li {
	line-height: 40px;
	display: inline-block;
	float: left;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
.cart-panel .order-list .selecter .icon-select {
	width: 20px;
	height: 20px;
	margin-top: 34px;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
.cart-panel .order-list .icon-select {
	display: inline-block;
	background-repeat: no-repeat;
	background-size: contain;
	background-position: center;
	background-image: url(../img/ico_unchecked.png);
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
.cart-panel .order-list .icon-select.active {
	background-image: url(../img/ico_checkout.png);
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
.cart-panel .order-list li.img-box {
	width: 100px;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
.cart-panel .order-list li.img-box img {
	width: 80px;
	height: 88px;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
.cart-panel .order-list li.product {
	width: 332px;
	padding: 24px 0;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
	overflow: hidden;
    text-overflow: ellipsis;
}
 
.cart-panel .order-list li.product span {
	white-space: nowrap;
	text-overflow: ellipsis;
	overflow: hidden;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
.cart-panel .order-list li.product .feature {
	color: #ff6a00;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
.cart-panel .order-list li.market-price {
	width: 120px;
	padding: 0;
	line-height: 88px;
	text-decoration: line-through;
	color: #999999;
	text-align: center;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
.price-sign {
	font-family: arial;
	margin-right: -4px;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
.price-num {
	font-family: arial, Verdana, Arial;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
.cart-panel .order-list li.order-price {
	width: 118px;
	padding: 0;
	line-height: 88px;
	color: #232628;
	font-weight: normal;
	text-align: center;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
.cart-panel .order-list li.num {
	width: 122px;
	line-height: 88px;
	text-align: center;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
.cart-panel .order-list:after {
	clear: both;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
.cart-panel .order-list li.operate {
	width: 120px;
	font-size: 12px;
	padding: 24px 0 24px 42px;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
/* 结算 */
.set-bar {
	margin-bottom: 30px;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
.set-bar .set-info {
	font-size: 12px;
	line-height: 52px;
	float: left;
	width: 870px;
	height: 52px;
	padding: 0 20px;
	border: 1px solid #d9d9d9;
	border-right: 0;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
.set-bar .set-info .set-stat {
	float: right;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
.set-bar .set-info .set-stat .price {
	font-size: 18px;
	font-weight: bold;
	display: inline-block;
	color: #ff6a00;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
 
.set-bar .btn-lg {
	font-weight: bold;
	float: right;
	width: 120px;
	height: 52px;
	padding: 10px 16px;
	font-size: 18px;
	line-height: 1.3333333;
	color: #ffffff;
	background-color: #ff6a00;
	border-color: #ff6a00;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
 .btn-dele {
	font-weight: bold;
	float: right;
	width: 120px;
	height: 52px;
	padding: 10px 16px;
	font-size: 18px;
	line-height: 1.3333333;
	color: #ffffff;
	background-color: #9ab2f8;
	border-color: #9ab2f8;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 .btn-dele1 {
	font-weight: bold;
	float: right;
	width: 200px;
	height: 52px;
	padding: 10px 16px;
	font-size: 18px;
	line-height: 1.3333333;
	color: #ffffff;
	background-color: #9ab2f8;
	border-color: #9ab2f8;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
 
/* 加减按钮样式 */
.number-box {
	border: #e5e5e5 solid 1px;
	display: inline-block;
	margin-top: 26px;
	overflow: hidden;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
.number-box input[type='text'] {
	height: 30px;
	border-top: none;
	border-bottom: none;
	border-left: #e5e5e5 solid 1px;
	border-right: #e5e5e5 solid 1px;
	margin: 0;
	text-align: center;
	width: 40px;
	outline: none;
	padding: 0 5px;
	float: left;
	line-height: 30px;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
.number-box input[type='button'] {
	height: 30px;
	width: 40px;
	float: left;
	border: none;
	outline: none;
	background-color: #f3f3f3;
	line-height: 30px;
	cursor: pointer;
	padding: 0;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
.number-box input[type='button']:hover {
	background-color: #f9f9f9;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
 
.number-box input[type='button']:active {
	background-color: #f6f6f6;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
}
#jiesuan>a{
	color: white;
}

效果展示

 

  • 2
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值