first commit

This commit is contained in:
编码猿
2024-09-27 01:32:49 +08:00
commit 28ebe05a64
7399 changed files with 1174529 additions and 0 deletions

View File

@@ -0,0 +1 @@
d2590945-a9c1-4e88-9507-de2bd20b4522

View File

@@ -0,0 +1,182 @@
// mall/shopcart/shopcart.js
const app = getApp();
const regeneratorRuntime = app.loadAsync()
const model = app.loadModel("index")
const http = app.loadHttp()
const util = app.loadUtils("util")
Page({
/**
* 组件的初始数据
*/
data: {
system: app.globalData.system, //设备相关信息
pageTitle: "购物车", //头部标题
isBack: true,//显示返回
right: [
{
text: '删除',
style: 'background-color: #F4333C; color: white',
}],
cartList: [],//购物车
total: 0,//购物车商品总价格
allShow: false,
isAllShow: false,//判断是否已经全选
postage:{},//邮费
},
//获取本地缓存中的购物车商品
async getCart() {
let cart = await model.shopCart.getCart()
cart.map((v, i) => {
cart[i].isShow = false
cart[i].allMon = (v.price * v.num).toFixed(2)
})
this.setData({
cartList: cart
})
this.getTotalPrice()
},
// 增加和减少商品数量
async handleChange1(e) {
let item = e.currentTarget.dataset.item
let value = e.detail.value
let cartList = this.data.cartList
item.num = value
// 更新购物车,返回最新购物车
let newCart = await model.shopCart.updateCart(item)
newCart.map((v, i) => {
for (let j = 0; j < cartList.length; j++) {
// 判断对应数据,来修改对应的isShow
if (util.Compare(v, cartList[j], "num")) {
newCart[i].isShow = cartList[j].isShow
newCart[i].allMon = (v.price * v.num).toFixed(2)
}
}
})
this.setData({
cartList: newCart
})
this.getTotalPrice()
},
// 侧滑删除事件
async onClick(e) {
let that = this
let item = e.currentTarget.dataset.item
item.num = 0
// 更新购物车,返回最新购物车
let newCart = await model.shopCart.updateCart(item)
newCart.map((v, i) => {
newCart[i].allMon = (v.price * v.num).toFixed(2)
})
that.setData({
cartList: newCart
})
that.getTotalPrice()
model.msg.dataMsg({
content: "删除成功",
type: "success"
})
},
// 计算选中的总价格
getTotalPrice() {
let cartList = this.data.cartList
let total = 0
cartList.map((v, i) => {
if (v.isShow) {
total += v.num * v.price
}
})
this.setData({
total: total.toFixed(2)
})
// 总价格同步到全局变量中
app.globalData.temCart.total = total.toFixed(2)
},
// 商品的勾选事件
checklist(e) {
let that = this
let index = e.currentTarget.dataset.index
let cartList = this.data.cartList
let allShow = false //如果为true说明全部数据都全选
let arr1 = []
if (cartList.length <= 0) {
return
}
// 如果为-1说明是全选
if (index == -1 && !this.data.isAllShow) {
this.setData({
isAllShow: true
})
cartList.map((v, i) => {
cartList[i].isShow = true
})
} else if (this.data.isAllShow && index == -1) {
this.setData({
isAllShow: false
})
cartList.map((v, i) => {
cartList[i].isShow = false
})
} else {
this.setData({
isAllShow: false
})
cartList[index].isShow = !cartList[index].isShow
}
// 每次勾选时判断是否已经全选
cartList.map((v, i) => {
arr1.push(v.isShow)
})
if (arr1.indexOf(false) == -1) {
allShow = true
}
this.setData({
cartList: cartList,
allShow: allShow
})
this.getTotalPrice()
},
// 商品提交事件
async placeOrder() {
let isLogin = await util.isLoginJump()
if (isLogin == 1) return;
let cartList = this.data.cartList
let newCart = []
cartList.map((v, i) => {
if (v.isShow) {
newCart.push(v)
}
})
app.globalData.temCart.allCart = newCart
if (newCart.length <= 0) {
return
}
wx.navigateTo({
url: "/mall/placeOrder/placeOrder"
})
},
// 获取当前邮费配置
async postage() {
let res = await http.http.request1({ url: `${http.api.postage}`, method: "POST", data: { type: 1 } })
if (res.data.status) {
this.setData({
postage: res.data.data
})
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad() {
this.postage()
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
this.setData({
total: 0,
allShow: false
})
this.getCart()
},
})

View File

@@ -0,0 +1,10 @@
{
"component": true,
"usingComponents": {
"wux-input-number": "../../extend/wux/dist/input-number/index",
"wux-swipe-action": "../../extend/wux/dist/swipe-action/index",
"wux-cell-group": "../../extend/wux/dist/cell-group/index",
"wux-cell": "../../extend/wux/dist/cell/index",
"i-input-number": "../../extend/iview/dist/input-number/index"
}
}

View File

@@ -0,0 +1,65 @@
<!-- 头部 -->
<nav-bar isBack="{{isBack}}" pageTitle="{{pageTitle}}" system="{{system}}"></nav-bar>
<!-- mall/shopcart/shopcart.wxml -->
<view class="shopcart">
<view class="shop_list">
<view wx:for="{{ cartList }}" wx:key="{{index}}" data-index="{{index}}" catchtap="checklist">
<wux-cell-group>
<wux-swipe-action autoClose right="{{ right }}" data-item="{{ item }}" bind:click="onClick">
<view class="shop_list_row" wx:if="{{ item.num != 0 }}">
<view class="shop_select">
<image src="{{item.isShow ? '/static/img/icon/wxPay2.png' : '/static/img/icon/wxPay1.png' }}" />
</view>
<view class="shop_info">
<view class="shop_img">
<image src="{{item.image}}" />
</view>
<view class="shop_info_p">
<view class="shop_info_title">
<view class="shop_title">{{item.name}}</view>
<view class="shop_j">
<span class="mr10" wx:if="{{ !!item.attr && item.attr.length >=0 }}" wx:for="{{item.attr}}" wx:key wx:for-item="list" >{{list}}</span>
</view>
</view>
<view class="shop_mon_num">
<view class="mon">¥{{item.allMon}}</view>
<view class="num">
<i-input-number i-class="my-i-number" data-item="{{ item }}" value="{{ item.num }}" min="0" max="100" bindchange="handleChange1" />
</view>
</view>
</view>
</view>
</view>
</wux-swipe-action>
</wux-cell-group>
</view>
</view>
<!-- 购物车为空时 -->
<view wx:if="{{ cartList.length <= 0 }}" class="cart_kong">
<view>
<image src="/static/img/icon/cart-kong.png" />
<view class="cart_kong_p">购物车空空如也~</view>
</view>
</view>
</view>
<view class="cart_sub">
<!-- <view class="cart_tips">
<view class="cart_tips_p">不满{{postage.satisfy_money}}元包邮,配送费¥{{postage.postage_money}}</view>
<view class="add_shop">继续凑单 ></view>
</view> -->
<view class="cart_but">
<view class="cart_in">
<view class="cart_all" data-index="-1" bind:tap="checklist">
<image src="{{ allShow ? '/static/img/icon/wxPay2.png' : '/static/img/icon/wxPay1.png' }}" />
全选
</view>
<view class="all_num">
<span>(不含运费)</span>
合计:¥{{total}}
</view>
</view>
<view class="purchase flex-con3" bind:tap="placeOrder">立即购买</view>
</view>
</view>
<!-- toasta提示 -->
<i-toast id="toast" />

View File

@@ -0,0 +1,249 @@
/* mall/shopcart/shopcart.wxss */
page {
height: 100%;
}
.mr10 {
margin-right: 10rpx;
}
.shopcart {
padding: 20rpx;
padding-bottom: 280rpx;
}
.shop_list {
background-color: #fff;
}
.shop_list_row {
height: 200rpx;
display: flex;
padding: 0 35rpx;
-webkit-align-items: center;
align-items: center;
border-bottom: #ebebeb solid 2rpx;
background: #fff;
}
.shop_list_row:last-child {
border: 0;
}
.shop_select {
line-height: 200rpx;
}
.shop_select image {
margin-right: 25rpx;
width: 35rpx;
height: 35rpx;
}
.shop_info {
flex: 1;
display: flex;
}
.shop_img {
margin-right: 20rpx;
height: 150rpx;
width: 150rpx;
background: #1dbf53;
}
.shop_img image {
height: 100%;
width: 100%;
}
.shop_info_p {
flex: 1;
display: flex;
flex-flow: column;
}
.shop_info_title {
flex: 1;
}
.shop_title {
font-family: PingFang-SC-Bold;
font-size: 30rpx;
color: #333;
font-weight: 600;
display: -webkit-box !important;
-webkit-box-orient: vertical;
-webkit-line-clamp: 1;
overflow: hidden;
}
.shop_j {
margin-top: 10rpx;
font-family: PingFang-SC-Medium;
font-size: 22rpx;
color: #999;
}
.shop_mon_num {
display: flex;
-webkit-align-items: center;
align-items: center;
}
.mon {
flex: 1;
font-family: PingFang-SC-Bold;
font-size: 32rpx;
color: #ff4737;
}
.wux_sub {
border: 0 !important;
color: #272727 !important;
}
.wux_input {
border: 0 !important;
background-color: #f5f5f5 !important;
}
.wux_add {
border: 0 !important;
color: #272727 !important;
}
.my-i-number view, .my-i-number input {
border: 0 !important;
}
.my-i-number input {
background-color: #f5f5f5 !important;
}
.cart_sub {
position: fixed;
bottom: 0;
left: 0;
right: 0;
width: 100%;
background-color: #fff;
border-bottom: 2rpx solid #e9e9e9;
z-index: 99999;
}
.cart_tips {
height: 80rpx;
background-color: #fcf0f0;
display: flex;
display: -webkit-flex;
-webkit-align-items: center;
align-items: center;
-webkit-justify-content: center;
justify-content: center;
padding: 0 27rpx 0 38rpx;
}
.cart_tips_p {
flex: 1;
text-align: left;
font-size: 24rpx;
color: #666;
}
.add_shop {
font-size: 24rpx;
color: #1dbf53;
}
.cart_but {
/* height: 100rpx; */
display: flex;
display: -webkit-flex;
-webkit-align-items: center;
align-items: center;
-webkit-justify-content: center;
justify-content: center;
padding-bottom: calc(env(safe-area-inset-bottom) / 2);
height: calc(100rpx + env(safe-area-inset-bottom) / 2);
}
.cart_in {
height: 100%;
flex: 1;
display: flex;
}
.purchase {
width: 260rpx;
height: 100rpx;
text-align: center;
line-height: calc(100rpx + env(safe-area-inset-bottom) / 2);
background-color: #1dbf53;
font-size: 32rpx;
color: #fff;
}
.cart_all {
flex: 1;
height: 100%;
padding-left: 45rpx;
display: -webkit-flex;
-webkit-align-items: center;
align-items: center;
}
.cart_all image {
width: 35rpx;
height: 35rpx;
margin-right: 17rpx;
}
.all_num {
padding-right: 14rpx;
font-size: 30rpx;
color: #333;
font-weight: 600;
display: flex;
display: -webkit-flex;
-webkit-align-items: center;
align-items: center;
}
.all_num span {
font-size: 22rpx;
color: #999;
font-weight: 400;
}
.cart_kong {
height: 600rpx;
width: 100%;
text-align: center;
display: flex;
display: -webkit-flex;
-webkit-align-items: center;
align-items: center;
-webkit-justify-content: center;
justify-content: center;
}
.cart_kong image {
width: 104rpx;
height: 88rpx;
}
.cart_kong_p {
margin-top: 33rpx;
font-family: PingFang-SC-Medium;
font-size: 26rpx;
color: #999;
}
.delete_tips {
text-align: right;
font-size: 24rpx;
color: #999;
margin-bottom: 5rpx;
}