购物车选规格

该代码段展示了一个Vue.js组件,用于显示商品详细信息,包括商品图片、名称、价格以及规格选择。用户可以点击选择不同的商品规格,数量,并有加入购物车和立即购买的功能按钮。组件还处理了规格选择和数量更改的逻辑。
摘要由CSDN通过智能技术生成
<template>
	<view class="diglog" v-if="shopInfo">
		<view class="canshu">
			<image :src="spec_image" style="height: 170rpx; width: 170rpx; margin-right: 10px;">
			</image>
			<view class="right">
				<view class="title">
					{{shopInfo.goods_name}}
				</view>
				<view class="yixuan">
					已选:{{skuShop}}
				</view>
				<view class="money">
					<view class="beforeMoney">
						<span>¥</span>
						{{specInfo?specInfo.goods_price:shopInfo.goods_price}}
					</view>
					<view class="afterMoney">
						¥
						{{specInfo?specInfo.line_price:shopInfo.line_price}}
					</view>
				</view>
			</view>
		</view>
		<view class="guige">
			<view v-for="(item,index) in shopInfo.spec_list" :key="index" class="item">
				<view class="title">
					{{item.spec_name}}
				</view>
				<view class="all">
					<view v-for="(ite,inde) in item.value" :key="inde" :class="sku[index]==inde?'ite ite_active':'ite'"
						@click="swSku(index,inde)">
						{{ite.spec_value}}
					</view>
				</view>
			</view>
			<view class="num">
				<view class="goumai">
					购买数量
				</view>
				<view class="right">
					<uni-number-box @change="changeValue" :min="1" :max="Number(shopInfo.stock)" />

				</view>
			</view>
		</view>
		<view class="btn">
			<view class="addCart" @click="addcart">
				加入购物车
			</view>
			<view class="mai" @click="confrim1">
				立即购买
			</view>
		</view>
	</view>
</template>

<script>
	import {
		goodDetail,
		addCart,
		getSpecGood,
		store_cartindex,
		buyConfirm
	} from '@/assets/api/shop.js'
	export default {
		props: {
			goods_id: Number,
			store_id: String
		},
		data() {
			return {
				buttonGroup: [{
						text: '加入购物车',
						backgroundColor: '#666666',
						color: '#fff'
					},
					{
						text: '立即购买',
						backgroundColor: '#004AD3',
						color: '#fff'
					}
				],
				show: false,
				num: 1,
				shopInfo: null, //商品详情
				sku: [], //选择商品规格标识
				skuShop: '', //已选商品参数文字
				page: 1,
				skuNum: 1, //商品数量,
				spec_value_id: 0, //选择的规格id,
				specInfo: null, //规格商品详情
				spec_image: '', //选择规格商品图片
			}
		},
		created() {

			this.goodDetail()
		},
		methods: {

			// 商品详情
			async goodDetail() {
				let that = this
				let res = await goodDetail({
					goods_id: this.goods_id,
					store_id: this.store_id
				})
				if (res.data.code == 1) {
					this.shopInfo = res.data.data
					this.spec_image = res.data.data.default_spec_good.spec_image
					this.spec_value_id = res.data.data.default_spec_good.goods_spec_id
					// this.shopInfo.spec_list.forEach(item => {
					// 	that.sku.push(0)
					// })
					// this.skuCon(that.sku)
					// this.getSpecGood(that.sku)
					// console.log(this.spec_value_id)
				}

			},
			// 选择商品规格
			swSku(index, inde) {
				// 更新数组
				this.$set(this.sku, index, inde);
				this.skuCon(this.sku)
				if (this.sku.length == this.shopInfo.spec_list.length) {
					this.getSpecGood(this.sku)
				}
				// this.getSpecGood(this.sku)
			},
			// 规格商品详情
			async getSpecGood(arr) {

				let array = []
				arr.forEach((item, index) => {
					array.push(this.shopInfo.spec_list[index].value[item].id)
				})
				this.spec_value_id = array.toString().replaceAll(",", "_")
				let data = {
					goods_id: Number(this.goods_id),
					spec_value_id: this.spec_value_id
				}
				let res = await getSpecGood(data)
				if (res.data.code == 1) {
					// console.log(res.data.data)
					this.spec_value_id = res.data.data.goods_spec_id
					this.specInfo = res.data.data
				}
			},
			// 选择商品文字
			skuCon(arr) {
				let that = this
				let str = ''
				arr.forEach((item, index) => {
					str += this.shopInfo.spec_list[index].value[item].spec_value + ';'
				})
				this.skuShop = str
				this.skuShop = this.skuShop.slice(0, this.skuShop.length - 1)
				this.$emit('skuValue', this.skuShop)
			},
			// 规格加入购物车
			async addcart() {
				if (this.sku.length != this.shopInfo.spec_list.length) {
					uni.showToast({
						icon: 'none',
						title: '请选择商品规格'
					})
					return
				}
				let res = await addCart({
					store_id: this.store_id,
					goods_spec_id: this.spec_value_id,
					number: this.skuNum
				})
				if (res.data.code == 1) {
					uni.showToast({
						icon: 'none',
						title: res.data.msg,
						success: () => {
							this.$emit('skuClose', true)
							this.storeCartindex()
						}
					})
				}
			},
			// 规格立即购买
			confrim1() {
				if (this.sku.length != this.shopInfo.spec_list.length) {
					uni.showToast({
						icon: 'none',
						title: '请选择商品规格'
					})
					return
				}


				this.$emit('skuClose', true)
				uni.navigateTo({
					url: `/pages/order/confrim?ids=${this.spec_value_id}&store_id=${this.store_id}&number=${this.skuNum}&status=${1}`
				})
			},
			// 加减数量
			changeValue(e) {
				this.skuNum = e
			},
		}
	}
