Browse Source

2024-01-09 新商品购买时限制数量的字段storage改为residue

zhiquz 1 year ago
parent
commit
cf1dce7990

+ 1 - 1
common/util/index.js

@@ -1,6 +1,6 @@
 import Vue from 'vue'
 
-export const deepClone = (obj, v) => { // 深克隆方法
+export const deepClone = (obj) => { // 深克隆方法
 	const targetObj = obj.constructor === Array ? [] : {}
 	Object.keys(obj).forEach(keys => {
 		if (obj[keys] && typeof obj[keys] === 'object') {

+ 5 - 2
components/public/add-cart.vue

@@ -20,11 +20,13 @@
 					<view v-for="(size, index) in item.size" :key="index" class="size-item">
 						<view class="left">
 							<text>{{ size }}</text>
-							<text class="basecolor">¥{{ item.money }}/{{ item.unit }}<text v-show="item.name == '红色贺岁款(精装版)'" class="basecolor">{{ `(剩余:${item.storage[index]}${item.unit})` }}</text></text>
+							<text class="basecolor">¥{{ item.money }}/{{ item.unit }}<text v-if="item.name == '红色贺岁款(精装版)'" class="basecolor">{{ `(剩余:${item.residue[index]}${item.unit})` }}</text></text>
 							<!-- <text></text> -->
 						</view>
 						<view v-if="+item.storage[index] > 0">
-							<NumInput :value="item.cart[index]" :args="[item.size_id[index]]" :num="item.step" :max="item.storage[index]" :name="item.name"
+							<NumInput v-if="item.name == '红色贺岁款(精装版)'" :value="item.cart[index]" :args="[item.size_id[index]]" :num="item.step" :max="item.residue[index]" :name="item.name"
+								@change="numChange" />
+							<NumInput v-else :value="item.cart[index]" :args="[item.size_id[index]]" :num="item.step" :name="item.name"
 								@change="numChange" />
 						</view>
 						<view v-else>暂无库存</view>
@@ -75,6 +77,7 @@
 			show(item) {
 				this.showed = true
 				this.item = item
+				console.log(item, 'item')
 			},
 			hide() {
 				this.showed = false

+ 21 - 18
pages/place-order/place-order.vue

@@ -58,7 +58,7 @@
 				return this.$store.state.userinfo
 			},
 			list() {
-				const temp = this.goodsList
+				const temp = deepClone(this.goodsList)
 				temp.forEach(goodItem => {
 					goodItem.cart = Array(goodItem.size.length).fill(0)
 					const itemInCart = this.$store.state.cart.list.find(e => e.attr_id === goodItem.attr_id)
@@ -105,22 +105,25 @@
 				uni.showLoading({
 					mask: true
 				})
+				// 新款商品剩余数量
+				let residue = [0,0,0,0,0,0,0,0,0,0,0,0,0,0] // 剩余数量
+				GetLimitGood().then(res => {
+					if (res.data.length) {
+						residue = res.data.map(item => (item.limit_num - item.num)) // 剩余数量 = 限制购买数量 - 已购买数量
+					}
+				})
 				_API_GoodList().then(res => {
 					if (res.code === 200) {
-						// let arr = res.data.list
-						// if (arr.length) {
-						// 	this.goodsList = arr.map(function(item) {
-						// 	  if (item.name == '红色贺岁款(精装版)') {
-						// 	    return {...item, storage: storage}
-						// 	  } else {
-						// 	    return item
-						// 	  }
-						// 	})
-						// } else {
-						// 	this.status = '暂无商品'
-						// }
-						this.goodsList = res.data.list
-						if (!this.goodsList.length) {
+						let arr = res.data.list
+						if (arr.length) {
+							this.goodsList = arr.map(function(item) {
+							  if (item.name == '红色贺岁款(精装版)') {
+							    return {...item, residue: residue}
+							  } else {
+							    return item
+							  }
+							})
+						} else {
 							this.status = '暂无商品'
 						}
 					} else {
@@ -140,15 +143,15 @@
 			},
 			tapShopCar(item) {
 				// 新款商品剩余数量
-				let storage = [0,0,0,0,0,0,0,0,0,0,0,0,0,0] // 剩余数量
+				let residue = [0,0,0,0,0,0,0,0,0,0,0,0,0,0] // 剩余数量
 				GetLimitGood().then(res => {
 					if (res.data.length) {
-						storage = res.data.map(item => (item.limit_num - item.num)) // 剩余数量 = 限制购买数量 - 已购买数量
+						residue = res.data.map(item => (item.limit_num - item.num)) // 剩余数量 = 限制购买数量 - 已购买数量
 					}
 					const arr = this.$store.state.cart.list
 					const i = arr.findIndex(item => item.name == '红色贺岁款(精装版)')
 					if (i != -1) {
-						this.$store.commit('cart/GETNEWGOODSNUM', storage)
+						this.$store.commit('cart/GETNEWGOODSNUM', residue)
 					}
 					this.$refs.addCart.show(deepClone(item))
 				})

+ 7 - 13
pages/shop-car1/shop-car1.vue

@@ -33,9 +33,11 @@
 					<view class="info">
 						<text>尺码:{{ sizeItem }}</text>
 						<text class="basecolor">¥{{ item.money }}/{{ item.unit }} </text>
-						<text class="basecolor" v-show="item.name == '红色贺岁款(精装版)'">剩余:{{ item.storage[sizeIndex] }}{{ item.unit }}</text>
+						<text class="basecolor" v-if="item.name == '红色贺岁款(精装版)'">剩余:{{ item.residue[sizeIndex] }}{{ item.unit }}</text>
 					</view>
-					<NumInput :value="item.cart[sizeIndex]" :args="[index, sizeIndex]" :num="item.step" :max="item.storage[sizeIndex]" :name="item.name"
+					<NumInput v-if="item.name == '红色贺岁款(精装版)'" :value="item.cart[sizeIndex]" :args="[index, sizeIndex]" :num="item.step"  :max="item.residue[index]" :name="item.name"
+						@change="numChange" />
+					<NumInput v-else :value="item.cart[sizeIndex]" :args="[index, sizeIndex]" :num="item.step" :name="item.name"
 						@change="numChange" />
 				</view>
 			</view>
@@ -215,15 +217,15 @@
 			// },
 			// 新款商品剩余数量
 			getLimitNum() {
-				let storage = [0,0,0,0,0,0,0,0,0,0,0,0,0,0] // 剩余数量
+				let residue = [0,0,0,0,0,0,0,0,0,0,0,0,0,0] // 剩余数量
 				GetLimitGood().then(res => {
 					if (res.data.length) {
-						storage = res.data.map(item => (item.limit_num - item.num)) // 剩余数量 = 限制购买数量 - 已购买数量
+						residue = res.data.map(item => (item.limit_num - item.num)) // 剩余数量 = 限制购买数量 - 已购买数量
 					}
 					const arr = this.$store.state.cart.list
 					const i = arr.findIndex(item => item.name == '红色贺岁款(精装版)')
 					if (i != -1) {
-					    this.$store.commit('cart/GETNEWGOODSNUM', storage)
+					    this.$store.commit('cart/GETNEWGOODSNUM', residue)
 					}
 				})
 			},
@@ -238,14 +240,6 @@
 			numChange(value, index, sizeIndex) { // 购物车数量发生变化
 				if (value) {
 					const cartinfo = this.$store.state.cart.list
-					// const storage = cartinfo[index].storage[sizeIndex]
-					// if (value > storage) {
-					// 	uni.showToast({
-					// 		title: '库存不足!',
-					// 		icon: 'none'
-					// 	})
-					// 	return
-					// }
 					cartinfo[index].cart[sizeIndex] = value
 					cartinfo[index].goods_num = sum(cartinfo[index].cart)
 					cartinfo[index].goods_money = sum(cartinfo[index].cart) * cartinfo[index].money

+ 1 - 1
store/modules/app.js

@@ -7,7 +7,7 @@ export default {
 		navtabbarHeight: uni.upx2px(128), // 自定义导航栏高
 		indextabbarHeight: uni.upx2px(98), // 首页 tabbar 高
 		token: uni.getStorageSync('token'),
-		token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9hcGkuYXBwLmNsaXUuY2NcL2FwaVwvbG9naW5cL2dldF91c2VyX29wZW5pZCIsImlhdCI6MTcwNDc2NTU3MywiZXhwIjoxNzA1NjI5NTczLCJuYmYiOjE3MDQ3NjU1NzMsImp0aSI6IjhQNDBid3ViVkhDY1V4YmIiLCJzdWIiOjM5NTE2LCJwcnYiOiIyM2JkNWM4OTQ5ZjYwMGFkYjM5ZTcwMWM0MDA4NzJkYjdhNTk3NmY3In0.FgS_FuFo63dNS6ztWaS1-KFbEDcfxD24VskMtL1WOR0',
+		// token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9hcGkuYXBwLmNsaXUuY2NcL2FwaVwvbG9naW5cL2dldF91c2VyX29wZW5pZCIsImlhdCI6MTcwNDc2NTU3MywiZXhwIjoxNzA1NjI5NTczLCJuYmYiOjE3MDQ3NjU1NzMsImp0aSI6IjhQNDBid3ViVkhDY1V4YmIiLCJzdWIiOjM5NTE2LCJwcnYiOiIyM2JkNWM4OTQ5ZjYwMGFkYjM5ZTcwMWM0MDA4NzJkYjdhNTk3NmY3In0.FgS_FuFo63dNS6ztWaS1-KFbEDcfxD24VskMtL1WOR0',
 		// token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9hcGkuYXBwLmNsaXUuY2NcL2FwaVwvbG9naW5cL2dldF91c2VyX29wZW5pZCIsImlhdCI6MTcwNDc2NTIwNSwiZXhwIjoxNzA1NjI5MjA1LCJuYmYiOjE3MDQ3NjUyMDUsImp0aSI6IjQxenp2R0M4UktvQzhvbE8iLCJzdWIiOjc1NjYwLCJwcnYiOiIyM2JkNWM4OTQ5ZjYwMGFkYjM5ZTcwMWM0MDA4NzJkYjdhNTk3NmY3In0.WBdmKKbMBiKgcx1posj_GUu7QZ_kd_RG3gsSyfTRDUY',
 	},
 	mutations: {

+ 1 - 1
store/modules/cart.js

@@ -157,7 +157,7 @@ export default {
 		GETNEWGOODSNUM(state, payload) {
 			state.list.forEach(v => {
 				if (v.name == '红色贺岁款(精装版)') {
-					v.storage = payload
+					v.residue = payload
 				}
 			})
 		},