Commit b38033eb by 胡悦

feat(订单创建): 新增商品总价计算和销售顾问自动填充功能

- 在Product组件中添加删除商品功能并触发总价计算
- 使用v-for循环渲染多个商品区域,减少重复代码
- 新增商品总价显示区域
- 添加获取上一笔订单销售顾问信息的API调用
- 扩展popupTypeEnum支持更多商品类型
- 优化表单提交逻辑,支持多种商品类型合并计算
1 parent 85fcb5e1
...@@ -227,5 +227,13 @@ module.exports = { ...@@ -227,5 +227,13 @@ module.exports = {
/** 获取商户基本信息 */ /** 获取商户基本信息 */
getServiceBaseInfo(data) { getServiceBaseInfo(data) {
return http.post({ method: 'dj.api.smartcarlife.serviceMerchant.getServiceBaseInfo', projectName: 'boutique', ...data }) return http.post({ method: 'dj.api.smartcarlife.serviceMerchant.getServiceBaseInfo', projectName: 'boutique', ...data })
} },
/** 获取转化员上一笔订单的销售顾问 */
getLastUserOrderInfo(data) {
return http.post({
method: 'dj.api.smartcarlife.order.getLastUser',
projectName: 'boutique',
...data
})
},
} }
...@@ -6,12 +6,26 @@ ...@@ -6,12 +6,26 @@
<view class="box-content"> <view class="box-content">
<GlCell :formList="formList" :formData="orderObj" @radioChange="radioChange" @inputBlur="inputBlur" <GlCell :formList="formList" :formData="orderObj" @radioChange="radioChange" @inputBlur="inputBlur"
@handleCell="handleCell"> @handleCell="handleCell">
<template slot="frontGear"> <!-- 使用v-for循环渲染产品组件,减少重复代码 -->
<Product v-if="orderObj.frontGear && orderObj.frontGear.length" :list="orderObj.frontGear" :positionTypeList="positionTypeList" :baseConfigData="baseConfigData"></Product> <template v-for="(_, slotName) in productSlots" :slot="slotName" >
<Product
:key="slotName"
v-if="orderObj[slotName] && orderObj[slotName].length"
@changeTotalPrice="changeTotalPrice"
:list="orderObj[slotName]"
:positionTypeList="positionTypeList"
:baseConfigData="baseConfigData">
</Product>
</template> </template>
<template slot="package"> <template slot="package">
<Package></Package> <Package></Package>
</template> </template>
<template slot="otherGoods">
<view class="total" v-if="totalPrice > 0">
<view class="total-left">总价</view>
<view class="total-right">¥{{totalPrice}}</view>
</view>
</template>
<template slot="otherPay"> <template slot="otherPay">
<view v-if="showPayTips" class="pay-tips">其他收款:当客户已向嘀加付款但无法使用流水补录时,新建工单应选择收款方为「嘀加收款」且支付方为「其他收款」。</view> <view v-if="showPayTips" class="pay-tips">其他收款:当客户已向嘀加付款但无法使用流水补录时,新建工单应选择收款方为「嘀加收款」且支付方为「其他收款」。</view>
</template> </template>
...@@ -52,6 +66,9 @@ export default { ...@@ -52,6 +66,9 @@ export default {
handler(newVal) { handler(newVal) {
if (newVal) { if (newVal) {
console.log('接收到的交易数据:', newVal) console.log('接收到的交易数据:', newVal)
this.orderCreateType = 'supplementOrder'
this.orderObj.outTradeNo = newVal.selectedItems.map(item => item.outTradeNo).join(',')
this.orderObj.tradeNo = newVal.selectedItems.map(item => item.tradeNo).join(',')
} }
}, },
immediate: true immediate: true
...@@ -59,6 +76,7 @@ export default { ...@@ -59,6 +76,7 @@ export default {
}, },
data() { data() {
return { return {
orderCreateType: "createWithPay", // supplementOrder(补录订单) createWithPay(新增)
formList: utils.deepClone(FORM_LIST), formList: utils.deepClone(FORM_LIST),
userInfo: {}, userInfo: {},
baseConfigData: {}, baseConfigData: {},
...@@ -70,6 +88,10 @@ export default { ...@@ -70,6 +88,10 @@ export default {
payeeType: 1, payeeType: 1,
salesType: '0', salesType: '0',
frontGear: null, frontGear: null,
frontWindow: null,
rearWindow: null,
rearGear: null,
sunRoof: null,
}, // 弹窗传入的数据}, }, // 弹窗传入的数据},
popupType: 0, popupType: 0,
popupTypeEnum, popupTypeEnum,
...@@ -83,6 +105,15 @@ export default { ...@@ -83,6 +105,15 @@ export default {
goodsList: [], goodsList: [],
positionTypeList: [], positionTypeList: [],
valueKey: '', valueKey: '',
totalPrice: 0,
// 产品槽位配置,用于循环渲染产品组件
productSlots: {
frontGear: true,
frontWindow: true,
rearGear: true,
rearWindow: true,
sunRoof: true
},
} }
}, },
computed: { computed: {
...@@ -95,7 +126,7 @@ export default { ...@@ -95,7 +126,7 @@ export default {
console.log(options, 'options') console.log(options, 'options')
}, },
mounted() { mounted() {
console.log('mounted') console.log('mounted', this.orderCreateType)
this.userInfo = uni.$storage.get('userInfo') || {} this.userInfo = uni.$storage.get('userInfo') || {}
this.baseConfigData = uni.$storage.get('mock_data') || {} this.baseConfigData = uni.$storage.get('mock_data') || {}
const { userInfo } = this const { userInfo } = this
...@@ -117,9 +148,10 @@ export default { ...@@ -117,9 +148,10 @@ export default {
this.getSubShopMerchantList(userInfo.shopMerchantId) this.getSubShopMerchantList(userInfo.shopMerchantId)
this.getSetting() this.getSetting()
this.getConfig() this.getConfig()
this.getEmployeeList() // this.getEmployeeList()
this.getSelectOrderGoodsList() this.getSelectOrderGoodsList()
this.getPositionList() this.getPositionList()
if (this.orderCreateType == 'createWithPay') this.getLastUserOrderInfo() // 补录订单不需要设置默认值
}, },
// 选择行事件 // 选择行事件
handleCell(val) { handleCell(val) {
...@@ -149,12 +181,15 @@ export default { ...@@ -149,12 +181,15 @@ export default {
this.changePayee() this.changePayee()
} }
}, },
// 弹窗确认回调
onConfirm(val) { onConfirm(val) {
console.log(val, 'onConfirm') console.log(val, 'onConfirm')
const { chooseContent } = val const { chooseContent } = val
// 根据popupTypeEnum优化处理 // 根据popupTypeEnum优化处理
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'];
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}`)
...@@ -171,10 +206,14 @@ export default { ...@@ -171,10 +206,14 @@ export default {
customerCouponCode: customerCouponCode customerCouponCode: customerCouponCode
}) })
this.$set(this.orderObj, 'couponInfo', couponName + customerCouponCode) this.$set(this.orderObj, 'couponInfo', couponName + customerCouponCode)
} else if (_typeValue.key == 'frontGear') { } else if (productFields.includes(_typeValue.key)) {
this.$set(this.orderObj, 'frontGear', val.chooseContent) // 商品类,需计算总价
this.$set(this.orderObj, _typeValue.key, val.chooseContent)
this.$nextTick(() => {
// 确保数据更新后再计算总价
this.changeTotalPrice()
})
} else if (_typeValue.key) { } else if (_typeValue.key) {
// this.formObj[_typeValue.key] = chooseContent;
this.orderObj[_typeValue.targetIdKey] = chooseContent[_typeValue.sourceIdKey] this.orderObj[_typeValue.targetIdKey] = chooseContent[_typeValue.sourceIdKey]
this.$set(this.orderObj, _typeValue.targetNameKey, chooseContent[_typeValue.sourceNameKey]) this.$set(this.orderObj, _typeValue.targetNameKey, chooseContent[_typeValue.sourceNameKey])
} }
...@@ -256,6 +295,7 @@ export default { ...@@ -256,6 +295,7 @@ export default {
async submit() { async submit() {
console.log(this.orderObj) console.log(this.orderObj)
if (!this.checkRequired()) return if (!this.checkRequired()) return
const {orderCreateType} = this
const obj = utils.deepClone(this.orderObj) const obj = utils.deepClone(this.orderObj)
const otherCustomer = ['standNo', 'plateNumber', 'customerSex', 'experienceFlag', 'salesType'] const otherCustomer = ['standNo', 'plateNumber', 'customerSex', 'experienceFlag', 'salesType']
obj.customer = { obj.customer = {
...@@ -268,8 +308,17 @@ export default { ...@@ -268,8 +308,17 @@ export default {
return acc return acc
}, {}) }, {})
} }
if (obj.frontGear) { // 将 frontGear、frontWindow、rearGear、rearWindow、sunRoof 字段合并到 goodsList 中
obj.subOrderList = obj.frontGear.map(item => { const labelFields = ['frontGear', 'frontWindow', 'rearGear', 'rearWindow', 'sunRoof']
let goodsList = []
labelFields.forEach(field => {
if (Array.isArray(obj[field]) && obj[field].length > 0) {
goodsList = goodsList.concat(obj[field]);
}
delete obj[field];
});
if (goodsList.length > 0) {
obj.subOrderList = goodsList.map(item => {
return { return {
totalPrice: item.goods.sellPrice, totalPrice: item.goods.sellPrice,
number: item.goods.number, number: item.goods.number,
...@@ -277,11 +326,10 @@ export default { ...@@ -277,11 +326,10 @@ export default {
} }
}) })
} }
delete obj.frontGear
delete obj.carBrand delete obj.carBrand
delete obj.couponInfo delete obj.couponInfo
console.log(obj, 'rucan') console.log(obj, 'rucan')
const res = await uni.$api.boutiqueApi.createWithPay(obj) const res = await uni.$api.boutiqueApi[orderCreateType](obj)
console.log(res, '===submit') console.log(res, '===submit')
if (res) { if (res) {
uni.showToast({ uni.showToast({
...@@ -290,6 +338,35 @@ export default { ...@@ -290,6 +338,35 @@ export default {
}) })
} }
}, },
// 计算所有产品的总价
changeTotalPrice() {
let total = 0
// 遍历所有产品槽位
Object.keys(this.productSlots).forEach(slotName => {
const productList = this.orderObj[slotName]
if (Array.isArray(productList) && productList.length > 0) {
// 计算每个产品的价格 * 数量,并累加到总价
productList.forEach(item => {
if (item.goods && item.goods.sellPrice && item.goods.number) {
total += parseFloat(item.goods.sellPrice) * parseInt(item.goods.number)
}
})
}
})
console.log(total, 'total')
// 更新总价
this.totalPrice = total.toFixed(2)
},
// 获取上一个订单的销售顾问信息 并且不是再次下单
async getLastUserOrderInfo() {
const res = await uni.$api.boutiqueApi.getLastUserOrderInfo({
sellerUserId: this.userInfo.subLoginUser.uuid
})
this.$set(this.orderObj, 'employeeName', res.employeeName)
this.orderObj.userId = res.userId
console.log(res, '上一个订单的销售顾问信息')
},
async getShopMerchantPointConfig(merchantId) { async getShopMerchantPointConfig(merchantId) {
const res = await uni.$api.boutiqueApi.getShopMerchantPointConfig({ merchantId }) const res = await uni.$api.boutiqueApi.getShopMerchantPointConfig({ merchantId })
console.log(res) console.log(res)
...@@ -395,8 +472,8 @@ export default { ...@@ -395,8 +472,8 @@ export default {
}) })
if (data && data.length) { if (data && data.length) {
this.employeeList = data this.employeeList = data
this.$set(this.orderObj, 'employeeName', data[0].staffName) // this.$set(this.orderObj, 'employeeName', data[0].staffName)
this.orderObj.userId = data[0].uuid // this.orderObj.userId = data[0].uuid
} }
}, },
async getPositionList() { async getPositionList() {
...@@ -631,6 +708,25 @@ export default { ...@@ -631,6 +708,25 @@ export default {
} }
} }
.total {
display: flex;
justify-content: space-between;
align-items: center;
padding: toRpx(24) toRpx(32) toRpx(24) 0;
font-size: toRpx(28);
border-bottom: toRpx(2) solid #f7f7f6;
&-left {
color: #333;
font-weight: 500;
}
&-right {
color: #f45001;
font-weight: 500;
}
}
.pay-tips { .pay-tips {
padding: toRpx(24) toRpx(24) toRpx(24) 0; padding: toRpx(24) toRpx(24) toRpx(24) 0;
font-size: toRpx(24); font-size: toRpx(24);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<view> <view>
<view class="shop-list"> <view class="shop-list">
<view class="shop-item" v-for="(item, index) in list" :key="item.goods.goodsId"> <view class="shop-item" v-for="(item, index) in list" :key="item.goods.goodsId">
<view class="sprite-icon icon-blue-delete"></view> <view class="sprite-icon icon-blue-delete" @click="deleteGoods(index)"></view>
<view class="right"> <view class="right">
<view class="shop-name">商品名称:{{ item.goods.goodsAlias || item.goods.upgradeGoodsName || <view class="shop-name">商品名称:{{ item.goods.goodsAlias || item.goods.upgradeGoodsName ||
item.goods.goodsInfo.goodsName }}</view> item.goods.goodsInfo.goodsName }}</view>
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
<input class="uni-input" type="digit" maxlength="9" placeholder="请输入价格" placeholder-style="font-size: 14px" v-model="item.goods.sellPrice" @blur="validatePrice($event, item, index)" /> <input class="uni-input" type="digit" maxlength="9" placeholder="请输入价格" placeholder-style="font-size: 14px" v-model="item.goods.sellPrice" @blur="validatePrice($event, item, index)" />
</view> </view>
</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" @input="validateNumber($event, item)" />
...@@ -105,6 +104,7 @@ export default { ...@@ -105,6 +104,7 @@ export default {
// 更新值 // 更新值
// this.$set(item.goods, 'sellPrice', value) // this.$set(item.goods, 'sellPrice', value)
this.$set(this.list[index].goods, 'sellPrice', value) this.$set(this.list[index].goods, 'sellPrice', value)
this.$emit('changeTotalPrice')
}, },
// 验证数量输入 // 验证数量输入
validateNumber(event, item) { validateNumber(event, item) {
...@@ -117,6 +117,7 @@ export default { ...@@ -117,6 +117,7 @@ export default {
} }
// 更新值 // 更新值
this.$set(item.goods, 'number', value) this.$set(item.goods, 'number', value)
this.$emit('changeTotalPrice')
}, },
// 增加数量 // 增加数量
increaseNumber(item) { increaseNumber(item) {
...@@ -128,6 +129,7 @@ export default { ...@@ -128,6 +129,7 @@ export default {
const newValue = currentValue >= 999 ? 999 : currentValue + 1 const newValue = currentValue >= 999 ? 999 : currentValue + 1
this.$set(item.goods, 'number', newValue.toString()) this.$set(item.goods, 'number', newValue.toString())
} }
this.$emit('changeTotalPrice')
}, },
// 减少数量 // 减少数量
decreaseNumber(item) { decreaseNumber(item) {
...@@ -140,6 +142,12 @@ export default { ...@@ -140,6 +142,12 @@ export default {
// 确保减少后的值不小于1 // 确保减少后的值不小于1
const newValue = Math.max(1, currentValue - 1) const newValue = Math.max(1, currentValue - 1)
this.$set(item.goods, 'number', newValue.toString()) this.$set(item.goods, 'number', newValue.toString())
this.$emit('changeTotalPrice')
},
// 删除商品
deleteGoods(index) {
this.list.splice(index, 1)
this.$emit('changeTotalPrice')
} }
} }
} }
......
...@@ -189,7 +189,7 @@ const FORM_LIST = [ ...@@ -189,7 +189,7 @@ const FORM_LIST = [
value: 'couponInfo', value: 'couponInfo',
type: 'select', type: 'select',
key: 'name', key: 'name',
// addHtml: '' addHtml: 'otherGoods'
}, },
{ {
label: '收款方式', label: '收款方式',
...@@ -320,6 +320,22 @@ const popupTypeEnum = { ...@@ -320,6 +320,22 @@ const popupTypeEnum = {
6: { 6: {
key: 'frontGear', key: 'frontGear',
list: '', list: '',
},
7: {
key: 'frontWindow',
list: '',
},
8: {
key: 'rearGear',
list: '',
},
9: {
key: 'rearWindow',
list: '',
},
10: {
key: 'sunRoof',
list: '',
} }
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!