Commit befee03d by cen

feat: 添加订单类型弹窗及相关策略组件

- 新增 OrderTypePopup 组件,用于选择订单类型
- 在 CreateOrder 组件中集成 OrderTypePopup
- 添加 OrderStrategy 组件,支持折扣、买赠和组合付款策略
- 更新 Product 组件以支持策略配置和价格计算
- 在样式中增加 .pb-24 类以调整底部填充
1 parent 8b1c3550
......@@ -243,6 +243,9 @@
.pt-12 {
padding-top: toRpx(12);
}
.pb-24 {
padding-bottom: toRpx(24);
}
.flex-1 {
flex: 1;
}
<template>
<view class="merchant-list">
<template v-for="(i, index) in list">
<view :key="index" @click="choose(i)" :class="['item flex', { active: currentId ? i.value == currentId : i.value == data[params.idKey] }]">
<view class="sprite-icon icon-tag-checked"></view>
{{ i.name }}
</view>
</template>
</view>
</template>
<script type="text/ecmascript-6">
import popupmixin from './popupmixin'
export default {
mixins: [popupmixin],
name: 'OrderTypePopup',
data () {
return {
}
},
mounted () {
},
methods: {
async getList () {
const params = this.params
const data = [{ name: '正常订单', value: '1' }, { name: '打折策略', value: '2' }, { name: '买赠策略', value: '3' }, { name: '冲量活动', value: '4' }, { name: '组合付款', value: '5' }]
this.updateParams(params, data || [])
},
initData (list) {
const { params: { idKey }, data } = this
if (data[idKey]) {
this.currentId = data[idKey]
let item = list.find(i => i.value == this.currentId)
this.$emit('choose', item)
}
this.list = list
this.$emit('onComplete')
},
choose (i) {
this.currentId = i.value
this.$emit('choose', i)
}
}
}
</script>
<style scoped lang="scss">
.merchant-list {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: toRpx(32);
margin: 0 toRpx(48);
.item {
justify-content: center;
height: toRpx(72);
border-radius: toRpx(8);
border: toRpx(2) solid #dce0e6;
box-sizing: border-box;
position: relative;
color: #333333;
font-size: toRpx(32);
.sprite-icon {
display: none;
position: absolute;
top: 0;
right: 0;
}
}
.active {
border-color: #2c66f7;
background: #ecf1ff;
color: #2c66f7;
.sprite-icon {
display: block;
}
}
}
</style>
......@@ -378,6 +378,15 @@ const componentConfig = {
searchValue: '',
noData: false,
defeat: true
},
28: {
name: 'OrderTypePopup',
title: '订单类型',
hideSearch: true,
// 绑定 CreateOrder 中的字段名
idKey: 'orderType',
cacheData: [],
loadComplete: false
}
}
export default { componentConfig }
......@@ -109,6 +109,7 @@ import Customer from './components/Customer.vue'
import Options from './components/Options.vue'
import CarBrand from './components/CarBrand.vue'
import Gearbox from './components/Gearbox.vue'
import OrderTypePopup from './components/OrderTypePopup.vue'
export default {
components: {
......@@ -131,7 +132,8 @@ export default {
Customer,
Options,
CarBrand,
Gearbox
Gearbox,
OrderTypePopup
},
name: '',
props: {
......
<template>
<view>
<view :class="[list.length ? 'shop-list':'']">
<view :class="[list.length ? 'shop-list' : '']">
<view class="shop-item" v-for="(item, index) in list" :key="item.goods.goodsId">
<view class="sprite-icon icon-blue-delete" @click="deleteGoods(index)"></view>
<view class="right">
<view class="shop-name">商品名称:{{ item.goods.goodsAlias || item.goods.upgradeGoodsName || item.goods.goodsInfo.goodsName }}</view>
<!-- <view class="alias">商品别名:{{ item.goods.goodsAlias }}</view> -->
<view class="front-gear-box">
<view class="front-gear-input-box">
<view class="front-gear-label" v-if="(item.goods.merchantGoodsPosition || item.goods.upgradeGoodsPosition) && (item.goods.goodsInfo.goodsType == 1 || item.goods.upgradeGoodsType == 1 || item.goods.goodsInfo.goodsType == baseConfigData.selfBuildFilmType || item.goods.upgradeGoodsType == baseConfigData.selfBuildFilmType)">
{{ formatPosition(item.goods.merchantGoodsPosition || item.goods.upgradeGoodsPosition, positionTypeList) }}
<view class="flex flex-1 pb-24">
<view class="sprite-icon icon-blue-delete" @click="deleteGoods(index)"></view>
<view class="right">
<view class="shop-name">商品名称:{{ item.goods.goodsAlias || item.goods.upgradeGoodsName || item.goods.goodsInfo.goodsName }}</view>
<!-- <view class="alias">商品别名:{{ item.goods.goodsAlias }}</view> -->
<view class="front-gear-box">
<view class="front-gear-input-box">
<view class="front-gear-label" v-if="(item.goods.merchantGoodsPosition || item.goods.upgradeGoodsPosition) && (item.goods.goodsInfo.goodsType == 1 || item.goods.upgradeGoodsType == 1 || item.goods.goodsInfo.goodsType == baseConfigData.selfBuildFilmType || item.goods.upgradeGoodsType == baseConfigData.selfBuildFilmType)">
{{ formatPosition(item.goods.merchantGoodsPosition || item.goods.upgradeGoodsPosition, positionTypeList) }}
</view>
<view class="front-gear-input">
<view class="unit">¥</view>
<input class="uni-input" :disabled="isDisabled" type="digit" maxlength="9" placeholder="请输入价格" placeholder-style="font-size: 14px" v-model="item.goods.sellPrice" @blur="validatePrice($event, item, index)" />
</view>
</view>
<view class="front-gear-input">
<view class="unit">¥</view>
<input class="uni-input" :disabled="isDisabled" type="digit" maxlength="9" placeholder="请输入价格" placeholder-style="font-size: 14px" v-model="item.goods.sellPrice" @blur="validatePrice($event, item, index)" />
<view class="control">
<view class="minus" @click="decreaseNumber(item)">-</view>
<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>
</view>
<view class="control">
<view class="minus" @click="decreaseNumber(item)">-</view>
<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>
</view>
</view>
<!-- 28 行:折扣 / 买赠 / 组合付款策略组件 -->
<OrderStrategy v-if="getStrategyType(item)" :strategyType="getStrategyType(item)" v-model="item.goods.strategyConfig" :basePrice="getBasePrice(item)" :displayPrice="getDisplayPrice(item)" @priceChange="onPriceChange(item, $event)" />
</view>
</view>
</view>
</template>
<script>
import OrderStrategy from './OrderStrategy.vue'
export default {
name: 'Product',
props: {
......@@ -47,8 +53,15 @@ export default {
isDisabled: {
type: Boolean,
default: false
},
orderTypeCode: {
type: [String, Number],
default: ''
}
},
components: {
OrderStrategy
},
created() {
// 初始化商品数量
this.initProductNumbers()
......@@ -60,8 +73,134 @@ export default {
updated() {
// 当组件数据更新时也检查number属性
this.initProductNumbers()
// 根据订单类型初始化策略配置
this.initStrategyConfig()
},
watch: {
orderTypeCode: {
handler() {
this.initStrategyConfig()
},
immediate: true
}
},
methods: {
// 根据订单类型获取策略类型
getStrategyType(item) {
const orderType = String(this.orderTypeCode || '')
// '1' 正常订单、'4' 冲量活动:不显示策略组件
if (orderType === '1' || orderType === '4') {
return null
}
// '2' 打折策略
if (orderType === '2') {
return 'discount'
}
// '3' 买赠策略
if (orderType === '3') {
return 'gift'
}
// '5' 组合付款
if (orderType === '5') {
return 'combined'
}
return null
},
// 计算基础价格(单价 * 数量)
getBasePrice(item) {
if (!item || !item.goods) return 0
const sellPrice = parseFloat(item.goods.sellPrice || 0)
const number = parseInt(item.goods.number || 1)
const basePrice = sellPrice * number
// 四舍五入保留两位小数
return Math.round(basePrice * 100) / 100
},
// 计算最终显示价格
getDisplayPrice(item) {
const basePrice = this.getBasePrice(item)
if (!basePrice) return '¥0.00'
const orderType = String(this.orderTypeCode || '')
const strategyConfig = item.goods.strategyConfig || {}
// '2' 打折策略
if (orderType === '2') {
if (strategyConfig.mode === 'ratio' && strategyConfig.discountRatio) {
// 折扣比例:1-10,表示 1 折到 10 折(即 0.1 到 1.0)
const ratio = parseFloat(strategyConfig.discountRatio)
if (ratio >= 1 && ratio <= 10) {
const finalPrice = basePrice * (ratio / 10)
return '¥' + (Math.round(finalPrice * 100) / 100).toFixed(2)
}
} else if (strategyConfig.mode === 'amount' && strategyConfig.discountAmount) {
// 折扣金额:0 到不能大于基础价格
const discountAmount = parseFloat(strategyConfig.discountAmount)
if (discountAmount >= 0 && discountAmount <= basePrice) {
const finalPrice = basePrice - discountAmount
return '¥' + (Math.round(finalPrice * 100) / 100).toFixed(2)
}
}
return '¥' + basePrice.toFixed(2)
}
// '3' 买赠策略
if (orderType === '3') {
if (strategyConfig.isGift === '1') {
return '¥0.00'
}
return '¥' + basePrice.toFixed(2)
}
// '5' 组合付款
if (orderType === '5') {
if (strategyConfig.mode === 'deduct' && strategyConfig.deductAmount) {
// 抵扣金额:0 到不能大于基础价格
const deductAmount = parseFloat(strategyConfig.deductAmount)
if (deductAmount >= 0 && deductAmount <= basePrice) {
const finalPrice = basePrice - deductAmount
return '¥' + (Math.round(finalPrice * 100) / 100).toFixed(2)
}
}
return '¥' + basePrice.toFixed(2)
}
return '¥' + basePrice.toFixed(2)
},
// 价格变化回调
onPriceChange(item, finalPrice) {
// 可以在这里更新商品的其他价格相关字段
this.$set(item.goods, 'finalPrice', finalPrice)
this.$emit('changeTotalPrice')
},
// 初始化策略配置
initStrategyConfig() {
if (!this.list || this.list.length === 0) return
const strategyType = this.getStrategyType({})
if (!strategyType) return
this.list.forEach(item => {
if (!item.goods) return
// 如果还没有 strategyConfig,初始化一个默认值
if (!item.goods.strategyConfig) {
if (strategyType === 'discount') {
this.$set(item.goods, 'strategyConfig', {
mode: 'none',
discountRatio: '',
discountAmount: ''
})
} else if (strategyType === 'gift') {
this.$set(item.goods, 'strategyConfig', {
isGift: '0'
})
} else if (strategyType === 'combined') {
this.$set(item.goods, 'strategyConfig', {
mode: 'none',
deductAmount: ''
})
}
}
})
},
// 初始化商品数量方法
initProductNumbers() {
if (this.list && this.list.length > 0) {
......@@ -127,6 +266,8 @@ export default {
// 更新值
// this.$set(item.goods, 'sellPrice', value)
this.$set(this.list[index].goods, 'sellPrice', value)
// 价格变化时,如果已选择订单类型,触发策略组件重新计算价格
this.$forceUpdate()
this.$emit('changeTotalPrice')
},
// 验证数量输入
......@@ -140,6 +281,8 @@ export default {
}
// 更新值
this.$set(item.goods, 'number', value)
// 数量变化时,如果已选择订单类型,触发策略组件重新计算价格
this.$forceUpdate()
this.$emit('changeTotalPrice')
},
// 增加数量
......@@ -181,8 +324,6 @@ export default {
padding: toRpx(12) toRpx(32) toRpx(12) 0;
.shop-item {
display: flex;
align-items: center;
background-color: #f5f7fa;
border-radius: toRpx(16);
margin-bottom: toRpx(16);
......
......@@ -127,6 +127,13 @@ const FORM_LIST = [
required: true
},
{
label: '订单类型',
value: 'orderType',
type: 'select',
key: 'name',
required: true
},
{
label: '请选择产品',
onlyLabel: true,
required: true,
......@@ -611,6 +618,11 @@ const popupTypeEnum = {
13: {
key: 'todayShow',
list: ''
},
28: {
// 订单类型弹窗(OrderTypePopup)
key: 'orderType',
list: ''
}
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!