</script>

<style scoped lang="scss">
	.diglog {
		padding: 10px;
		background-color: #FFFFFF;
		border-top-left-radius: 20rpx;
		border-top-right-radius: 20rpx;

		.canshu {
			display: flex;
			padding: 10px 0;

			// .right {
			// 	width: calc(100% - 300rpx);
			// }

			.title {
				-webkit-line-clamp: 1;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				overflow: hidden;
				text-overflow: ellipsis;
				font-size: 30rpx;

				font-weight: bold;
				color: #333333;
			}

			.yixuan {
				font-size: 26rpx;

				font-weight: 500;
				color: #999999;
			}

			.money {
				display: flex;
				margin-top: 10px;

				.beforeMoney {
					font-size: 20px;

					font-weight: bold;
					color: #FF3210;
				}

				.afterMoney {
					font-size: 24rpx;

					font-weight: 500;
					text-decoration: line-through;
					color: #999999;
					margin-left: 10px;
				}
			}
		}

		.guige {
			margin: 10px 0;

			.item {
				margin: 10px 0;

				.title {
					width: auto;
					height: 33rpx;
					font-size: 30rpx;

					font-weight: bold;
					color: #333333;
					margin: 10px 0;
				}

				.all {
					display: flex;
					flex-wrap: wrap;

					.ite {
						min-width: 100rpx;
						height: 50rpx;
						background: #F3F4F6;
						border-radius: 40rpx;
						font-size: 28rpx;
						color: #666666;
						text-align: center;
						line-height: 50rpx;
						margin: 5px 0;
						margin-right: 20rpx;
						padding: 5rpx 10rpx;
					}

					.ite_active {
						background: #E9F1FF;
						border: 1px solid #004AD3;
						color: #004AD3;
					}
				}
			}

			.num {
				display: flex;
				justify-content: space-between;

				.goumai {
					font-size: 34rpx;

					font-weight: bold;
					color: #333333;
				}

				.right {
					display: flex;
					text-align: center;
					align-items: center;

					.add {
						width: 40rpx;
						height: 40rpx;
						background: #FFFFFF;
						border: 1px solid #004AD3;
						border-radius: 10rpx;
						line-height: 20rpx;
					}

					.shuliang {
						margin: 0 5px;
					}

					.reduce {
						width: 40rpx;
						height: 40rpx;
						background: #004AD3;
						border-radius: 10rpx;
						line-height: 46rpx;
					}
				}
			}


		}

		.btn {
			background: #FFFFFF;
			border-radius: 40rpx 40rpx 0rpx 0rpx;
			display: flex;
			margin: 20px 0;
			font-size: 30rpx;
			color: #fff;
			text-align: center;
			line-height: 80rpx;

			.addCart {
				width: 345rpx;
				height: 80rpx;
				background: #666666;
				border-radius: 40rpx 0rpx 0rpx 40rpx;
			}

			.mai {
				width: 345rpx;
				height: 80rpx;
				background: #004AD3;
				border-radius: 0rpx 40rpx 40rpx 0rpx;
			}
		}

	}
</style>

在线商城购物车测试用例可以从以下几个方面考虑: 1. 界面测试: - 确保购物车页面的布局合理且完整,包括商品信息、价格、数量等显示。 - 确保页面的功能按钮正常显示,如结算、删除、修改数量等。 - 检查购物车页面的连接是否正常,如商品详情页、结算页面等。 - 确保购物车中的失效宝贝以及其他相关信息正常显示。 2. 功能测试: - 确保用户可以添加商品到购物车,无论是否登录。 - 对于未登录用户添加商品到购物车后登录,确认商品是否合并到用户购物车。 - 如果不允许未登录用户添加商品到购物车,检查用户是否收到相应的登录提示。 - 确保购物车内商品价格正确显示,包括用户会员折扣。 - 确保勾商品后,已商品的总价和优惠活动正确显示。 - 确保勾商品后,点击结算按钮能进入确认订单信息页面。 - 确保可以对购物车中的商品进行信息的修改和规格的变更,并能成功保存。 - 确保购物车管理功能正常,包括商品的删除、添加、编辑等操作。 3. 性能测试: - 检查打开购物车页面的时间是否在用户可接受的范围内。 - 检查编辑购物车、删除和添加商品所需的时间。 - 确保结算金额能实时显示。 - 检查清空失效商品所需的时间。 4. 兼容性测试: - 在不同型号和操作系统下(如iOS和安卓)测试应用的功能是否正常运行。 5. 网络环境测试: - 在不同网络环境下(如3G、4G、WiFi)测试应用的各功能是否正常运行。 - 检查在网络异常情况下是否会有相关的提醒,并测试数据的恢复和加载情况。 6. 异常测试: - 模拟没有内存的情况,检查应用是否能正常响应。 - 测试横竖屏切换时页面展示是否正常。 - 模拟网络中断和频繁操作某一功能,检查是否会导致闪退。 - 在接入电话、短信和社交软件等信息提示时,测试应用是否能正常运行。 通过以上测试用例,可以全面评估在线商城购物车的功能和性能,确保用户能够顺畅地使用购物车功能。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [【测试用例练习】测试购物车(含思路)](https://blog.csdn.net/qq_40181927/article/details/124642059)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *3* [淘宝购物车的测试用例](https://blog.csdn.net/matilda_art/article/details/107922261)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值