Commit fc7cdb53 by 胡悦

feat(商品管理): 新增SKU商品组件并优化商品数量验证逻辑

添加SkuGoods组件用于处理多规格商品
优化Product和Package组件的商品数量初始化及验证逻辑
统一价格和数量输入验证规则
修复NoticePopup组件按钮列表更新的问题
1 parent a7d2adb2
...@@ -75,6 +75,10 @@ export default { ...@@ -75,6 +75,10 @@ export default {
align-items: center; align-items: center;
justify-content: center; justify-content: center;
font-size: toRpx(30); font-size: toRpx(30);
.sprite-icon {
background-color: #fff;
border-radius: toRpx(14);
}
.entrance-name { .entrance-name {
margin-top: toRpx(22); margin-top: toRpx(22);
} }
......
...@@ -18,9 +18,10 @@ ...@@ -18,9 +18,10 @@
</Product> </Product>
</template> </template>
<template slot="package"> <template slot="package">
<Package></Package> <Package v-if="orderObj.package" :list="orderObj.package" :positionTypeList="positionTypeList"></Package>
</template> </template>
<template slot="skuGoods"> <template slot="skuGoods">
<SkuGoods v-if="orderObj.skuGoods" :list="orderObj.skuGoods" :positionTypeList="positionTypeList" :baseConfigData="baseConfigData"></SkuGoods>
<view class="total" v-if="totalPrice > 0"> <view class="total" v-if="totalPrice > 0">
<view class="total-left">总价</view> <view class="total-left">总价</view>
<view class="total-right">¥{{totalPrice}}</view> <view class="total-right">¥{{totalPrice}}</view>
...@@ -45,6 +46,7 @@ import OrderPopup from '@/components/OrderPopup/index.vue' ...@@ -45,6 +46,7 @@ import OrderPopup from '@/components/OrderPopup/index.vue'
import GlCell from '../../../../components/Form/GlCell.vue' import GlCell from '../../../../components/Form/GlCell.vue'
import Product from './Product.vue' import Product from './Product.vue'
import Package from './Package.vue' import Package from './Package.vue'
import SkuGoods from './SkuGoods.vue'
import { FORM_LIST, popupTypeEnum, payTypeList } from '../contant' import { FORM_LIST, popupTypeEnum, payTypeList } from '../contant'
export default { export default {
name: 'CreateOrder', name: 'CreateOrder',
...@@ -52,7 +54,8 @@ export default { ...@@ -52,7 +54,8 @@ export default {
GlCell, GlCell,
OrderPopup, OrderPopup,
Product, Product,
Package Package,
SkuGoods
}, },
props: { props: {
selectedTradeData: { selectedTradeData: {
...@@ -91,6 +94,8 @@ export default { ...@@ -91,6 +94,8 @@ export default {
rearWindow: null, rearWindow: null,
rearGear: null, rearGear: null,
sunRoof: null, sunRoof: null,
package: null,
skuGoods: null
}, // 弹窗传入的数据}, }, // 弹窗传入的数据},
popupType: 0, popupType: 0,
popupTypeEnum, popupTypeEnum,
...@@ -165,7 +170,7 @@ export default { ...@@ -165,7 +170,7 @@ export default {
this.externalData = [] this.externalData = []
} }
// 定义产品相关字段数组 // 定义产品相关字段数组
const productFields = ['frontGear', 'frontWindow', 'rearGear', 'rearWindow', 'sunRoof'] const productFields = ['frontGear', 'frontWindow', 'rearGear', 'rearWindow', 'sunRoof', 'package', 'skuGoods']
if (productFields.includes(val.value)) { if (productFields.includes(val.value)) {
this.valueKey = val.value this.valueKey = val.value
} }
...@@ -188,7 +193,7 @@ export default { ...@@ -188,7 +193,7 @@ export default {
const _typeValue = this.popupTypeEnum[this.popupType] const _typeValue = this.popupTypeEnum[this.popupType]
console.log(_typeValue) console.log(_typeValue)
// 定义产品相关字段数组 // 定义产品相关字段数组
const productFields = ['frontGear', 'frontWindow', 'rearGear', 'rearWindow', 'sunRoof']; const productFields = ['frontGear', 'frontWindow', 'rearGear', 'rearWindow', 'sunRoof', 'package', 'skuGoods'];
if (_typeValue.key == 'carBrand') { if (_typeValue.key == 'carBrand') {
// 车型 // 车型
this.$set(this.orderObj, _typeValue.key, `${chooseContent.carBrand}-${chooseContent.carChildsBrandName}-${chooseContent.carSeriesName}`) this.$set(this.orderObj, _typeValue.key, `${chooseContent.carBrand}-${chooseContent.carChildsBrandName}-${chooseContent.carSeriesName}`)
......
...@@ -12,12 +12,12 @@ ...@@ -12,12 +12,12 @@
<view class="popup-text">{{ text }}</view> <view class="popup-text">{{ text }}</view>
<view class="popup-buttons"> <view class="popup-buttons">
<view <view
v-for="(button, index) in buttons" v-for="(button, index) in buttonsList"
:key="index" :key="index"
class="popup-button" class="popup-button"
:class="[ :class="[
`button-${button.type || 'default'}`, `button-${button.type || 'default'}`,
{ 'single-button': buttons.length === 1 } { 'single-button': buttonsList.length === 1 }
]" ]"
@click="handleButtonClick(button)" @click="handleButtonClick(button)"
> >
...@@ -57,7 +57,8 @@ export default { ...@@ -57,7 +57,8 @@ export default {
}, },
data() { data() {
return { return {
popupShow: false popupShow: false,
buttonsList: []
} }
}, },
computed: { computed: {
...@@ -89,6 +90,23 @@ export default { ...@@ -89,6 +90,23 @@ export default {
// 触发点击事件,传递按钮信息 // 触发点击事件,传递按钮信息
this.$emit('buttonClick', button) this.$emit('buttonClick', button)
} }
},
// 监听props变化,更新本地数据
watch: {
buttons: {
immediate: true,
handler(newVal) {
if (newVal) {
this.buttonsList = JSON.parse(JSON.stringify(newVal))
}
}
}
},
created() {
// 初始化时将buttons赋值给buttonsList
this.buttonsList = JSON.parse(JSON.stringify(this.buttons))
} }
} }
</script> </script>
......
<template> <template>
<view> <view>
<view class="package-list"> <view class="package-list">
<view class="package-item"> <view class="package-item" v-for="(item, index) in list" :key="index">
<view class="header"> <view class="header">
<view class="header-left"> <view class="header-left">
<view class="sprite-icon icon-blue-delete"></view> <view class="sprite-icon icon-blue-delete"></view>
<view class="name">平步青云套餐</view> <view class="name">{{item.packageGoods.packageAlias||item.packageGoods.packageName}}</view>
</view>
<view class="price">¥6660.00</view>
</view>
<view class="goods-item">
<view class="goods-name">AITO汽车专享 M5中控屏钢化保护膜</view>
<view class="alias-name">商品别名:阿尔法 T5极狐非三电整车延保(新车2年6万公里)</view>
<view class="front-gear-box">
<view class="front-gear-input-box">
<view class="front-gear-label">前档玻璃</view>
<view class="front-gear-input">
<view class="unit">¥</view>
<input class="uni-input" type="digit" placeholder="请输入价格" placeholder-style="font-size: 14px" />
</view>
</view>
<view class="control"> <view class="control">
<view class="minus">-</view> <view class="minus" @click="decreaseNumber(item)">-</view>
<input class="uni-input control-input" type="number" /> <input class="uni-input control-input" type="number" maxlength="3" v-model="item.packageGoods.number" @blur="validateNumber($event, item)" />
<view class="add">+</view> <view class="add" @click="increaseNumber(item)">+</view>
</view> </view>
</view> </view>
<view class="price">¥{{item.packageGoods.upgradePrice}}</view>
</view> </view>
<view class="goods-item"> <view class="goods-item" v-for="(goods, ind) in item.packageGoods.goodsList" :key="ind">
<view class="goods-name">AITO汽车专享 M5中控屏钢化保护膜</view> <view class="goods-name">{{goods.goodsAlias || goods.upgradeGoodsName}}</view>
<view class="alias-name">商品别名:阿尔法 T5极狐非三电整车延保(新车2年6万公里)</view> <!-- <view class="alias-name">商品别名:阿尔法 T5极狐非三电整车延保(新车2年6万公里)</view> -->
<view class="front-gear-box"> <view class="front-gear-box">
<view class="front-gear-input-box"> <view class="front-gear-input-box">
<view class="front-gear-label">前档玻璃</view> <view class="front-gear-label" v-if="goods.merchantGoodsPosition || goods.goodsInfo.goodsTypeName">{{goods.goodsInfo.goodsType===1?formatPosition(goods.merchantGoodsPosition, positionTypeList):goods.goodsInfo.goodsTypeName}}</view>
<view class="front-gear-input"> <view class="front-gear-input">
<view class="unit">¥</view> <view class="unit">¥</view>
<input class="uni-input" type="digit" placeholder="请输入价格" placeholder-style="font-size: 14px" /> <input class="uni-input" type="digit" maxlength="9" placeholder="请输入价格" placeholder-style="font-size: 14px" v-model="goods.sellPrice" @blur="validatePrice($event, goods, ind, index)" />
</view> </view>
</view> </view>
<view class="control">
<view class="minus">-</view>
<input class="uni-input control-input" type="number" />
<view class="add">+</view>
</view>
</view> </view>
</view> </view>
</view> </view>
...@@ -50,8 +32,110 @@ ...@@ -50,8 +32,110 @@
</view> </view>
</template> </template>
<script> <script>
export default { export default {
name: 'Package' name: 'Package',
props: {
list: {
type: Array,
default: () => []
},
positionTypeList: {
type: Array,
default: []
},
},
created() {
// 初始化商品数量
this.list.forEach(item => {
if (!item.packageGoods.number) {
this.$set(item.packageGoods, 'number', '1')
}
})
},
methods: {
// 格式化位置信息
formatPosition(item, positionTypeList) {
const filterData = positionTypeList.filter(v => v.positionValue == item)
return (filterData.length && filterData[0] && filterData[0].positionName) || ''
},
// 验证数量输入
validateNumber(event, item) {
let value = event.detail.value
// 限制只能输入整数
value = value.replace(/[^\d]/g, '')
// 如果为空或0,设置为1
if (!value || value.trim() === '' || parseInt(value) === 0) {
value = '1'
}
// 更新值
this.$set(item.packageGoods, 'number', value)
this.$emit('changeTotalPrice')
},
// 增加数量
increaseNumber(item) {
if (!item.packageGoods.number) {
this.$set(item.packageGoods, 'number', '1')
} else {
const currentValue = parseInt(item.packageGoods.number)
// 限制最大数量为999
const newValue = currentValue >= 999 ? 999 : currentValue + 1
this.$set(item.packageGoods, 'number', newValue.toString())
}
this.$emit('changeTotalPrice')
},
// 减少数量
decreaseNumber(item) {
// 如果商品数量不存在或小于等于1,设置为1
if (!item.packageGoods.number || parseInt(item.packageGoods.number) <= 1) {
this.$set(item.packageGoods, 'number', '1')
return
}
const currentValue = parseInt(item.packageGoods.number)
// 确保减少后的值不小于1
const newValue = Math.max(1, currentValue - 1)
this.$set(item.packageGoods, 'number', newValue.toString())
this.$emit('changeTotalPrice')
},
validatePrice(event, goods, ind, index) {
let value = event.detail.value
console.log('value', value)
// 如果为空则设置为0
if (!value || value.trim() === '') {
value = '0'
}
// 限制只能输入数字和小数点
value = value.replace(/[^\d.]/g, '')
// 限制只能有一个小数点
if (value.split('.').length > 2) {
value = value.slice(0, value.lastIndexOf('.')) + value.slice(value.lastIndexOf('.') + 1)
}
// 限制最多两位小数
if (value.includes('.')) {
const parts = value.split('.')
if (parts[1].length > 2) {
parts[1] = parts[1].substring(0, 2)
value = parts.join('.')
}
}
// 限制最大值为100000
if (parseFloat(value) > 100000) {
value = '100000'
}
// 限制最小值为0
if (parseFloat(value) < 0 || parseFloat(value) == 0) {
value = '0'
}
// 如果validMinSellPrice为Y,则强制修改值为最小值
if (goods.validMinSellPrice === 'Y' && goods.minSellPrice && parseFloat(value) < parseFloat(goods.minSellPrice)) {
console.log('最小值', goods.minSellPrice)
value = goods.minSellPrice.toString()
}
// 更新值
this.$set(this.list[index].packageGoods.goodsList[ind], 'sellPrice', value)
this.$emit('changeTotalPrice')
},
}
} }
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
...@@ -94,8 +178,17 @@ export default { ...@@ -94,8 +178,17 @@ export default {
} }
} }
} }
}
.package-list {
padding: toRpx(12) toRpx(32) toRpx(12) 0;
.package-item {
background-color: #f5f7fa;
border-radius: toRpx(16);
margin-bottom: toRpx(16);
.control { .control {
margin-left: toRpx(32);
display: flex; display: flex;
align-items: center; align-items: center;
...@@ -129,15 +222,6 @@ export default { ...@@ -129,15 +222,6 @@ export default {
border-right: toRpx(2) solid #eff0f2; border-right: toRpx(2) solid #eff0f2;
} }
} }
}
.package-list {
padding: toRpx(12) toRpx(32) toRpx(12) 0;
.package-item {
background-color: #f5f7fa;
border-radius: toRpx(16);
margin-bottom: toRpx(16);
.header { .header {
display: flex; display: flex;
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
</view> </view>
<view class="control"> <view class="control">
<view class="minus" @click="decreaseNumber(item)">-</view> <view class="minus" @click="decreaseNumber(item)">-</view>
<input class="uni-input control-input" type="number" maxlength="3" v-model="item.goods.number" @input="validateNumber($event, item)" /> <input class="uni-input control-input" type="number" maxlength="3" v-model="item.goods.number" @blur="validateNumber($event, item)" />
<view class="add" @click="increaseNumber(item)">+</view> <view class="add" @click="increaseNumber(item)">+</view>
</view> </view>
</view> </view>
...@@ -49,13 +49,27 @@ export default { ...@@ -49,13 +49,27 @@ export default {
}, },
created() { created() {
// 初始化商品数量 // 初始化商品数量
this.initProductNumbers()
},
mounted() {
// 确保每次使用组件时都检查并设置number属性
this.initProductNumbers()
},
updated() {
// 当组件数据更新时也检查number属性
this.initProductNumbers()
},
methods: {
// 初始化商品数量方法
initProductNumbers() {
if (this.list && this.list.length > 0) {
this.list.forEach(item => { this.list.forEach(item => {
if (!item.goods.number) { if (!item.goods.number) {
this.$set(item.goods, 'number', '1') this.$set(item.goods, 'number', '1')
} }
}) })
}
}, },
methods: {
circulation(data, str) { circulation(data, str) {
let arr = str.split('.'), let arr = str.split('.'),
result; result;
...@@ -75,6 +89,10 @@ export default { ...@@ -75,6 +89,10 @@ export default {
validatePrice(event, item, index) { validatePrice(event, item, index) {
let value = event.detail.value let value = event.detail.value
console.log('value', value) console.log('value', value)
// 如果为空则设置为0
if (!value || value.trim() === '') {
value = '0'
}
// 限制只能输入数字和小数点 // 限制只能输入数字和小数点
value = value.replace(/[^\d.]/g, '') value = value.replace(/[^\d.]/g, '')
// 限制只能有一个小数点 // 限制只能有一个小数点
...@@ -99,6 +117,10 @@ export default { ...@@ -99,6 +117,10 @@ export default {
} }
if (item.goods.validMinSellPrice === 'Y' && item.goods.minSellPrice && parseFloat(value) < parseFloat(item.goods.minSellPrice)) { if (item.goods.validMinSellPrice === 'Y' && item.goods.minSellPrice && parseFloat(value) < parseFloat(item.goods.minSellPrice)) {
console.log('最小值', item.goods.minSellPrice) console.log('最小值', item.goods.minSellPrice)
uni.showToast({
title: '单价不可低于商品最低价',
icon: 'none'
})
value = item.goods.minSellPrice.toString() value = item.goods.minSellPrice.toString()
} }
// 更新值 // 更新值
......
...@@ -57,7 +57,7 @@ export default { ...@@ -57,7 +57,7 @@ export default {
console.log(item) console.log(item)
// 保存当前选择的组件信息,但不立即切换 // 保存当前选择的组件信息,但不立即切换
const selectedItem = item const selectedItem = item
if (this.toolComponentName == selectedItem.name) return
// 如果当前组件是OrderManagement,直接切换组件,不显示弹窗 // 如果当前组件是OrderManagement,直接切换组件,不显示弹窗
if (this.toolComponentName === 'OrderManagement') { if (this.toolComponentName === 'OrderManagement') {
this.toolComponentName = selectedItem.name this.toolComponentName = selectedItem.name
...@@ -66,7 +66,7 @@ export default { ...@@ -66,7 +66,7 @@ export default {
} }
// 配置弹窗按钮 // 配置弹窗按钮
this.$refs.notice.buttons = [{ this.$refs.notice.buttonsList = [{
text: '确认退出', text: '确认退出',
type: 'default', type: 'default',
callback: () => { callback: () => {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!