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: {
......
......@@ -2,110 +2,44 @@
<view class="order">
<view class="common-title">{{ orderCreateType == 'createWithPay' ? '新建工单' : '补录订单' }}</view>
<view class="box">
<scroll-view
class="scroll-view"
scroll-y="true"
>
<scroll-view class="scroll-view" scroll-y="true">
<view class="box-content">
<GlCell
:formList="formList"
:formData="orderObj"
@radioChange="radioChange"
@inputBlur="inputBlur"
@handleCell="handleCell"
>
<GlCell :formList="formList" :formData="orderObj" @radioChange="radioChange" @inputBlur="inputBlur" @handleCell="handleCell">
<template slot="frontGear">
<Product
v-if="orderObj.frontGear"
@changeTotalPrice="changeTotalPrice"
:list="orderObj.frontGear"
:positionTypeList="positionTypeList"
:baseConfigData="baseConfigData"
></Product>
<Product v-if="orderObj.frontGear" @changeTotalPrice="changeTotalPrice" :list="orderObj.frontGear" :positionTypeList="positionTypeList" :baseConfigData="baseConfigData" :orderTypeCode="orderObj.orderTypeCode"></Product>
</template>
<template slot="frontWindow">
<Product
v-if="orderObj.frontWindow"
@changeTotalPrice="changeTotalPrice"
:list="orderObj.frontWindow"
:positionTypeList="positionTypeList"
:baseConfigData="baseConfigData"
></Product>
<Product v-if="orderObj.frontWindow" @changeTotalPrice="changeTotalPrice" :list="orderObj.frontWindow" :positionTypeList="positionTypeList" :baseConfigData="baseConfigData" :orderTypeCode="orderObj.orderTypeCode"></Product>
</template>
<template slot="rearWindow">
<Product
v-if="orderObj.rearWindow"
@changeTotalPrice="changeTotalPrice"
:list="orderObj.rearWindow"
:positionTypeList="positionTypeList"
:baseConfigData="baseConfigData"
></Product>
<Product v-if="orderObj.rearWindow" @changeTotalPrice="changeTotalPrice" :list="orderObj.rearWindow" :positionTypeList="positionTypeList" :baseConfigData="baseConfigData" :orderTypeCode="orderObj.orderTypeCode"></Product>
</template>
<template slot="rearGear">
<Product
v-if="orderObj.rearGear"
@changeTotalPrice="changeTotalPrice"
:list="orderObj.rearGear"
:positionTypeList="positionTypeList"
:baseConfigData="baseConfigData"
></Product>
<Product v-if="orderObj.rearGear" @changeTotalPrice="changeTotalPrice" :list="orderObj.rearGear" :positionTypeList="positionTypeList" :baseConfigData="baseConfigData" :orderTypeCode="orderObj.orderTypeCode"></Product>
</template>
<template slot="sunRoof">
<Product
v-if="orderObj.sunRoof"
@changeTotalPrice="changeTotalPrice"
:list="orderObj.sunRoof"
:positionTypeList="positionTypeList"
:baseConfigData="baseConfigData"
></Product>
<Product v-if="orderObj.sunRoof" @changeTotalPrice="changeTotalPrice" :list="orderObj.sunRoof" :positionTypeList="positionTypeList" :baseConfigData="baseConfigData" :orderTypeCode="orderObj.orderTypeCode"></Product>
</template>
<template slot="package">
<Package
v-if="orderObj.package"
@changeTotalPrice="changeTotalPrice"
:list="orderObj.package"
:positionTypeList="positionTypeList"
></Package>
<Package v-if="orderObj.package" @changeTotalPrice="changeTotalPrice" :list="orderObj.package" :positionTypeList="positionTypeList"></Package>
</template>
<template slot="skuGoods">
<SkuGoods
v-if="orderObj.skuGoods"
:list="orderObj.skuGoods"
@changeTotalPrice="changeTotalPrice"
:positionTypeList="positionTypeList"
:baseConfigData="baseConfigData"
></SkuGoods>
<view
class="total"
v-if="totalPrice > 0"
>
<SkuGoods v-if="orderObj.skuGoods" :list="orderObj.skuGoods" @changeTotalPrice="changeTotalPrice" :positionTypeList="positionTypeList" :baseConfigData="baseConfigData"></SkuGoods>
<view class="total" v-if="totalPrice > 0">
<view class="total-left">总价</view>
<view class="total-right">¥{{ totalPrice }}</view>
</view>
</template>
<template slot="otherPay">
<view
v-if="showPayTips"
class="pay-tips"
>其他收款:当客户已向嘀加付款但无法使用流水补录时,新建工单应选择收款方为「嘀加收款」且支付方为「其他收款」。</view>
<view v-if="showPayTips" class="pay-tips">其他收款:当客户已向嘀加付款但无法使用流水补录时,新建工单应选择收款方为「嘀加收款」且支付方为「其他收款」。</view>
</template>
</GlCell>
</view>
<view
@click="submit"
class="btn"
>直接下单</view>
<view @click="submit" class="btn">直接下单</view>
</scroll-view>
</view>
<!-- 弹窗 -->
<order-popup
ref="orderPopup"
:data="orderObj"
:dataKey="valueKey"
@onConfirm="onConfirm"
:externalData="externalData"
:popupType="popupType"
/>
<order-popup ref="orderPopup" :data="orderObj" :dataKey="valueKey" @onConfirm="onConfirm" :externalData="externalData" :popupType="popupType" />
</view>
</template>
......@@ -137,7 +71,7 @@ export default {
},
watch: {
transmissionOfData: {
handler (newVal) {
handler(newVal) {
if (newVal) {
// 处理交易数据
const handleTransactionData = newVal => {
......@@ -248,7 +182,7 @@ export default {
immediate: true
}
},
data () {
data() {
return {
orderCreateType: 'createWithPay', // supplementOrder(补录订单) createWithPay(新增)
formList: utils.deepClone(FORM_LIST),
......@@ -296,19 +230,19 @@ export default {
}
},
computed: {
showPayTips () {
showPayTips() {
if (this.orderObj.payeeType == 0 && this.orderObj.selectPayType == 7) return true
else return false
}
},
mounted () {
mounted() {
console.log('mounted', this.orderCreateType)
this.userInfo = uni.$storage.get('userInfo') || {}
this.baseConfigData = uni.$storage.get('mock_data') || {}
this.initData()
},
methods: {
initData () {
initData() {
console.log('initData', this.orderCreateType, this.orderObj.id)
// 埋点
if (this.orderCreateType == 'createWithPay' && !this.orderObj.id) {
......@@ -367,7 +301,7 @@ export default {
if (this.orderCreateType == 'createWithPay' && !this.orderObj.id) this.getLastUserOrderInfo() // 补录订单和有id的情况,不需要设置默认值
},
// 选择行事件
handleCell (val) {
handleCell(val) {
console.log(val, this.orderObj)
// 获取当前选中的popupType
this.popupType = Object.keys(this.popupTypeEnum).find(key => this.popupTypeEnum[key].key === val.value) * 1
......@@ -388,7 +322,7 @@ export default {
this.$refs.orderPopup.open()
},
// 单选框change事件
radioChange (e, val) {
radioChange(e, val) {
console.log(e, val)
this.$set(this.orderObj, val.value, e.detail.value)
if (val.value == 'payeeType') {
......@@ -396,7 +330,7 @@ export default {
}
},
// 弹窗确认回调
onConfirm (val, flag) {
onConfirm(val, flag) {
console.log(val, flag, 'onConfirm')
this.externalData = []
// const { chooseContent } = val
......@@ -422,6 +356,11 @@ export default {
customerCouponCode: customerCouponCode
})
this.$set(this.orderObj, 'couponInfo', couponName + customerCouponCode)
} else if (_typeValue.key == 'orderType') {
// 订单类型
// 保存显示文案和编码,方便后续接口使用
this.$set(this.orderObj, 'orderType', chooseContent.name)
this.$set(this.orderObj, 'orderTypeCode', chooseContent.value)
} else if (productFields.includes(_typeValue.key)) {
if (_typeValue.key == 'skuGoods') {
if (!this.orderObj[_typeValue.key]) {
......@@ -453,7 +392,7 @@ export default {
}
},
// 输入框失去焦点事件
inputBlur (e, val) {
inputBlur(e, val) {
console.log(e, val)
this.orderObj.customer[val.value] = this.orderObj[val.value]
......@@ -475,7 +414,7 @@ export default {
}
},
// 校验必填等规则
checkRequired () {
checkRequired() {
const phoneRex = /^[1]([3-9])[0-9]{9}$/
// 把formList中所有required为true的对象放到一个数组中
const requiredArr = []
......@@ -548,7 +487,7 @@ export default {
},
// 提交
async submit () {
async submit() {
// VIN车架号-动态校验
const carVin = this.orderObj.standNo
console.log('validateState', this.validateState)
......@@ -650,7 +589,7 @@ export default {
}
},
// 计算所有产品的总价
changeTotalPrice () {
changeTotalPrice() {
let total = 0
// 遍历所有商品
const productFields = ['frontGear', 'frontWindow', 'rearGear', 'rearWindow', 'sunRoof', 'package', 'skuGoods']
......@@ -685,7 +624,7 @@ export default {
},
// 获取上一个订单的销售顾问信息 并且不是再次下单
async getLastUserOrderInfo () {
async getLastUserOrderInfo() {
const res = await uni.$api.boutiqueApi.getLastUserOrderInfo({
sellerUserId: this.userInfo.subLoginUser.uuid
})
......@@ -698,7 +637,7 @@ export default {
this.getEmployeeList()
}
},
async getShopMerchantPointConfig (merchantId) {
async getShopMerchantPointConfig(merchantId) {
const res = await uni.$api.boutiqueApi.getShopMerchantPointConfig({ merchantId })
if (res.pointsMultiRole == 'Y') {
const employeeCell = this.formList[0].find(item => item.label === '销售顾问')
......@@ -711,7 +650,7 @@ export default {
}
},
// 判断二级流量方
async getSubShopMerchantList (merchantId) {
async getSubShopMerchantList(merchantId) {
const res = await uni.$api.boutiqueApi.getSubShopMerchantList({ merchantId })
if (res && res.length) {
this.subShopMerchantList = res
......@@ -722,7 +661,7 @@ export default {
}
},
// 动态获取 车型 车架 车牌 是否必填
getYQorderInfo () {
getYQorderInfo() {
return new Promise(async (resolve, reject) => {
const YQorderSetting = uni.$storage.get('boutique_YQorderSetting')
if (YQorderSetting) return resolve(YQorderSetting)
......@@ -743,16 +682,15 @@ export default {
notUpgradeExperience: 'foEfRequiredFlag',
notUpgradeRejectionReason: 'foRrRequiredFlag'
}
; (data.orderFieldSettingList || []).forEach(e => {
const key = keyMap[e.fieldKey] || e.fieldKey
YQorderSetting[key] = e.isRequired ? 'Y' : 'N'
})
;(data.orderFieldSettingList || []).forEach(e => {
const key = keyMap[e.fieldKey] || e.fieldKey
YQorderSetting[key] = e.isRequired ? 'Y' : 'N'
})
YQorderSetting.shopMerchantId = userInfo.shopMerchantId
// 过滤园区店是否需要屏蔽手机号选项
let filterYqPhoneConfig = JSON.parse(data.yqPhoneConfig)
YQorderSetting.yqPhoneConfig =
filterYqPhoneConfig?.find(item => item.yqMerchantId == merchantId)
YQorderSetting.yqPhoneConfig = filterYqPhoneConfig?.find(item => item.yqMerchantId == merchantId)
console.log(YQorderSetting)
uni.$storage.set('boutique_YQorderSetting', YQorderSetting)
......@@ -762,7 +700,7 @@ export default {
})
},
// 获取车型、车架号、车牌号必填规则
async getSetting () {
async getSetting() {
const res = await this.getYQorderInfo()
const dictionaryObj = {
carTypeRequiredFlag: 'carBrand',
......@@ -775,7 +713,7 @@ export default {
}
},
// 获取园区店支付方式
async getConfig () {
async getConfig() {
const res = await uni.$api.boutiqueApi.getYqStoreConfig({
yqMerchantId: this.orderObj.sellerMerchantId
})
......@@ -801,7 +739,7 @@ export default {
this.changePayee()
console.log(this.djPayList, this.merchantPayList, 'list')
},
changePayee () {
changePayee() {
const cell = this.formList[2].find(item => item.value === 'selectPayType')
if (cell) {
cell.radioList = this.orderObj.payeeType == 1 ? this.merchantPayList : this.djPayList
......@@ -813,7 +751,7 @@ export default {
}
},
// 获取 销售顾问列表
async getEmployeeList () {
async getEmployeeList() {
const { userInfo, orderObj } = this
const { shopMerchantId, sceneType, merchantId } = userInfo,
data = await uni.$api.popupApi.getEmployeeList({
......@@ -826,12 +764,12 @@ export default {
this.orderObj.userId = data[0].uuid
}
},
async getPositionList () {
async getPositionList() {
const res = await uni.$api.boutiqueApi.getPositionList({})
this.positionTypeList = res
},
// 商品列表
async getSelectOrderGoodsList () {
async getSelectOrderGoodsList() {
const { userInfo } = this
const res = await uni.$api.boutiqueApi.getSelectOrderGoodsList({
merchantId: userInfo.shopMerchantId,
......@@ -1013,7 +951,7 @@ export default {
console.log(this.orderObj, 'this.orderObj')
this.changeTotalPrice()
},
handleSpecificationsEcho (item) {
handleSpecificationsEcho(item) {
let skuArr = []
const { otherProduct } = this,
arr = item.specificationData.split('/'),
......
<template>
<view class="strategy-row">
<!-- 打折策略 -->
<view v-if="strategyType === 'discount'" class="strategy-left">
<view class="tab-group">
<view v-for="tab in discountTabs" :key="tab.value" class="tab-item" :class="{ 'tab-item--active': localState.mode === tab.value }" @click="onDiscountTabChange(tab.value)">
{{ tab.label }}
</view>
</view>
<view v-if="localState.mode === 'ratio' || localState.mode === 'amount'" class="input-box">
<!-- 折扣比例 -->
<view v-if="localState.mode === 'ratio'" class="ratio-input">
<input class="ratio-input-inner" type="digit" :placeholder="ratioPlaceholder" placeholder-class="placeholder" :value="localState.discountRatio" @input="onInput('discountRatio', $event.detail.value)" />
<text class="unit">折</text>
</view>
<!-- 折扣金额 -->
<view v-else class="amount-input">
<view class="unit">¥</view>
<input class="input amount-input-inner" type="digit" placeholder="请输入" placeholder-class="placeholder" :value="localState.discountAmount" @input="onInput('discountAmount', $event.detail.value)" />
</view>
</view>
</view>
<!-- 买赠策略 -->
<view v-else-if="strategyType === 'gift'" class="strategy-left flex">
<view class="label">是否为赠品</view>
<radio-group class="radio-group value" @change="onGiftRadioChange">
<label v-for="item in giftOptions" :key="item.value" class="uni-list-cell uni-list-cell-pd">
<radio style="transform: scale(0.65) translateY(-3px)" :value="item.value" :checked="item.value === localState.isGift" />
<view class="radio-name">{{ item.label }}</view>
</label>
</radio-group>
</view>
<!-- 组合付款 -->
<view v-else-if="strategyType === 'combined'" class="strategy-left">
<view class="tab-group">
<view v-for="tab in combinedTabs" :key="tab.value" class="tab-item" :class="{ 'tab-item--active': localState.mode === tab.value }" @click="onCombinedTabChange(tab.value)">
{{ tab.label }}
</view>
</view>
<view v-if="localState.mode === 'deduct'" class="input-box">
<view class="amount-input">
<view class="unit">¥</view>
<input class="input amount-input-inner" type="digit" placeholder="请输入" placeholder-class="placeholder" :value="localState.deductAmount" @input="onInput('deductAmount', $event.detail.value)" />
</view>
</view>
</view>
<!-- 右侧价格展示 -->
<view v-if="showPrice" class="strategy-right">
<view class="price-label">价格</view>
<view class="price-value">{{ computedPrice }}</view>
</view>
</view>
</template>
<script>
export default {
name: 'OrderStrategy',
props: {
// discount(打折策略)/ gift(买赠策略)/ combined(组合付款)
strategyType: {
type: String,
default: 'discount'
},
// v-model 绑定的值
value: {
type: Object,
default() {
return {}
}
},
// 右侧价格展示文案(已废弃,改用计算值)
priceText: {
type: String,
default: '-'
},
// 基础价格(单价 * 数量)
basePrice: {
type: [Number, String],
default: 0
},
showPrice: {
type: Boolean,
default: true
}
},
data() {
return {
localState: {
// mode: ratio / amount / none / deduct
mode: 'none',
discountRatio: '',
discountAmount: '',
isGift: '0',
deductAmount: ''
},
discountTabs: [
{ label: '无折扣', value: 'none' },
{ label: '折扣比例', value: 'ratio' },
{ label: '折扣金额', value: 'amount' }
],
combinedTabs: [
{ label: '无抵扣', value: 'none' },
{ label: '抵扣金额', value: 'deduct' }
],
giftOptions: [
{ label: '是', value: '1' },
{ label: '否', value: '0' }
]
}
},
computed: {
// 计算最终价格
computedPrice() {
const basePrice = parseFloat(this.basePrice || 0)
if (!basePrice) return '-'
// 打折策略
if (this.strategyType === 'discount') {
if (this.localState.mode === 'ratio' && this.localState.discountRatio) {
const ratio = parseFloat(this.localState.discountRatio)
// 折扣比例:1-10,表示 1 折到 10 折(即 0.1 到 1.0)
if (ratio >= 1 && ratio <= 10) {
const finalPrice = basePrice * (ratio / 10)
return '¥' + (Math.round(finalPrice * 100) / 100).toFixed(2)
}
} else if (this.localState.mode === 'amount' && this.localState.discountAmount) {
const discountAmount = parseFloat(this.localState.discountAmount)
// 折扣金额:0 到不能大于基础价格
if (discountAmount >= 0 && discountAmount <= basePrice) {
const finalPrice = basePrice - discountAmount
return '¥' + (Math.round(finalPrice * 100) / 100).toFixed(2)
}
}
return '¥' + basePrice.toFixed(2)
}
// 买赠策略
if (this.strategyType === 'gift') {
if (this.localState.isGift === '1') {
return '¥0.00'
}
return '¥' + basePrice.toFixed(2)
}
// 组合付款
if (this.strategyType === 'combined') {
if (this.localState.mode === 'deduct' && this.localState.deductAmount) {
const deductAmount = parseFloat(this.localState.deductAmount)
// 抵扣金额:0 到不能大于基础价格
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)
}
},
watch: {
// 外部 v-model -> 内部 state
value: {
handler(val) {
if (!val) return
Object.keys(this.localState).forEach(key => {
if (val[key] !== undefined) {
this.localState[key] = val[key]
}
})
},
deep: true,
immediate: true
},
// 内部 state 改变 -> 向外通知
localState: {
handler() {
this.$emit('input', { ...this.localState })
this.$emit('change', { ...this.localState })
// 价格变化时通知父组件
const basePrice = parseFloat(this.basePrice || 0)
if (basePrice) {
const finalPrice = this.calculateFinalPrice(basePrice)
this.$emit('priceChange', finalPrice)
}
},
deep: true
},
// 基础价格变化时重新计算
basePrice: {
handler() {
const basePrice = parseFloat(this.basePrice || 0)
if (basePrice) {
const finalPrice = this.calculateFinalPrice(basePrice)
this.$emit('priceChange', finalPrice)
}
},
immediate: true
}
},
methods: {
// 计算最终价格(内部方法)
calculateFinalPrice(basePrice) {
const bp = parseFloat(basePrice || 0)
if (!bp) return 0
// 打折策略
if (this.strategyType === 'discount') {
if (this.localState.mode === 'ratio' && this.localState.discountRatio) {
const ratio = parseFloat(this.localState.discountRatio)
if (ratio >= 1 && ratio <= 10) {
return Math.round(bp * (ratio / 10) * 100) / 100
}
} else if (this.localState.mode === 'amount' && this.localState.discountAmount) {
const discountAmount = parseFloat(this.localState.discountAmount)
if (discountAmount >= 0 && discountAmount <= bp) {
return Math.round((bp - discountAmount) * 100) / 100
}
}
return Math.round(bp * 100) / 100
}
// 买赠策略
if (this.strategyType === 'gift') {
if (this.localState.isGift === '1') {
return 0
}
return Math.round(bp * 100) / 100
}
// 组合付款
if (this.strategyType === 'combined') {
if (this.localState.mode === 'deduct' && this.localState.deductAmount) {
const deductAmount = parseFloat(this.localState.deductAmount)
if (deductAmount >= 0 && deductAmount <= bp) {
return Math.round((bp - deductAmount) * 100) / 100
}
}
return Math.round(bp * 100) / 100
}
return Math.round(bp * 100) / 100
},
onInput(key, val) {
let v = (val || '').replace(/[^\d.]/g, '')
const parts = v.split('.')
if (parts.length > 2) {
v = parts[0] + '.' + parts.slice(1).join('')
}
if (v.indexOf('.') > -1) {
const [intPart, decPart] = v.split('.')
v = intPart + '.' + (decPart || '').slice(0, 2)
}
const basePrice = parseFloat(this.basePrice || 0)
// 限制输入值范围,直接修正而不是提示
if (key === 'discountRatio') {
// 折扣比例:限制在 1-10 之间
if (v) {
const ratio = parseFloat(v)
if (ratio < 1) {
v = '1'
} else if (ratio > 10) {
v = '10'
} else {
// 保留两位小数,但如果输入的是整数就不显示小数点
const rounded = Math.round(ratio * 100) / 100
v = rounded === Math.floor(rounded) ? rounded.toString() : rounded.toFixed(2)
}
}
} else if (key === 'discountAmount' || key === 'deductAmount') {
// 折扣金额/抵扣金额:限制在 0 到基础价格之间
if (v) {
const amount = parseFloat(v)
if (isNaN(amount)) {
v = ''
} else if (amount < 0) {
v = '0'
} else if (basePrice > 0 && amount > basePrice) {
// 直接限制为最大值,保留两位小数
v = basePrice.toFixed(2)
} else {
// 确保保留两位小数
const rounded = Math.round(amount * 100) / 100
v = rounded === Math.floor(rounded) ? rounded.toString() : rounded.toFixed(2)
}
}
}
this.localState[key] = v
},
// 买赠单选框 change,保持与收款方式一致的事件风格
onGiftRadioChange(e) {
this.onGiftChange(e.detail.value)
},
onDiscountTabChange(mode) {
this.localState.mode = mode
if (mode === 'none') {
this.localState.discountRatio = ''
this.localState.discountAmount = ''
}
},
onCombinedTabChange(mode) {
this.localState.mode = mode
if (mode === 'none') {
this.localState.deductAmount = ''
}
},
onGiftChange(val) {
this.localState.isGift = val
}
}
}
</script>
<style scoped lang="scss">
.strategy-row {
display: flex;
align-items: center;
justify-content: space-between;
padding: toRpx(24) toRpx(24) 0 toRpx(24);
border-top: toRpx(2) solid #ebedf0;
box-sizing: border-box;
}
.strategy-left {
display: flex;
align-items: center;
}
.tab-group {
display: flex;
background: #ededf2;
border-radius: toRpx(16);
overflow: hidden;
padding: toRpx(8);
box-sizing: border-box;
.tab-item {
padding: toRpx(8) toRpx(16);
font-size: toRpx(26);
color: #222222;
font-weight: 400;
}
.tab-item--active {
background-color: #ffffff;
border-radius: toRpx(6);
}
}
.input-box {
margin-left: toRpx(16);
}
.input {
width: toRpx(160);
height: toRpx(64);
padding: 0 toRpx(16);
border-radius: toRpx(12);
background-color: #ffffff;
box-sizing: border-box;
color: #333333;
}
.placeholder {
color: #b6b6b8;
font-size: toRpx(28);
}
.ratio-input {
display: flex;
align-items: center;
background-color: #ffffff;
border: toRpx(2) solid #eff0f2;
border-radius: toRpx(12);
padding: 0 toRpx(16);
height: toRpx(64);
width: toRpx(160);
font-size: toRpx(28);
line-height: toRpx(64);
box-sizing: border-box;
.ratio-input-inner {
flex: 1;
border: none;
padding: 0;
background: transparent;
height: 100%;
width: 100%;
color: #333333;
box-sizing: border-box;
}
.unit {
color: #333333;
margin-left: toRpx(8);
flex-shrink: 0;
line-height: toRpx(64);
display: inline-block;
}
}
.amount-input {
display: flex;
align-items: center;
background-color: #ffffff;
border-radius: toRpx(12);
padding-left: toRpx(24);
.unit {
font-size: toRpx(26);
color: #333;
flex-shrink: 0;
}
.amount-input-inner {
width: toRpx(140);
padding-left: toRpx(8);
text-align: right;
}
}
.label {
font-size: toRpx(28);
color: #222222;
margin-right: toRpx(24);
flex-shrink: 0;
line-height: 1; // 使用 line-height 而不是固定高度,确保与右侧文字基线对齐
}
.radio-group {
display: flex;
align-items: center;
&.value {
justify-content: flex-end;
width: 100%;
}
.uni-list-cell {
margin-left: toRpx(48);
&:first-child {
margin-left: 0;
}
}
.radio-name {
display: inline-block;
color: #292d33;
font-size: toRpx(28);
line-height: 1; // 确保与左侧 label 的 line-height 一致
}
}
.radio-item {
display: flex;
align-items: center;
margin-right: toRpx(24);
}
.radio-dot {
width: toRpx(28);
height: toRpx(28);
border-radius: 50%;
border: toRpx(2) solid #d1d5db;
margin-right: toRpx(8);
}
.radio-dot--active {
border-color: #2c66f7;
background-color: #2c66f7;
}
.radio-text {
font-size: toRpx(26);
color: #666;
}
.radio-item--active .radio-text {
color: #2c66f7;
}
.strategy-right {
display: flex;
align-items: center;
font-size: toRpx(26);
color: #333;
.price-label {
margin-right: toRpx(8);
}
.price-value {
color: #f45001;
}
}
</style>
<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!