3
0
Fork 0
web-store-retail-h5/components/cartBtmList.vue

879 lines
21 KiB
Vue
Raw Permalink Normal View History

2025-03-23 09:29:40 +08:00
<!--
* @Descripttion:
* @version:
2025-03-23 09:29:40 +08:00
* @Author: kBank
* @Date: 2022-11-21 15:11:22
-->
<template>
<view class="content">
<view class="context">
<view
class="kuang"
v-for="(item, index) in shopCarList"
:key="item.specialArea"
>
<view
v-for="(ctem, cndex) in item.shoppingCartList"
:key="cndex"
class="goodList"
>
<!-- <u-checkbox activeColor="red"
:name="ctem.shoppingId"></u-checkbox> -->
<view class="goodList_i">
<view class="goodList_it">
<img :src="ctem.cover1" class="cover" alt="" />
<view class="goodList_ir">
<view class="tit1">
{{ ctem.waresName }}
</view>
<view class="goodList_ib">
<view class="tit2">
{{ ctem.waresPrice | numberToCurrency | isLocal }}
</view>
<view class="tit3"
>业绩: {{ ctem.achieve | numberToCurrency | isLocal }}</view
2025-03-23 09:29:40 +08:00
>
</view>
</view>
</view>
<view
v-for="(stem, sndex) in ctem.productParams"
:key="sndex"
class="product_i"
>
<img :src="stem.cover" alt="" />
<view class="product_il">
<view class="tit4"
>{{ stem.productName
}}{{
(stem.waresItemsParamsList.length > 0 &&
stem.waresItemsParamsList[0].specsName) ||
''
2025-03-23 09:29:40 +08:00
}}</view
>
<!-- <view class="tit4"></view> -->
<view class="tit5"
>x{{
(stem.waresItemsParamsList.length > 0 &&
stem.waresItemsParamsList[0].quantity) ||
''
2025-03-23 09:29:40 +08:00
}}</view
>
</view>
</view>
<view class="goodsSet">
<u-number-box
:min="1"
@change="changeCar($event, item, ctem)"
v-model="ctem.number"
></u-number-box>
<u-icon
name="trash"
@tap="delOne(ctem)"
size="26"
color="#BFBFBF"
></u-icon>
</view>
</view>
</view>
<!-- </u-checkbox-group> -->
</view>
</view>
<view class="kong_t" v-show="cartEmpty">
2025-03-23 09:29:40 +08:00
<img class="kong" src="@/static/images/kong.png" alt=""
/></view>
<view class="zhan"></view>
<!-- 底部 -->
<view class="footer_f">
<view class="footer">
<view class="footer_l">
<view class="footer_ll">
<u-icon size="36" name="shopping-cart"> </u-icon>
<view class="footer_lr">
<view class="r1">{{
totalPrice | numberToCurrency | isLocal
}}</view>
<view class="l1">业绩:{{ totalAchive | numberToCurrency }}</view>
2025-03-23 09:29:40 +08:00
</view>
</view>
</view>
<view class="footer_r">
<u-button
type="success"
class="uBtn"
shape="circle"
:loading="isLoading"
:loadingText="'购买中'"
2025-03-23 09:29:40 +08:00
@tap="goBuy"
:disabled="submitDisabled"
2025-04-22 17:47:02 +08:00
color="#005BAC"
>{{ '去结算' }}
2025-03-23 09:29:40 +08:00
</u-button>
</view>
</view>
</view>
<view class="pp">
<u-popup
:show="dialogVisible2"
:closeable="true"
:closeOnClickOverlay="false"
mode="center"
@close="dialogVisible2 = false"
>
<view class="popList">
<u-checkbox-group
v-model="allTable"
placement="column"
@change="handleSelectionChange"
>
<view class="popList_i" v-for="item in tableData" :key="item.pkId">
<u-checkbox :name="item.pkId"> </u-checkbox>
<view class="popList_ii">
<img :src="item.cover1" alt="" />
<view>
<view>{{ item.waresName }}</view>
<view>{{ item.waresCode }}</view>
<view>{{ item.waresPrice }}</view>
<!-- <view>{{ item.quantity }}</view> -->
<u-number-box v-model="item.quantity" :min="1"></u-number-box>
</view>
</view>
</view>
</u-checkbox-group>
<view class="popBtm">
<view>合计:{{ total | toThousandthAndKeepDecimal }}</view>
<view class="que" @click="tableTrue">确定</view>
</view>
</view>
</u-popup>
</view>
</view>
</template>
<script>
import * as api from '@/config/goods'
2025-06-10 09:21:43 +08:00
import {
REGIEST_AREA,
UPGRADE_AREA,
REPURCHASE_AREA,
REISSUE_AREA,
} from '@/util/specialAreaMap'
import { MEMBER_SIGN } from '@/util/common'
2025-03-23 09:29:40 +08:00
export default {
data() {
return {
isSelectAll: [],
shopCarList: [],
isLoading: false,
isTo: 0,
goodsCheck: [],
totalPrice: 0,
totalAchive: 0,
num: 0,
pkCountry: 1,
specialArea: 1,
userInfo: {},
tableData: [],
dialogVisible2: false,
selTable: [],
allTable: [],
total: '0.00',
2025-03-23 09:29:40 +08:00
// show:false,
// title:'提示',
2025-03-23 09:29:40 +08:00
// content:'确认删除该商品?'
}
2025-03-23 09:29:40 +08:00
},
computed: {
submitDisabled() {
if (this.goodsCheck[0]?.orderItemsParams) {
return this.goodsCheck[0]?.orderItemsParams?.length === 0
}
return true
},
cartEmpty() {
return (
this.shopCarList.length === 0 ||
this.shopCarList[0]?.shoppingCartList?.length === 0
)
},
},
2025-03-23 09:29:40 +08:00
watch: {
selTable: {
handler(n, o) {
let total = 0
n.forEach(item => {
total += Number(item.waresPrice) * item.quantity
})
this.total = total
2025-03-23 09:29:40 +08:00
},
deep: true,
},
},
props: {
areas: {
type: Number | String,
default: 1,
},
},
onLoad(options) {
// this.getCarList()
},
onShow() {
// this.getCarList()
},
methods: {
tableTrue() {
if (this.selTable.length > 0) {
let a = {
specialArea: this.goodsCheck[0].specialArea,
orderItemsParams: [],
}
a.orderItemsParams = this.selTable.map(item => {
2025-03-23 09:29:40 +08:00
return {
waresCode: item.waresCode,
quantity: item.quantity,
waresItemsParamList: item.productGroup,
energySilo: 1,
}
})
a.orderItemsParams.forEach(item => {
item.waresItemsParamList = item.waresItemsParamList.map(ctem => {
2025-03-23 09:29:40 +08:00
return {
pkWaresSpecsSku: ctem.pkSkuId,
quantity: ctem.quantity,
}
})
})
api.energyShopSilo(a).then(res => {
2025-03-23 09:29:40 +08:00
if (res.code == 200) {
this.dialogVisible2 = false
let shoppArr = this.goodsCheck[0].orderItemsParams.map(item => {
return item.shoppingId
})
2025-03-23 09:29:40 +08:00
if (this.goodsCheck[0].specialArea == 1) {
uni.navigateTo({
url:
'/pages/regiest/index?specialArea=' +
2025-03-23 09:29:40 +08:00
this.goodsCheck[0].specialArea +
'&shoppArr=' +
2025-03-23 09:29:40 +08:00
JSON.stringify(shoppArr) +
'&selTable=' +
2025-03-23 09:29:40 +08:00
JSON.stringify(this.selTable),
})
2025-03-23 09:29:40 +08:00
} else if (this.goodsCheck[0].specialArea == 2) {
uni.navigateTo({
url:
'/pages/other/index?specialArea=' +
2025-03-23 09:29:40 +08:00
this.goodsCheck[0].specialArea +
'&shoppArr=' +
2025-03-23 09:29:40 +08:00
JSON.stringify(shoppArr) +
'&selTable=' +
2025-03-23 09:29:40 +08:00
JSON.stringify(this.selTable),
})
2025-03-23 09:29:40 +08:00
}
}
})
2025-03-23 09:29:40 +08:00
} else {
uni.showToast({
title: '请选择赠品',
icon: 'none',
})
2025-03-23 09:29:40 +08:00
}
},
handleSelectionChange(val) {
let arr = []
this.tableData.forEach(item => {
val.forEach(ctem => {
2025-03-23 09:29:40 +08:00
if (item.pkId == ctem) {
arr.push(item)
2025-03-23 09:29:40 +08:00
}
})
})
this.selTable = arr
2025-03-23 09:29:40 +08:00
},
selectAll(e) {
let i = 0
2025-03-23 09:29:40 +08:00
// isSelected
if (e.length > 0) {
this.shopCarList.forEach(item => {
item.isSelected = true
item.shoppingCartList.forEach(ctem => {
ctem.isSelected = true
item.isSelect.push(ctem.shoppingId)
})
})
this.shopCarList.forEach(item => {
2025-03-23 09:29:40 +08:00
if (item.isSelected) {
i++
2025-03-23 09:29:40 +08:00
}
})
this.isTo = i
2025-03-23 09:29:40 +08:00
// this.checkArea()
} else {
this.shopCarList.forEach(item => {
item.isSelected = false
item.shoppingCartList.forEach(ctem => {
ctem.isSelected = false
item.isSelect = []
})
})
this.shopCarList.forEach(item => {
2025-03-23 09:29:40 +08:00
if (item.isSelected) {
i++
2025-03-23 09:29:40 +08:00
}
})
this.isTo = i
2025-03-23 09:29:40 +08:00
// this.checkArea()
}
},
delAll() {
let arr = []
this.shopCarList.forEach(item => {
item.isSelect.forEach(ctem => {
2025-03-23 09:29:40 +08:00
arr.push({
shoppingId: ctem,
})
})
})
api.batchDelShopping({ deleteList: arr }).then(res => {
this.getCarList()
2025-03-23 09:29:40 +08:00
// this.getShoppingCount()
uni.showToast({
title: '删除成功',
icon: 'none',
2025-03-23 09:29:40 +08:00
duration: 1500,
})
})
2025-03-23 09:29:40 +08:00
},
goBuy() {
let shoppArr = this.goodsCheck[0].orderItemsParams.map(item => {
return item.shoppingId
})
uni.setStorageSync('allGoods', JSON.stringify(shoppArr))
2025-03-23 09:29:40 +08:00
if (
2025-06-10 09:21:43 +08:00
[REGIEST_AREA.id, UPGRADE_AREA.id].includes(
this.goodsCheck[0].specialArea
)
2025-03-23 09:29:40 +08:00
) {
let deleteList = []
shoppArr.forEach(item => {
2025-03-23 09:29:40 +08:00
deleteList.push({
shoppingId: item,
})
})
const area =
this.goodsCheck[0].specialArea == REGIEST_AREA.id
? 'regiest'
: 'upgrade'
2025-04-07 11:21:11 +08:00
uni.navigateTo({
url:
`/pages/${area}/index?specialArea=` +
2025-03-23 09:29:40 +08:00
this.goodsCheck[0].specialArea +
'&shoppArr=' +
2025-03-23 09:29:40 +08:00
JSON.stringify(shoppArr),
})
2025-03-23 09:29:40 +08:00
} else {
if (this.goodsCheck[0].specialArea == 30) {
2025-03-23 09:29:40 +08:00
if (this.goodsCheck[0].orderItemsParams.length > 1) {
uni.showToast({
title: '续约专区每次只能购买一件商品',
icon: 'none',
})
return false
2025-03-23 09:29:40 +08:00
} else {
let num = this.goodsCheck[0].orderItemsParams.some(
item => item.quantity > 1
)
2025-03-23 09:29:40 +08:00
if (num) {
uni.showToast({
title: '续约专区每次只能购买一件商品',
icon: 'none',
})
return false
2025-03-23 09:29:40 +08:00
} else {
uni.navigateTo({
url:
'/pages/other/index?specialArea=' +
2025-03-23 09:29:40 +08:00
this.goodsCheck[0].specialArea +
'&shoppArr=' +
2025-03-23 09:29:40 +08:00
JSON.stringify(shoppArr),
})
2025-03-23 09:29:40 +08:00
}
}
} else {
2025-03-23 09:29:40 +08:00
uni.navigateTo({
url:
'/pages/other/index?specialArea=' +
2025-03-23 09:29:40 +08:00
this.goodsCheck[0].specialArea +
'&shoppArr=' +
2025-03-23 09:29:40 +08:00
JSON.stringify(shoppArr),
})
2025-03-23 09:29:40 +08:00
}
}
},
// 修改数量
changeCar(e, item, ctem) {
api
.plusReduceShopping({
shoppingId: ctem.shoppingId,
number: e.value,
specialArea: item.specialArea,
})
.then(res => {
2025-03-23 09:29:40 +08:00
if (res.code == 200) {
this.dealData()
2025-03-23 09:29:40 +08:00
} else {
this.getCarList()
2025-03-23 09:29:40 +08:00
}
// this.getShoppingCount()
})
2025-03-23 09:29:40 +08:00
},
// 计算价格
checkPrice() {
let totalPrice = 0
let totalAchive = 0
let num = 0
this.goodsCheck.forEach(item => {
item.orderItemsParams.forEach(ctem => {
totalPrice += parseFloat(ctem.waresPrice * ctem.quantity)
totalAchive += parseFloat(ctem.achieve * ctem.quantity)
num += ctem.quantity
})
})
2025-03-23 09:29:40 +08:00
// if (this.goodsCheck.length != 1) {
this.totalPrice = totalPrice.toFixed(2)
this.totalAchive = totalAchive.toFixed(2)
this.num = num
2025-03-23 09:29:40 +08:00
// }
},
checkboxChange(e, item) {
if (e.length > 0) {
this.$set(item, 'isSelected', true)
this.$set(item, 'isSelect', e)
2025-03-23 09:29:40 +08:00
// this.checkArea()
} else {
this.$set(item, 'isSelected', false)
this.$set(item, 'isSelect', e)
2025-03-23 09:29:40 +08:00
// this.checkArea()
}
let i = 0
this.shopCarList.forEach(item => {
2025-03-23 09:29:40 +08:00
if (item.isSelected) {
i++
2025-03-23 09:29:40 +08:00
}
})
this.isTo = i
let blin = true
this.shopCarList.forEach(item => {
2025-03-23 09:29:40 +08:00
if (item.isSelect.length != item.shoppingCartList.length) {
blin = false
2025-03-23 09:29:40 +08:00
}
})
2025-03-23 09:29:40 +08:00
if (blin) {
this.isSelectAll = [1]
2025-03-23 09:29:40 +08:00
} else {
this.isSelectAll = []
2025-03-23 09:29:40 +08:00
}
},
// 单删
delOne(ctem) {
let deleteList = [
{
shoppingId: ctem.shoppingId,
},
]
api.batchDelShopping({ deleteList: deleteList }).then(res => {
this.getCarList()
2025-03-23 09:29:40 +08:00
// this.getShoppingCount()
uni.showToast({
title: '删除成功',
icon: 'none',
2025-03-23 09:29:40 +08:00
duration: 1500,
})
})
2025-03-23 09:29:40 +08:00
},
getCarList(specialArea) {
if (specialArea) {
this.specialArea = specialArea
this.userInfo = uni.getStorageSync('User')
2025-03-23 09:29:40 +08:00
if (this.specialArea == 1) {
if (uni.getStorageSync('pkCountry')) {
this.pkCountry = uni.getStorageSync('pkCountry')
2025-03-23 09:29:40 +08:00
} else {
this.pkCountry = this.userInfo.pkSettleCountry
2025-03-23 09:29:40 +08:00
}
} else {
this.pkCountry = this.userInfo.pkSettleCountry
2025-03-23 09:29:40 +08:00
}
}
api
.getShopping({
specialArea: this.specialArea,
pkCountry: this.pkCountry,
})
.then(res => {
res.data.forEach(item => {
item.isSelected = false
item.isSelect = []
item.shoppingCartList.forEach(ctem => {
ctem.isSelected = false
ctem.waresItemsParamList = []
2025-03-23 09:29:40 +08:00
if (item.specialArea != 21) {
ctem.productParams.forEach(stem => {
2025-03-23 09:29:40 +08:00
if (stem.waresItemsParamsList.length > 0) {
stem.waresItemsParamsList[0].pkWaresSpecsSku =
stem.waresItemsParamsList[0].pkSkuId
stem.waresItemsParamsList[0].productName = stem.productName
ctem.waresItemsParamList.push(stem.waresItemsParamsList[0])
2025-03-23 09:29:40 +08:00
}
})
2025-03-23 09:29:40 +08:00
} else {
}
})
})
this.shopCarList = res.data
this.goPay()
this.dealData()
})
2025-03-23 09:29:40 +08:00
},
goPay() {
let arr = []
this.shopCarList.forEach(item => {
item.shoppingCartList.forEach(ctem => {
2025-03-23 09:29:40 +08:00
arr.push({
specialArea: item.specialArea,
orderItemsParams: [
{
waresCode: ctem.waresCode,
waresName: ctem.waresName,
achieve: ctem.achieve,
shoppingId: ctem.shoppingId,
waresPrice: ctem.waresPrice,
cover1: ctem.cover1,
source: ctem.source,
quantity: ctem.number,
waresItemsParamList: ctem.waresItemsParamList,
waresSkuList: ctem.waresSkuList || [],
},
],
})
})
})
2025-03-23 09:29:40 +08:00
const arrayHashmap = arr.reduce((obj, item) => {
obj[item.specialArea]
? obj[item.specialArea].orderItemsParams.push(
...item.orderItemsParams
)
: (obj[item.specialArea] = item)
return obj
}, {})
this.goodsCheck = Object.values(arrayHashmap)
2025-03-23 09:29:40 +08:00
},
// 处理数据
dealData() {
let arr = [
{
specialArea: this.shopCarList[0].specialArea,
orderItemsParams: [],
},
]
this.shopCarList[0].shoppingCartList.forEach(ctem => {
2025-03-23 09:29:40 +08:00
arr[0].orderItemsParams.push({
waresCode: ctem.waresCode,
waresName: ctem.waresName,
shoppingId: ctem.shoppingId,
achieve: ctem.achieve,
waresPrice: ctem.waresPrice,
cover1: ctem.cover1,
source: ctem.source,
quantity: ctem.number,
waresItemsParamList: ctem.waresItemsParamList,
waresSkuList: ctem.waresSkuList || [],
})
})
this.goodsCheck = arr
this.checkPrice()
2025-03-23 09:29:40 +08:00
},
},
}
2025-03-23 09:29:40 +08:00
</script>
<style lang="scss" scoped>
.content {
background: #f9f9f9;
height: 50vh;
overflow-y: auto;
}
.context {
// padding: 24rpx;
}
.kuang {
// padding: 20rpx 40rpx;
background: #fff;
box-shadow: 0px 2px 10px 0px rgba(204, 204, 204, 0.5); // border-top: 20rpx solid #f6f5f3;
}
.kuang_t {
border-bottom: 1px solid #eeeeee;
padding: 40rpx 24rpx;
}
.goodList {
display: flex;
padding: 0 20rpx;
border-bottom: 1px solid #eee;
}
.cover {
width: 136rpx;
height: 136rpx;
background: #ffffff;
border: 1px solid #eeeeee;
border-radius: 10rpx;
}
.goodList_i {
flex: 1;
}
.goodList_it {
display: flex;
padding: 20rpx 0;
.goodList_ir {
margin-left: 20rpx;
flex: 1;
display: flex;
flex-direction: column;
justify-content: space-between;
.goodList_ib {
display: flex;
align-items: center;
justify-content: space-between;
img {
width: 56rpx;
height: 56rpx;
}
}
}
}
.goodsSet {
display: flex;
justify-content: space-between;
align-items: center;
padding: 26rpx 0;
}
.product_i {
display: flex;
align-items: center;
background: #f6f6f6;
padding: 15rpx;
.product_il {
display: flex;
align-items: center;
flex: 1;
justify-content: space-between;
margin-left: 20rpx;
}
img {
width: 50rpx;
height: 50rpx;
background: #ffffff;
border: 1px solid #dddddd;
border-radius: 10rpx;
}
}
.tit1 {
font-size: 28rpx;
font-family: Source Han Sans CN;
font-weight: 400;
color: #333333;
}
.tit2 {
font-size: 36rpx;
font-family: Source Han Sans CN;
font-weight: bold;
2025-04-23 11:51:12 +08:00
color: #f82c1a;
2025-03-23 09:29:40 +08:00
}
.tit3 {
font-size: 26rpx;
font-family: Source Han Sans CN;
font-weight: 400;
color: #999999;
}
.tit4 {
font-size: 28rpx;
font-family: PingFang SC;
font-weight: 400;
color: #333333;
}
.tit5 {
font-size: 24rpx;
font-family: Source Han Sans CN;
font-weight: 400;
color: #999999;
}
.footer_f {
position: fixed;
bottom: 0;
width: 100%;
z-index: 10;
box-shadow: 0px -2px 20px 0px rgba(204, 204, 204, 0.5);
}
.footer {
display: flex;
justify-content: space-between;
padding: 20rpx 24rpx;
background: #fff;
.footer_l {
display: flex;
align-items: center;
.footer_ll {
position: relative;
display: flex;
align-items: center;
.pop {
position: absolute;
top: -16rpx;
right: -16rpx;
width: 28rpx;
height: 28rpx;
line-height: 28rpx;
background: #005bac;
2025-03-23 09:29:40 +08:00
box-shadow: 0rpx 3rpx 7rpx 0rpx rgba(0, 0, 0, 0.25);
border-radius: 50%;
text-align: center;
font-size: 22rpx;
font-family: Arial;
font-weight: bold;
color: #f1f2f7;
}
}
}
.footer_lr {
margin-left: 20rpx; // display: flex;
// align-items: center;
}
.footer_r {
// flex: 1;
display: flex;
align-items: center;
font-size: 20rpx;
font-weight: 500;
color: #333333;
}
}
.disFlex {
display: flex;
align-items: center;
}
.h1 {
font-size: 10px;
font-family:
PingFang SC-Medium,
PingFang SC;
2025-03-23 09:29:40 +08:00
font-weight: 500;
color: #333333;
margin-right: 20rpx;
}
.r1 {
font-size: 36rpx;
font-family: Source Han Sans CN;
font-weight: 400;
2025-04-23 11:51:12 +08:00
color: #f82c1a;
2025-03-23 09:29:40 +08:00
margin-right: 20rpx;
}
.l1 {
font-size: 24rpx;
font-family: PingFang SC;
font-weight: 400;
color: #333333;
margin-right: 20rpx;
}
.uBtn {
padding: 20rpx 70rpx;
}
.zhan {
height: 240rpx;
}
.deldel {
color: #005bac;
2025-03-23 09:29:40 +08:00
margin-left: 20rpx;
}
.sel {
position: relative;
}
.kong_t {
text-align: center;
padding-top: 20%;
}
.kong {
width: 576rpx;
height: 406rpx;
}
::v-deep .pp .u-popup__content {
width: 80%;
height: 60%;
overflow-y: auto;
}
.popList {
padding-top: 40rpx;
}
.popList_i {
display: flex;
align-items: center;
padding: 0rpx 40rpx 0rpx 20rpx;
margin-bottom: 40rpx;
.popList_ii {
display: flex;
align-items: center;
}
img {
width: 160rpx;
height: 160rpx;
border-radius: 8px;
margin-right: 20rpx;
}
}
.popBtm {
position: sticky;
bottom: 0;
display: flex;
align-items: center;
justify-content: space-between;
background: #fff;
box-shadow: 0px 2px 20px 0px rgba(204, 204, 204, 1);
padding: 20rpx 40rpx;
font-size: 14px;
.que {
background: #e03030;
border-radius: 20px;
color: #fff;
text-align: center;
padding: 10rpx 20rpx;
}
}
</style>