|
|
@@ -181,6 +181,8 @@
|
|
|
|
|
|
</view>
|
|
|
<view class="line"></view>
|
|
|
+
|
|
|
+
|
|
|
<view class="select-right">
|
|
|
<view style="position: absolute;background-color: white;z-index: 99999999;" v-if="showDiscount">
|
|
|
<view style="display:flex;padding:20upx;justify-content: space-between;align-items:center;flex-wrap:wrap;">
|
|
|
@@ -205,6 +207,18 @@
|
|
|
<text style="color:green;">包装资材费</text>
|
|
|
<text><text :class="{selected:checkType == 2}">{{form.labourCost}}</text></text>
|
|
|
</view>
|
|
|
+ <view class="input-list" v-if="hasAvailableHb">
|
|
|
+ <text>红包</text>
|
|
|
+ <!-- 注意:不要用 <text> 包裹组件(小程序端 text 只能嵌套 text),否则 hb-select 不会渲染 -->
|
|
|
+ <view>
|
|
|
+ <hb-select
|
|
|
+ :hbData="hbData"
|
|
|
+ :totalPrice="preDiscountPrice"
|
|
|
+ v-model="selectedHbId"
|
|
|
+ @change="(hb) => { selectedHb = hb }"
|
|
|
+ ></hb-select>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
<view class="input-list">
|
|
|
<text>总金额</text>
|
|
|
<text @click="viewDiscount()">
|
|
|
@@ -243,10 +257,12 @@ import VKeyboard from '@/components/vKeyboard/VKeyboard.vue'
|
|
|
import TimePicker from '@/components/TimePicker';
|
|
|
import WeightInput from '@/components/delivery-input/weight-input.vue';
|
|
|
import RemarkInput from '@/components/delivery-input/remark-input.vue';
|
|
|
+import HbSelect from './hb-select'
|
|
|
import productMins from "@/mixins/product";
|
|
|
import { getAllStaff} from '@/api/shop-admin'
|
|
|
import { merchantDetail } from '@/api/merchant'
|
|
|
import { quickOrderAllDeliveryQuotes } from '@/api/delivery'
|
|
|
+import { getAvailableHb } from "@/api/hb"
|
|
|
import { mapGetters } from "vuex";
|
|
|
export default {
|
|
|
name:'selectCustomer',
|
|
|
@@ -311,6 +327,11 @@ export default {
|
|
|
value: ''
|
|
|
},
|
|
|
weightDebounceTimer: null,
|
|
|
+ selectedHbId: null,
|
|
|
+ selectedHb: null,
|
|
|
+ hbData: [],
|
|
|
+ // 用于确保异步回填 hbData 后,相关 computed 一定重新计算(兼容部分端的更新差异)
|
|
|
+ hbDataVersion: 0,
|
|
|
};
|
|
|
},
|
|
|
props:{
|
|
|
@@ -339,11 +360,16 @@ export default {
|
|
|
default:0
|
|
|
}
|
|
|
},
|
|
|
- components:{ VKeyboard, TimePicker, WeightInput, RemarkInput },
|
|
|
+ components:{ VKeyboard, TimePicker, WeightInput, RemarkInput, HbSelect },
|
|
|
mixins: [productMins],
|
|
|
computed:{
|
|
|
...mapGetters(["getLoginInfo"]),
|
|
|
+ // 总金额, 也就是合计金额
|
|
|
totalPrice(){
|
|
|
+ return this.systemPrice
|
|
|
+ },
|
|
|
+ // 计算不含红包的总价
|
|
|
+ preDiscountPrice(){
|
|
|
let price = 0
|
|
|
const sendCost = Number(this.form.sendCost)
|
|
|
|
|
|
@@ -355,38 +381,36 @@ export default {
|
|
|
if(this.form.reductionRule != 0){
|
|
|
if(this.form.reductionRule == 1){
|
|
|
if(this.isHcMapRule()){
|
|
|
- price = this.allPrice+Number(this.form.customSendCost)
|
|
|
+ price = this.allPrice + Number(this.form.customSendCost)
|
|
|
}else{
|
|
|
- price = this.allPrice+sendCost
|
|
|
+ price = this.allPrice + sendCost
|
|
|
}
|
|
|
}else if(this.form.reductionRule == 2){
|
|
|
if(this.isHsMapRule()){
|
|
|
- price = this.allPrice+Number(this.form.customSendCost)
|
|
|
+ price = this.allPrice + Number(this.form.customSendCost)
|
|
|
}else{
|
|
|
const distanceInMeters = Number(this.showDistance) || 0
|
|
|
const freeKmInMeters = (Number(this.hsFreeKm) || 0) * 1000
|
|
|
- const diff = distanceInMeters - freeKmInMeters
|
|
|
+ const diff = distanceInMeters - freeKmInMeters
|
|
|
if(diff > 0){
|
|
|
//花束满减规则 -- 每超出1公里,加收 hsAddFee 元(不足1公里按1公里计算)
|
|
|
const addFeePrice = Math.ceil(diff / 1000) * this.hsAddFee
|
|
|
this.form.sendCost = addFeePrice
|
|
|
- price = this.allPrice+addFeePrice
|
|
|
+ price = this.allPrice + addFeePrice
|
|
|
}else{
|
|
|
- price = this.allPrice+sendCost
|
|
|
+ price = this.allPrice + sendCost
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}else{
|
|
|
- price = this.allPrice+sendCost
|
|
|
+ price = this.allPrice + sendCost
|
|
|
}
|
|
|
price = parseFloat(price.toFixed(2))
|
|
|
}else{
|
|
|
- price = Number(this.allPrice)+Number(this.form.labourCost)
|
|
|
+ price = Number(this.allPrice) + Number(this.form.labourCost)
|
|
|
price = parseFloat(price.toFixed(2))
|
|
|
}
|
|
|
}
|
|
|
- this.form.modifyPrice = price
|
|
|
-
|
|
|
return price
|
|
|
},
|
|
|
diffPrice(){
|
|
|
@@ -405,9 +429,38 @@ export default {
|
|
|
isAddressInvalid() {
|
|
|
//this.custom 有也会出现空的情况
|
|
|
return this.$util.isEmpty(this.custom) || this.$util.isEmpty(this.custom.long) || this.$util.isEmpty(this.custom.lat) || this.$util.isEmpty(this.custom.address)
|
|
|
- }
|
|
|
+ },
|
|
|
+ hasAvailableHb(){
|
|
|
+ // 显式依赖一次版本号,确保 hbData 异步更新后 computed 一定失效重算
|
|
|
+ this.hbDataVersion // eslint-disable-next-line no-unused-expressions
|
|
|
+
|
|
|
+ if (!this.hbData || this.hbData.length === 0) return false
|
|
|
+ const price = Number(this.preDiscountPrice) || 0
|
|
|
+ return this.hbData.some(item => {
|
|
|
+ const min = Number(item.minConsume) || 0
|
|
|
+ //console.log('price, min ----- ', price, min)
|
|
|
+ return price >= min
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 合计金额(含红包扣减)
|
|
|
+ systemPrice(){
|
|
|
+ let finalPrice = Number(this.preDiscountPrice) || 0
|
|
|
+ // 减去红包金额
|
|
|
+ if(this.hasAvailableHb && this.selectedHb){
|
|
|
+ finalPrice = finalPrice - Number(this.selectedHb.amount || 0)
|
|
|
+ }
|
|
|
+ if(finalPrice < 0) finalPrice = 0
|
|
|
+ return parseFloat(Number(finalPrice).toFixed(2))
|
|
|
+ },
|
|
|
},
|
|
|
watch:{
|
|
|
+ // systemPrice 变化时,默认回填应付金额
|
|
|
+ systemPrice: {
|
|
|
+ handler(val){
|
|
|
+ this.form.modifyPrice = val
|
|
|
+ },
|
|
|
+ immediate: true
|
|
|
+ },
|
|
|
settleOpenStatus:{
|
|
|
handler(val){
|
|
|
if(Number(val) == 1){
|
|
|
@@ -421,6 +474,11 @@ export default {
|
|
|
this.form.dealPrice = 0
|
|
|
this.form.sendType = 1
|
|
|
this.form.getGoods = 1
|
|
|
+ // 重置红包选择,避免上次结算残留
|
|
|
+ this.selectedHbId = null
|
|
|
+ this.selectedHb = null
|
|
|
+ this.form.hbId = null
|
|
|
+ this.form.hbAmount = null
|
|
|
|
|
|
//如果余额够使用余额支付
|
|
|
if(Number(this.balance)>Number(this.form.modifyPrice)){
|
|
|
@@ -441,6 +499,9 @@ export default {
|
|
|
this.hsAddFee = res.data.hsAddFee
|
|
|
}
|
|
|
})
|
|
|
+
|
|
|
+ //获取可用红包数据
|
|
|
+ this.getHbData()
|
|
|
}
|
|
|
},
|
|
|
immediate:true
|
|
|
@@ -546,7 +607,7 @@ export default {
|
|
|
setDiscount(num){
|
|
|
this.$util.hitVoice()
|
|
|
this.discountValue = Number(num)
|
|
|
- let price = Number(this.totalPrice)*Number(num)
|
|
|
+ let price = Number(this.systemPrice)*Number(num)
|
|
|
price = parseFloat(price.toFixed(2))
|
|
|
this.form.modifyPrice = price
|
|
|
this.showDiscount = false
|
|
|
@@ -863,6 +924,17 @@ export default {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 红包信息
|
|
|
+ if(this.hasAvailableHb && this.selectedHbId && this.selectedHb){
|
|
|
+ this.form.hbId = this.selectedHbId
|
|
|
+ this.form.hbAmount = this.selectedHb.amount
|
|
|
+ }else{
|
|
|
+ // this.form.hbId = null //后端会产生 Column 'hbId' cannot be null
|
|
|
+ // this.form.hbAmount = null
|
|
|
+ this.form.hbId = 0
|
|
|
+ this.form.hbAmount = 0
|
|
|
+ }
|
|
|
+
|
|
|
if(this.form.callErrand == 1){
|
|
|
if(this.form.sendType == 2 && this.form.hasPay == 0){
|
|
|
this.$msg('扫码付款,暂不支持马上发跑腿')
|
|
|
@@ -878,7 +950,20 @@ export default {
|
|
|
},
|
|
|
cancel(){
|
|
|
this.$emit('cancelSettle')
|
|
|
- }
|
|
|
+ },
|
|
|
+ getHbData(){
|
|
|
+ getAvailableHb({
|
|
|
+ customId: this.customId,
|
|
|
+ shopId: this.getLoginInfo.shopId
|
|
|
+ }).then(res=>{
|
|
|
+ if(res.code == 1){
|
|
|
+ const list = res && res.data ? res.data : []
|
|
|
+ // 用数组替换 + 版本号自增,确保视图/计算属性稳定刷新
|
|
|
+ this.hbData = Array.isArray(list) ? list : []
|
|
|
+ this.hbDataVersion += 1
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
}
|
|
|
}
|
|
|
</script>
|