fix: 修复了一些东西,新增购物车功能

This commit is contained in:
2025-11-27 08:41:32 +08:00
parent 33750943b4
commit 65d61d519d
6 changed files with 861 additions and 432 deletions

View File

@@ -54,7 +54,7 @@ export default {
return {
code: "",
form: {
check: true
check: false
},
encryptedData: "",
iv: "",

View File

@@ -10,6 +10,14 @@ const prefix = '/order';
export async function genOrderApi(params) {
return await post(`${prefix}/gen-order`, params, 3)
}
/**
* 创建订单 - 购物车
* @param params
* @returns {Promise<*>}
*/
export async function genOrderByCartApi(params) {
return await post(`${prefix}/gen-order-by-cart`, params, 3)
}
/**
* 保存购药、复诊状态下的挂号信息
* @param params

View File

@@ -6,7 +6,7 @@ import {get, post, uploadFile} from './http'
* @returns {Promise<*>}
*/
export async function getStoreDrugListBySalespersonApi(params) {
return await get('/store/drug-list-by-salesperson', params, 3)
return await get('/product/drug-list-by-salesperson', params, 3)
}
/**
* 获取扫码诊所的商品详情
@@ -14,5 +14,5 @@ export async function getStoreDrugListBySalespersonApi(params) {
* @returns {Promise<*>}
*/
export async function getStoreDrugDetailApi(params) {
return await get('/store/product-detail', params, 3)
}
return await get('/product/product-detail', params, 3)
}

View File

@@ -46,19 +46,82 @@
<text class="spec-label">规格</text>
<text class="spec-value">{{ item.drug.specification }}</text>
</view>
<view class="item-price">
<text class="price-tag">¥{{ item.price }}</text>
<!-- <text class="stock-tag">库存{{ item.stock }}</text>-->
<text class="stock-tag">库存999</text>
<view class="item-bottom">
<view class="price-section">
<text class="price-tag">¥{{ item.price }}</text>
<text class="stock-tag">库存999</text>
</view>
<!-- 简洁的购物车图标按钮 -->
<view class="cart-icon-btn" @click.stop="showCartPopup(item)">
<u-icon name="shopping-cart" color="#4A90E2" size="36"></u-icon>
</view>
</view>
</view>
</view>
</view>
<!-- 购物车悬浮球 -->
<view
class="cart-float"
:style="{ left: cartPosition.x + 'px', top: cartPosition.y + 'px' }"
@touchstart="onTouchStart"
@touchmove="onTouchMove"
@touchend="onTouchEnd"
@click="goToCart"
>
<u-badge :count="cartCount" :max="99" type="error" class="cart-badge" v-if="cartCount > 0"></u-badge>
<u-icon name="shopping-cart" color="#ffffff" size="32"></u-icon>
</view>
<!-- 购物车弹窗 -->
<u-popup
v-model="showPopup"
mode="bottom"
border-radius="20"
:closeable="true"
@close="closePopup"
>
<view class="popup-content">
<view class="popup-header">
<text class="popup-title">选择购买数量</text>
</view>
<view class="product-info">
<image class="product-image" :src="getProductImage" mode="aspectFill"></image>
<view class="product-details">
<text class="product-name">{{ getProductName }}</text>
<text class="product-spec">{{ getProductSpec }}</text>
<view class="product-price">¥{{ currentProduct.price || '' }}</view>
</view>
</view>
<view class="quantity-selector">
<text class="quantity-label">购买数量</text>
<view class="quantity-controls">
<u-number-box
v-model="quantity"
:min="1"
:max="999"
integer
:step="1"
:disabled-input="false"
@change="quantityChange"
></u-number-box>
</view>
</view>
<view class="popup-actions">
<button class="cancel-btn" @click="closePopup">取消</button>
<button class="confirm-btn" @click="confirmAddToCart">加入购物车</button>
</view>
</view>
</u-popup>
</view>
</template>
<script>
import {getStoreDrugListBySalespersonApi} from "@/request/api/store";
import { getStoreDrugListBySalespersonApi} from "@/request/api/product";
import {getCartCountsApi, saveCartApi} from "@/request/api/cart";
export default {
data() {
@@ -69,11 +132,38 @@ export default {
scrollViewHeight: 0,
doctorId: 0,
r_type: 0,
// 购物车相关数据
cartCount: 0,
cartPosition: {
x: 0,
y: 0
},
cartMove: {
startX: 0,
startY: 0,
moving: false
},
// 弹窗相关数据
showPopup: false,
currentProduct: {},
quantity: 1
};
},
computed: {
// 计算属性来处理可能为空的属性
getProductImage() {
return this.currentProduct.drug && this.currentProduct.drug.image ? this.currentProduct.drug.image : '';
},
getProductName() {
return this.currentProduct.drug && this.currentProduct.drug.drug_name ? this.currentProduct.drug.drug_name : '';
},
getProductSpec() {
return this.currentProduct.drug && this.currentProduct.drug.specification ? this.currentProduct.drug.specification : '';
}
},
onLoad(e) {
this.doctorId = e.doctor_id;
this.r_type = e.register_type
this.r_type = e.register_type;
console.log(e, 'e');
},
methods: {
@@ -85,6 +175,7 @@ export default {
}).then((res) => {
if (res.data.code == 0) {
this.products = res.data.result.records;
this.cartCount = res.data.result.cart_count;
this.filteredProducts = [...this.products];
}
})
@@ -104,32 +195,167 @@ export default {
this.scrollViewHeight = systemInfo.windowHeight - 160;
},
handClickProduct(item) {
uni.navigateTo({
// url: `/subPackages/product/symptoms?id=${item.drug.id}&drug_name=${item.drug.drug_name}&doctor_id=${this.doctorId}&type=${this.r_type}&is_otc=${item.drug.is_otc}&image=${item.drug.image}&price=${item.price}`
url: `/subPackages/product/symptoms?id=${item.drug.id}&drug_name=${item.drug.drug_name}&is_otc=${item.drug.is_otc}&image=${item.drug.image}&price=${item.price}`
// url: `/subPackages/shop/search-list`
});
// console.log(`/subPackages/product/symptoms?id=${item.drug.id}&drug_name=${item.drug.drug_name}&doctor_id=${this.doctorId}&type=${this.r_type}`, 'ssssssss')
// if (item.drug.is_otc === 0) {
// uni.navigateTo({
// url: `/subPackages/shop/orders-detail?id=${item.drug.id}&drug_name=${item.drug.drug_name}&doctor_id=${this.doctorId}&type=${this.r_type}`
// });
// } else {
// uni.navigateTo({
// url: `/subPackages/product/symptoms?id=${item.drug.id}&drug_name=${item.drug.drug_name}&doctor_id=${this.doctorId}&type=${this.r_type}`
// // url: `/subPackages/shop/search-list`
// });
// }
},
// 购物车相关方法
// 初始化购物车位置
initCartPosition() {
const systemInfo = uni.getSystemInfoSync();
this.cartPosition = {
x: systemInfo.windowWidth - 80, // 距离右侧80px
y: systemInfo.windowHeight - 200 // 距离底部200px
};
},
// 触摸开始
onTouchStart(e) {
this.cartMove.startX = e.touches[0].clientX;
this.cartMove.startY = e.touches[0].clientY;
this.cartMove.moving = false;
},
// 触摸移动
onTouchMove(e) {
this.cartMove.moving = true;
const moveX = e.touches[0].clientX - this.cartMove.startX;
const moveY = e.touches[0].clientY - this.cartMove.startY;
this.cartPosition.x += moveX;
this.cartPosition.y += moveY;
this.cartMove.startX = e.touches[0].clientX;
this.cartMove.startY = e.touches[0].clientY;
},
// 触摸结束
onTouchEnd() {
if (!this.cartMove.moving) return;
const systemInfo = uni.getSystemInfoSync();
const screenWidth = systemInfo.windowWidth;
const screenHeight = systemInfo.windowHeight;
// 边界检测
let finalX = this.cartPosition.x;
let finalY = this.cartPosition.y;
// 限制在屏幕范围内
finalX = Math.max(10, Math.min(finalX, screenWidth - 70));
finalY = Math.max(10, Math.min(finalY, screenHeight - 70));
// 自动吸附到左侧或右侧
if (finalX < screenWidth / 2) {
finalX = 20; // 吸附到左侧
} else {
finalX = screenWidth - 70; // 吸附到右侧
}
this.cartPosition = {
x: finalX,
y: finalY
};
},
// 跳转到购物车页面
goToCart() {
uni.navigateTo({
url: '/subPackages/shop/shop-cate'
});
},
// 显示购物车弹窗
showCartPopup(item) {
this.currentProduct = item;
this.quantity = 1;
this.showPopup = true;
},
// 关闭弹窗
closePopup() {
this.showPopup = false;
},
// 数量变化
quantityChange(value) {
console.log('数量变化:', value);
},
// 确认加入购物车
confirmAddToCart() {
try {
// 获取当前购物车数据
let cart = uni.getStorageSync('cart') || [];
// 确保cart是数组
if (!Array.isArray(cart)) {
cart = [];
}
// 查找商品是否已在购物车中
const existingItem = cart.find(cartItem => cartItem.id === this.currentProduct.drug.id);
saveCartApi({
store_id: uni.getStorageSync('store_id')|| '11001',
drug_id: this.currentProduct.drug.id,
quantity: this.quantity
}).then(() => {
// 更新购物车数量
this.updateCartCount();
// 关闭弹窗
this.closePopup();
// 显示成功提示
uni.showToast({
title: `已加入${this.quantity}件商品`,
icon: 'success',
duration: 1500
});
})
} catch (error) {
console.error('加入购物车失败:', error);
uni.showToast({
title: '加入购物车失败',
icon: 'none',
duration: 1000
});
}
},
// 更新购物车数量
updateCartCount() {
let that = this;
getCartCountsApi({
store_id: uni.getStorageSync('store_id') || '11001',
page: 1,
limit: 100
}).then((res) => {
if (res.data.code == 0) {
that.cartCount = res.data.result.cart_count;
}
})
}
},
onShow() {
this.getList();
this.calculateScrollViewHeight();
this.initCartPosition();
this.updateCartCount(); // 更新购物车数量
},
onReady() {
uni.onWindowResize(() => this.calculateScrollViewHeight());
uni.onWindowResize(() => {
this.calculateScrollViewHeight();
this.initCartPosition();
});
},
// 添加页面加载时的购物车初始化
mounted() {
this.updateCartCount();
}
};
</script>
@@ -140,6 +366,7 @@ export default {
background: #f0f5ff;
min-height: 100vh;
box-sizing: border-box;
position: relative;
}
.search-section {
@@ -160,6 +387,7 @@ export default {
border-radius: 16rpx;
box-shadow: 0 4rpx 12rpx rgba(0,0,0,0.05);
transition: all 0.2s ease;
background-color: #ffffff;
&:active {
transform: translateY(4rpx);
@@ -176,6 +404,8 @@ export default {
.item-content {
flex: 1;
display: flex;
flex-direction: column;
}
.item-title {
@@ -200,22 +430,187 @@ export default {
margin-right: 4rpx;
}
.item-price {
.item-bottom {
display: flex;
justify-content: space-between;
align-items: center;
padding: 16rpx 0;
border-top: 1rpx solid #f0f0f0;
margin-top: auto;
}
.price-section {
display: flex;
flex-direction: column;
}
.price-tag {
font-size: 32rpx;
font-weight: 500;
color: #3A86FF;
margin-bottom: 4rpx;
}
.stock-tag {
font-size: 24rpx;
color: #95a5a6;
}
// 简洁的购物车图标按钮
.cart-icon-btn {
width: 72rpx;
height: 72rpx;
border-radius: 50%;
background-color: rgba(74,144,226,0.1);
display: flex;
align-items: center;
justify-content: center;
transition: all 0.2s ease;
&:active {
background-color: rgba(74,144,226,0.2);
transform: scale(0.95);
}
}
// 购物车悬浮球样式
.cart-float {
position: fixed;
width: 100rpx;
height: 100rpx;
background: linear-gradient(135deg, #4A90E2, #3A86FF);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 8rpx 24rpx rgba(74,144,226,0.3);
z-index: 999;
transition: transform 0.2s ease;
&:active {
transform: scale(0.95);
}
}
.cart-badge {
position: absolute;
top: -10rpx;
right: -10rpx;
}
// 弹窗样式
.popup-content {
padding: 40rpx;
padding-bottom: 60rpx; // 为底部安全区域留出空间
}
.popup-header {
margin-bottom: 40rpx;
text-align: center;
}
.popup-title {
font-size: 36rpx;
font-weight: 600;
color: #2c3e50;
}
.product-info {
display: flex;
margin-bottom: 50rpx;
padding: 30rpx;
background-color: #f8f9fa;
border-radius: 16rpx;
}
.product-image {
width: 120rpx;
height: 120rpx;
border-radius: 12rpx;
margin-right: 24rpx;
}
.product-details {
flex: 1;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.product-name {
font-size: 30rpx;
font-weight: 500;
color: #2c3e50;
margin-bottom: 8rpx;
}
.product-spec {
font-size: 24rpx;
color: #95a5a6;
margin-bottom: 12rpx;
}
.product-price {
font-size: 32rpx;
font-weight: 600;
color: #3A86FF;
}
.quantity-selector {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 60rpx;
padding: 30rpx 0;
border-top: 1rpx solid #f0f0f0;
border-bottom: 1rpx solid #f0f0f0;
}
.quantity-label {
font-size: 30rpx;
color: #2c3e50;
font-weight: 500;
}
.quantity-controls {
display: flex;
align-items: center;
}
.popup-actions {
display: flex;
justify-content: space-between;
}
.cancel-btn {
flex: 1;
margin-right: 20rpx;
background-color: #f8f9fa;
color: #95a5a6;
border: none;
border-radius: 50rpx;
padding: 24rpx 0;
font-size: 30rpx;
font-weight: 500;
&:active {
background-color: #e9ecef;
}
}
.confirm-btn {
flex: 1;
margin-left: 20rpx;
background: linear-gradient(135deg, #4A90E2, #3A86FF);
color: #ffffff;
border: none;
border-radius: 50rpx;
padding: 24rpx 0;
font-size: 30rpx;
font-weight: 500;
&:active {
opacity: 0.8;
}
}
</style>

View File

@@ -92,7 +92,7 @@
</template>
<script>
import {getStoreDrugDetailApi} from "@/request/api/store";
import {getStoreDrugDetailApi} from "@/request/api/product";
import {genOrderApi, saveRegisterInfoApi} from "@/request/api/order";
export default {

View File

@@ -1,456 +1,482 @@
<template>
<view class="container safe-area-inset-bottom">
<!-- 清空购物车 -->
<view class="head">
<view class="num">
购物车{{totalCount}}件商品
</view>
<view class="clear" @click='clearCart'>
<text class="iconfont icon-qingchu"></text>
清空购物车
</view>
</view>
<view class="container safe-area-inset-bottom">
<!-- 清空购物车 -->
<view class="head">
<view class="num">
购物车{{ totalCount }}件商品
</view>
<view class="clear" @click='clearCart'>
<text class="iconfont icon-qingchu"></text>
清空购物车
</view>
</view>
<!-- 商品列表 -->
<view class="card">
<!-- 门店 -->
<view class="store"><text class="iconfont icon-mendian"></text>{{cartLists.store_name}}</view>
<u-checkbox-group>
<view class="list" v-for="item in cartLists.valid">
<!-- 商品列表 -->
<view class="card">
<!-- 门店 -->
<view class="store">
<text class="iconfont icon-mendian"></text>
{{ cartLists.store_name }}
</view>
<u-checkbox-group>
<view class="list" v-for="item in cartLists.data" :key="item.id">
<u-checkbox shape="circle" @change="checkboxChange(item)" v-model="item.checked">
</u-checkbox>
<u-checkbox shape="circle" @change="checkboxChange(item)" v-model="item.checked">
</u-checkbox>
<view class="img">
<image :src="item.drug.image" mode=""></image>
</view>
<view class="it">
<view class="it_name">{{item.drug.drug_name}}</view>
<view class="it_info">{{item.drug.small_info}}</view>
<view class="it_price">
<text>{{item.drug.drugstore_drug.price}}</text>
<view class="it_num">
<uni-number-box :min="1" @change="changeNum($event,item)" :value="item.qty">
</uni-number-box>
</view>
</view>
</view>
</view>
</u-checkbox-group>
</view>
<view class="img" @click="checkboxChange(item)">
<image :src="item.drug.image" mode=""></image>
</view>
<view class="it" @click="checkboxChange(item)">
<view class="it_name">{{ item.drug.drug_name }}</view>
<view class="it_info">{{ item.drug.usage }}</view>
<view class="it_price">
<text>{{ item.drug.drugstore_drug.price }}</text>
<view class="it_num" @click.stop>
<uni-number-box :min="1" @change="changeNum($event,item)" :value="item.qty">
</uni-number-box>
</view>
</view>
</view>
</view>
</u-checkbox-group>
</view>
<view class="footer">
<view class="allselect-left">
<u-checkbox-group>
<u-checkbox v-model="checked" @change="checkedAll" shape="circle">全选</u-checkbox>
</u-checkbox-group>
</view>
<view class="footer">
<view class="allselect-left" @click="checkedAll">
<u-checkbox-group>
<u-checkbox v-model="checked" shape="circle">全选</u-checkbox>
</u-checkbox-group>
</view>
<view class="total">
合计
<text class="price">{{totalPrice}}</text>
</view>
<view class="total">
合计
<text class="price">{{ totalPrice }}</text>
</view>
<view class="to_btn" @click="toPay">去结算</view>
</view>
</view>
<view class="to_btn" @click="toPay">去结算</view>
</view>
</view>
</template>
<script>
// CartList
import {
CartList,
addCart,
clearAll
// CartList
import {
CartList,
addCart,
clearAll
} from '../../request/api/api'
export default {
data() {
return {
checked: false,
allcheck: false,
value: 1,
numberValue: 0,
vModelValue: 3,
list: [{
checked: false,
disabled: false
}],
selectList: [], //选中的数据
cartLists: {},
drug_ids:[],//药品id
cart_ids:[],//购物车id
qty:'',
change_qty:'',
true_qty:''
} from '../../request/api/api'
import {getCartListApi, saveCartApi} from "@/request/api/cart";
import {genOrderByCartApi} from "@/request/api/order";
}
},
onLoad() {
this.getCartList()
},
export default {
data() {
return {
checked: false,
allcheck: false,
value: 1,
numberValue: 0,
vModelValue: 3,
list: [{
checked: false,
disabled: false
}],
selectList: [], //选中的数据
cartLists: {
data: []
},
drug_ids: [],//药品id
cart_ids: [],//购物车id
qty: '',
change_qty: '',
true_qty: ''
computed: {
//全部价格
totalPrice: function() {
var totalPrice = 0;
for (var i = 0; i < this.cartLists.valid.filter(item=>item.checked).length; i++) {
totalPrice += this.cartLists.valid[i].drug.drugstore_drug.price * this.cartLists.valid[i].qty;
}
return totalPrice.toFixed(2);
},
//全部件数
}
},
// onLoad() {
// this.getCartList()
// },
onShow() {
this.getCartList()
},
totalCount: function() {
var totalCount = 0;
for (var i = 0; i < this.cartLists.valid.length; i++) {
totalCount += this.cartLists.valid[i].qty;
}
return totalCount;
},
},
computed: {
//全部价格
totalPrice: function() {
// 添加空值检查
if (!this.cartLists || !this.cartLists.data || this.cartLists.data.length === 0) {
return '0.00';
}
methods: {
//清空购物车
clearCart(){
// const list=this.cartLists.valid.map(item=>item.drug_id)
// this.drug_id=list
// this.true_qty=0
// this.addToCart()
this.clearAll()
this.getCartList()
},
// 搜索
toSearch() {
// this.getList()
},
//加减法
changeNum(e, current) {
console.log(e, current);
this.cartLists.valid.forEach(item => {
if (item.id == current.id) {
item.qty = e;
this.true_qty=e
// this.qty=e
this.drug_id=current.drug_id
}
this.addToCart()
})
let totalPrice = 0;
// 先过滤出已选中的商品,再计算总价
const checkedItems = this.cartLists.data.filter(item => item.checked);
},
// 选中某个复选框时由checkbox时触发
checkboxChange(item) {
console.log(item);
// this.drug_ids.push(item.drug_id)
// this.cart_ids.push(item.id)
item.checked = !item.checked
if (this.cartLists.valid.filter(e => !e.checked).length) {
this.checked = false
checkedItems.forEach(item => {
// 添加价格和数量的有效性检查
const price = item.drug?.drug_store_relations?.price || 0;
const qty = item.qty || 0;
totalPrice += price * qty;
});
} else {
this.checked = true
}
// console.log(item);
// item.checked = !item.checked
// if (!item.checked) {
// this.allChecked = false
// } else {
// // 判断每一个商品是否是被选择的状态
// const cartList = this.list.every(item => {
// return item.checked === true
// })
// if (cartList) {
// this.allChecked = true
// } else {
// this.allChecked = false
// }
// }
},
//// 更新购物车中商品的数量
return totalPrice.toFixed(2);
},
//全部件数
// 选中任一checkbox时由checkbox-group触发
checkboxGroupChange(item) {
console.log(item, 7711117);
// console.log(e,c);
totalCount: function () {
var totalCount = 0;
for (var i = 0; i < this.cartLists.data.length; i++) {
totalCount += this.cartLists.data[i].qty;
}
return totalCount;
},
},
methods: {
//清空购物车
clearCart() {
// const list=this.cartLists.data.map(item=>item.drug_id)
// this.drug_id=list
// this.true_qty=0
// this.addToCart()
this.clearAll()
},
// 搜索
toSearch() {
// this.getList()
},
//加减法
changeNum(e, current) {
console.log(e, current);
this.cartLists.data.forEach(item => {
if (item.id == current.id) {
item.qty = e;
this.true_qty = e
// this.qty=e
this.drug_id = current.drug_id
this.addToCart()
}
})
},
// 全选
checkedAll() {
},
// 选中某个复选框时由checkbox时触发
checkboxChange(item) {
console.log(item);
// this.drug_ids.push(item.drug_id)
// this.cart_ids.push(item.id)
item.checked = !item.checked
if (this.cartLists.data.filter(e => !e.checked).length) {
this.checked = false
if (this.cartLists.valid.filter(item => item.checked).length === this.cartLists.valid.length) {
this.cartLists = {
...this.cartLists,
valid: this.cartLists.valid.map(item => {
return {
...item,
checked: false
}
})
}
} else {
this.cartLists = {
...this.cartLists,
valid: this.cartLists.valid.map(item => {
return {
...item,
checked: true
}
})
}
}
} else {
this.checked = true
}
// console.log(item);
// item.checked = !item.checked
// if (!item.checked) {
// this.allChecked = false
// } else {
// // 判断每一个商品是否是被选择的状态
// const cartList = this.list.every(item => {
// return item.checked === true
// })
// if (cartList) {
// this.allChecked = true
// } else {
// this.allChecked = false
// }
// }
},
//// 更新购物车中商品的数量
},
toPay() {
const list=this.cartLists.valid.filter(item=>item.checked).map(item=>{
return {
drug_id:item.drug_id,
id:item.id,
numbers:item.qty
// numbers:item.qty,
}
})
uni.navigateTo({
url: `/subPackages/shop/shop-pay?list=${JSON.stringify(list)}`
})
},
//加入购物车
clearAll(){
clearAll({
method: "post",
data: {
store_id: uni.getStorageSync('store_id') || '11001',
}
}).then((res) => {
// console.log(res, 'list');
if (res.data.code == 0) {
console.log(res);
}
})
},
addToCart() {
addCart({
method: "post",
data: {
store_id: uni.getStorageSync('store_id') || '11001',
drug_id: this.drug_id,
change_qty: this.change_qty,
true_qty:this.true_qty
// id:this.id
}
}).then((res) => {
// console.log(res, 'list');
if (res.data.code == 0) {
console.log(res);
}
})
},
//请求购物车列表数据
getCartList() {
CartList({
method: "post",
data: {
store_id: uni.getStorageSync('store_id') || '11001',
// category_first:this.category_first,
// category_second:this.category_second,
}
}).then((res) => {
// console.log(res, 'list');
if (res.data.code == 0) {
// this.drugLists=res.data.data
// 选中任一checkbox时由checkbox-group触发
checkboxGroupChange(item) {
console.log(item, 7711117);
// console.log(e,c);
this.cartLists = {
...res.data.data,
valid: res.data.data.valid.map(item => {
return {
...item,
checked: false
}
})
}
// console.log(this.cartLists);
uni.setStorageSync('CARTLIST', res.data.data)
console.log(this.cartLists, 666);
// console.log(this.cartLists.valid[0].drug);
}
})
},
}
}
},
// 全选
checkedAll() {
if (this.cartLists.data.filter(item => item.checked).length === this.cartLists.data.length) {
this.cartLists = {
...this.cartLists,
data: this.cartLists.data.map(item => {
return {
...item,
checked: false
}
})
}
} else {
this.cartLists = {
...this.cartLists,
data: this.cartLists.data.map(item => {
return {
...item,
checked: true
}
})
}
}
},
toPay() {
const list = this.cartLists.data.filter(item => item.checked).map(item => {
return {
drug_id: item.drug_id,
id: item.id,
numbers: item.qty
// numbers:item.qty,
}
})
let cart_ids = list.map(item => item.id);
genOrderByCartApi({
store_id: uni.getStorageSync('store_id') || '11001',
cart_ids: cart_ids
}).then((resOrder) => {
if (resOrder.data.code === 0) {
uni.navigateTo({
url: `/subPackages/my/my-drug/drug-info?id=${resOrder.data.result.id}&order_type=${resOrder.data.result.order_type}`
})
}
})
// uni.navigateTo({
// url: `/subPackages/shop/shop-pay?list=${JSON.stringify(list)}`
// })
},
// 清空购物车
clearAll() {
clearAll({
method: "post",
data: {
store_id: uni.getStorageSync('store_id') || '11001',
}
}).then((res) => {
// console.log(res, 'list');
if (res.data.code == 0) {
console.log(res);
// 提示成功清空购物车
uni.showToast({
title: '清空成功',
icon: 'success',
})
this.getCartList()
}
})
},
addToCart() {
saveCartApi({
store_id: uni.getStorageSync('store_id') || '11001',
drug_id: this.drug_id,
quantity: this.true_qty
// id:this.id
}).then((res) => {
// console.log(res, 'list');
if (res.data.code == 0) {
console.log(res);
}
})
},
//请求购物车列表数据
getCartList() {
getCartListApi({
store_id: uni.getStorageSync('store_id') || '11001',
}).then((res) => {
console.log(res, 'list');
if (res.data.code == 0) {
// this.drugLists=res.data.data
this.cartLists = {
...res.data.result,
data: res.data.result.data.map((item) => {
return {
...item,
checked: false
};
})
};
console.log(this.cartLists, 666);
// console.log(this.cartLists.data[0].drug);
}
})
},
}
}
</script>
<style lang="scss" scoped>
.container {
width: 750rpx;
max-height: 100%;
min-height: 100vh;
padding-bottom: env(safe-area-inset-bottom);
background: #F5F5F5;
.container {
width: 750rpx;
max-height: 100%;
min-height: 100vh;
padding-bottom: env(safe-area-inset-bottom);
background: #F5F5F5;
.head {
width: 750rpx;
height: 88rpx;
margin: 0 auto;
padding: 0rpx 40rpx 0;
display: flex;
justify-content: space-between;
align-items: center;
.head {
width: 750rpx;
height: 88rpx;
margin: 0 auto;
padding: 0rpx 40rpx 0;
display: flex;
justify-content: space-between;
align-items: center;
.num {
font-size: 28rpx;
font-family: PingFang SC-Regular, PingFang SC;
font-weight: 400;
color: #232323;
}
.num {
font-size: 28rpx;
font-family: PingFang SC-Regular, PingFang SC;
font-weight: 400;
color: #232323;
}
.clear {
font-size: 24rpx;
font-family: PingFang SC-Regular, PingFang SC;
font-weight: 400;
color: #232323;
.clear {
font-size: 24rpx;
font-family: PingFang SC-Regular, PingFang SC;
font-weight: 400;
color: #232323;
.iconfont {
font-size: 32rpx;
margin-left: 6rpx;
}
}
}
.iconfont {
font-size: 32rpx;
margin-left: 6rpx;
}
}
}
.card {
width: 750rpx;
margin: 0 auto;
padding: 20rpx 12rpx 20rpx 20rpx;
background: #FFFFFF;
.card {
width: 750rpx;
margin: 0 auto;
padding: 20rpx 12rpx 200rpx 20rpx;
background: #FFFFFF;
.store {
font-size: 28rpx;
font-family: PingFang SC-Regular, PingFang SC;
font-weight: 500;
color: #232323;
margin-left: 20rpx;
.store {
font-size: 28rpx;
font-family: PingFang SC-Regular, PingFang SC;
font-weight: 500;
color: #232323;
margin-left: 20rpx;
.iconfont {
font-size: 39rpx;
color: #666666;
vertical-align: middle;
margin-right: 10rpx;
}
.iconfont {
font-size: 39rpx;
color: #666666;
vertical-align: middle;
margin-right: 10rpx;
}
}
}
.list {
display: flex;
justify-content: space-around;
width: 100%;
height: 254rpx;
display: flex;
align-items: center;
.list {
display: flex;
justify-content: space-around;
width: 100%;
height: 254rpx;
display: flex;
align-items: center;
.checkbox {
width: 44rpx;
height: 44rpx;
background: #1777FF;
border-radius: 50%;
}
.checkbox {
width: 44rpx;
height: 44rpx;
background: #1777FF;
border-radius: 50%;
}
.img {
width: 200rpx;
height: 200rpx;
margin-right: 10rpx;
.img {
width: 200rpx;
height: 200rpx;
margin-right: 10rpx;
image {
width: 200rpx;
height: 200rpx;
border-radius: 8rpx;
}
}
image {
width: 200rpx;
height: 200rpx;
border-radius: 8rpx;
}
}
.it {
flex: 1;
padding: 16rpx 10rpx;
font-family: PingFang SC-Bold, PingFang SC;
.it {
flex: 1;
padding: 16rpx 10rpx;
font-family: PingFang SC-Bold, PingFang SC;
.it_name {
font-size: 28rpx;
font-weight: bold;
color: #232323;
}
.it_name {
font-size: 28rpx;
font-weight: bold;
color: #232323;
}
.it_info {
font-size: 24rpx;
font-weight: 400;
color: #666666;
margin: 20rpx 0 48rpx 10rpx;
display: -webkit-box;
-webkit-line-clamp: 1;
-webkit-box-orient: vertical;
text-overflow: ellipsis;
overflow: hidden;
}
.it_info {
font-size: 24rpx;
font-weight: 400;
color: #666666;
margin: 20rpx 0 48rpx 10rpx;
display: -webkit-box;
-webkit-line-clamp: 1;
-webkit-box-orient: vertical;
text-overflow: ellipsis;
overflow: hidden;
}
.it_price {
display: flex;
align-items: center;
justify-content: space-between;
.it_price {
display: flex;
align-items: center;
justify-content: space-between;
text {
font-size: 36rpx;
font-weight: bold;
color: #F93030;
}
}
}
}
text {
font-size: 36rpx;
font-weight: bold;
color: #F93030;
}
}
}
}
}
}
.footer {
width: 750rpx;
height: 104rpx;
background: #fff;
position: fixed;
left: 0;
bottom: env(safe-area-inset-bottom);
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 24rpx;
.footer {
width: 750rpx;
height: 104rpx;
background: #fff;
position: fixed;
left: 0;
bottom: env(safe-area-inset-bottom);
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 44rpx;
.total {
font-size: 28rpx;
font-family: PingFang SC-Regular, PingFang SC;
font-weight: 400;
color: #232323;
.total {
font-size: 28rpx;
font-family: PingFang SC-Regular, PingFang SC;
font-weight: 400;
color: #232323;
.price {
font-size: 36rpx;
font-family: PingFang SC-Bold, PingFang SC;
font-weight: bold;
color: #4175EE;
}
}
.price {
font-size: 36rpx;
font-family: PingFang SC-Bold, PingFang SC;
font-weight: bold;
color: #4175EE;
}
}
.to_btn {
width: 196rpx;
height: 64rpx;
border-radius: 64rpx;
text-align: center;
line-height: 62rpx;
background: #4175EE;
font-size: 28rpx;
font-family: PingFang SC-Regular, PingFang SC;
font-weight: 400;
color: #FFFFFF;
.to_btn {
width: 196rpx;
height: 64rpx;
border-radius: 64rpx;
text-align: center;
line-height: 62rpx;
background: #4175EE;
font-size: 28rpx;
font-family: PingFang SC-Regular, PingFang SC;
font-weight: 400;
color: #FFFFFF;
}
}
}
}
}
}
</style>