396 lines
10 KiB
Vue
396 lines
10 KiB
Vue
<template>
|
||
<view class="page-content">
|
||
<nut-cell-group>
|
||
<nut-cell v-if="!form.address_info?.address_id" title="添加地址" is-link @click="chooseAddress"></nut-cell>
|
||
<nut-cell v-else :title="form.address_info.user_name + ' ' + form.address_info.tel_number" is-link
|
||
:sub-title="
|
||
form.address_info.province_name +
|
||
form.address_info.city_name +
|
||
form.address_info.county_name +
|
||
form.address_info.street_name +
|
||
form.address_info.detail_info_new
|
||
" @click="chooseAddress"></nut-cell>
|
||
</nut-cell-group>
|
||
|
||
<nut-cell-group>
|
||
<nut-cell center>
|
||
<template #title>
|
||
<view class="goods-info-row">
|
||
<!-- 左侧文字区域 -->
|
||
<view class="left-text">
|
||
<view class="goods-name">
|
||
<nut-tag custom-color="#1a1a1a">{{ goods?.goods_house?.degree?.degree_name }}</nut-tag>
|
||
<text style="margin-left: 10rpx">{{ goods?.goods_house?.goods_name }}</text>
|
||
</view>
|
||
<text class="goods-no">串号:{{ goods?.goods_house?.goods_no }}</text>
|
||
</view>
|
||
<!-- 右侧价格区域 -->
|
||
</view>
|
||
</template>
|
||
<template #link>
|
||
<nut-price :price="getPrice(goods?.goods_house)" size="small" :need-symbol="true" />
|
||
</template>
|
||
</nut-cell>
|
||
</nut-cell-group>
|
||
|
||
<nut-cell-group>
|
||
<nut-cell>
|
||
<view class="total-price-inner">
|
||
<text>件数</text>
|
||
<text>{{ order_total_num }}件</text>
|
||
</view>
|
||
</nut-cell>
|
||
<nut-cell>
|
||
<view class="total-price-inner">
|
||
<text>商品总额</text>
|
||
<nut-price :price="getPrice(goods?.goods_house)" :need-symbol="true" />
|
||
</view>
|
||
</nut-cell>
|
||
</nut-cell-group>
|
||
<view class="bottom-submit-inner">
|
||
<view class="bottom-submit-inner-info">
|
||
<text>合计:</text>
|
||
<nut-price size="large" :price="getPrice(goods?.goods_house)" :need-symbol="true" />
|
||
</view>
|
||
<view class="bottom-submit-inner-btn">
|
||
<nut-button type="primary" @click="onSubmitClick">确认下单</nut-button>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</template>
|
||
|
||
<script setup>
|
||
import {
|
||
onLoad,
|
||
onShow,
|
||
onHide
|
||
} from '@dcloudio/uni-app';
|
||
import {
|
||
reactive,
|
||
ref
|
||
} from 'vue';
|
||
import {
|
||
fetchOrderbuyNow,
|
||
houseFetchGoodsPreview
|
||
} from '@/api/house_order';
|
||
|
||
import {
|
||
fetchGetConfig,
|
||
fetchGetPriceRules,
|
||
} from '@/api/config';
|
||
|
||
import {
|
||
navigateTo
|
||
} from '@/utils/helper';
|
||
|
||
|
||
// 审核模式
|
||
const audit = ref(true);
|
||
// 是否开启整仓调价
|
||
const isWarehouse = ref(false)
|
||
|
||
|
||
// 单个商品规则列表
|
||
const singleRule = ref([])
|
||
// 价格区间规则列表
|
||
const rangeRule = ref([])
|
||
// 整仓规则
|
||
const warehouseRule = reactive({
|
||
val: 0,
|
||
val_type: 1,
|
||
})
|
||
|
||
|
||
// 获取全部调价规则
|
||
const GetPriceRules = () => {
|
||
fetchGetPriceRules().then(res => {
|
||
console.log('res', res);
|
||
// 区间调价
|
||
rangeRule.value = res?.range ?? [];
|
||
// 单机调价
|
||
singleRule.value = res?.single ?? [];
|
||
// 整仓调价
|
||
Object.assign(warehouseRule, res?.warehouse?.[0] ?? {
|
||
val: 0,
|
||
val_type: 1,
|
||
})
|
||
})
|
||
}
|
||
|
||
|
||
// 获取价格
|
||
const getPrice = (goods) => {
|
||
// 判断是否开启整仓调价
|
||
if (isWarehouse.value) {
|
||
console.log("开启整仓调价");
|
||
// 查找单机器加价规则
|
||
const list = singleRule.value || singleRule; // 兼容 ref 和 reactive
|
||
// 根据 product_id == goods_id 找对应规则
|
||
const rule = list.find(item => item.product_id === goods?.goods_id);
|
||
if (rule) {
|
||
// 存在单机加价规则
|
||
const basePrice = Number(goods?.goods_price);
|
||
const val = Number(rule.val);
|
||
let finalPrice = basePrice;
|
||
// val_type 处理
|
||
if (rule.val_type == 1) {
|
||
finalPrice = basePrice + val; // 固定加价
|
||
} else if (rule.val_type == 2) {
|
||
finalPrice = basePrice + (basePrice * val / 100); // 按百分比加
|
||
}
|
||
return finalPrice.toFixed(2); // 保留两位小数
|
||
} else {
|
||
// 不存在则使用整仓加价
|
||
const basePrice = Number(goods?.goods_price);
|
||
const val = Number(warehouseRule.val);
|
||
let finalPrice = basePrice;
|
||
// val_type 处理
|
||
if (warehouseRule.val_type == 1) {
|
||
finalPrice = basePrice + val; // 固定加价
|
||
} else if (warehouseRule.val_type == 2) {
|
||
finalPrice = basePrice + (basePrice * val / 100); // 按百分比加
|
||
}
|
||
return finalPrice.toFixed(2); // 保留两位小数
|
||
}
|
||
} else {
|
||
console.log("未开启整仓调价");
|
||
// 查找单机器加价规则
|
||
const singleRuleList = singleRule.value || singleRule; // 兼容 ref 和 reactive
|
||
// 根据 product_id == goods_id 找对应规则
|
||
const oneRule = singleRuleList.find(item => item.product_id === goods?.goods_id);
|
||
if (oneRule) {
|
||
// 存在单机加价规则
|
||
const basePrice = Number(goods?.goods_price);
|
||
const val = Number(oneRule.val);
|
||
let finalPrice = basePrice;
|
||
// val_type 处理
|
||
if (oneRule.val_type == 1) {
|
||
finalPrice = basePrice + val; // 固定加价
|
||
} else if (oneRule.val_type == 2) {
|
||
finalPrice = basePrice + (basePrice * val / 100); // 按百分比加
|
||
}
|
||
return finalPrice.toFixed(2); // 保留两位小数
|
||
} else {
|
||
// 不存在则使用区间加价
|
||
const basePrice = Number(goods?.goods_price)
|
||
// // 查找区间加价规则
|
||
const rangeRulelist = rangeRule.value || rangeRule; // 兼容 ref 和 reactive
|
||
const quRule = rangeRulelist.find(item => {
|
||
const min = Number(item.min_price)
|
||
const max = Number(item.max_price)
|
||
return basePrice >= min && basePrice < max
|
||
}) || null
|
||
if (quRule) {
|
||
// 存在区间加价
|
||
const val = Number(quRule.val);
|
||
let finalPrice = basePrice;
|
||
// val_type 处理
|
||
if (quRule.val_type == 1) {
|
||
finalPrice = basePrice + val; // 固定加价
|
||
} else if (quRule.val_type == 2) {
|
||
finalPrice = basePrice + (basePrice * val / 100); // 按百分比加
|
||
}
|
||
return finalPrice.toFixed(2); // 保留两位小数
|
||
} else {
|
||
// 不存在区间加价
|
||
return basePrice
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
const getConfig = () => {
|
||
fetchGetConfig().then(res => {
|
||
console.log('getConfig=====>', res)
|
||
audit.value = res.appConfig.is_audit == 1
|
||
isWarehouse.value = res.appConfig.is_warehouse == 1
|
||
})
|
||
}
|
||
|
||
|
||
|
||
const chooseAddress = () => {
|
||
uni.chooseAddress({
|
||
success(res) {
|
||
// console.log(res.userName)
|
||
// console.log(res.telNumber)
|
||
// console.log(res.provinceName + res.cityName + res.countyName + res.streetName + res.detailInfoNew)
|
||
// console.log(res.userName)
|
||
// console.log(res.postalCode)
|
||
// console.log(res.provinceName)
|
||
// console.log(res.cityName)
|
||
// console.log(res.countyName)
|
||
// console.log(res.detailInfo)
|
||
// console.log(res.nationalCode)
|
||
// console.log(res.telNumber)
|
||
console.log(res);
|
||
Object.assign(form, {
|
||
address_info: {
|
||
address_id: res.addressID || 1,
|
||
user_name: res.userName,
|
||
tel_number: res.telNumber,
|
||
city_name: res.cityName || '',
|
||
county_name: res.countyName || '',
|
||
detail_info: res.detailInfo || '',
|
||
detail_info_new: res.detailInfoNew || '',
|
||
national_code: res.nationalCode || '',
|
||
national_code_full: res.nationalCodeFull || '',
|
||
postal_code: res.postalCode || '',
|
||
province_name: res.provinceName || '',
|
||
street_name: res.streetName || '',
|
||
},
|
||
});
|
||
},
|
||
});
|
||
};
|
||
|
||
|
||
|
||
|
||
const ids = ref([]);
|
||
// const list = reactive([]);
|
||
const goods = reactive({})
|
||
|
||
|
||
const order_total_price = ref(0);
|
||
const order_total_num = ref(0);
|
||
|
||
|
||
const form = reactive({
|
||
goods_id: 0,
|
||
address_info: {},
|
||
});
|
||
|
||
|
||
const fromStr = ref('');
|
||
|
||
|
||
|
||
onLoad(options => {
|
||
|
||
console.log('init');
|
||
// 获取配置
|
||
getConfig()
|
||
GetPriceRules()
|
||
|
||
|
||
console.log('🚀 ~ from:', options.from);
|
||
fromStr.value = options.from;
|
||
console.log('🚀 ~ ids:', options.ids);
|
||
form.goods_id = options.ids;
|
||
});
|
||
|
||
|
||
|
||
|
||
onShow(() => {
|
||
console.log('🚀 ~ onShowfrom:', fromStr.value);
|
||
if (fromStr.value === 'list' || fromStr.value === 'item') {
|
||
houseFetchGoodsPreview({
|
||
goods_id: form.goods_id,
|
||
}).then(res => {
|
||
console.log(res);
|
||
// Object.assign(list, res.goods_list);
|
||
Object.assign(goods, res.goods)
|
||
// Object.assign(form.address_info, res.address_info);
|
||
order_total_price.value = res.order_total_price;
|
||
order_total_num.value = res.order_total_num;
|
||
});
|
||
}
|
||
});
|
||
|
||
onHide(() => {
|
||
fromStr.value = '';
|
||
});
|
||
|
||
|
||
|
||
// 提交订单
|
||
const onSubmitClick = () => {
|
||
if (!form.address_info?.address_id) {
|
||
uni.showToast({
|
||
title: '请选择收货地址',
|
||
icon: 'none',
|
||
});
|
||
return;
|
||
}
|
||
fetchOrderbuyNow(form).then(res => {
|
||
console.log(res);
|
||
uni.redirectTo({
|
||
url: '/pages/order/detail?id=' + res.order_id,
|
||
success: res => {},
|
||
fail: () => {},
|
||
complete: () => {},
|
||
});
|
||
// navigateTo('/pages/order/detail/index?id=' + res.order_id)
|
||
});
|
||
};
|
||
</script>
|
||
<style scoped lang="scss">
|
||
.page-content {
|
||
// min-height: 100vh;
|
||
min-height: calc(100vh - 60px); //100vh;
|
||
background-color: #f2f3f5;
|
||
padding: 20rpx;
|
||
padding-bottom: 140rpx;
|
||
}
|
||
|
||
/* 信息行布局 */
|
||
.goods-info-row {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
padding-bottom: 10rpx;
|
||
// border-bottom: 2rpx solid #f2f3f5;
|
||
|
||
/* 左侧文字样式 */
|
||
.left-text {
|
||
flex: 1;
|
||
}
|
||
|
||
.goods-name {
|
||
font-size: 30rpx;
|
||
color: #000000;
|
||
display: block;
|
||
margin-bottom: 8rpx;
|
||
}
|
||
|
||
.goods-no {
|
||
font-size: 26rpx;
|
||
color: #000000;
|
||
display: block;
|
||
}
|
||
|
||
/* 右侧价格样式 */
|
||
.price {
|
||
margin-left: 20rpx;
|
||
align-self: center;
|
||
/* 垂直居中在两行文字之间 */
|
||
}
|
||
}
|
||
|
||
.bottom-submit-inner {
|
||
position: fixed;
|
||
bottom: 0;
|
||
left: 0;
|
||
height: 120rpx;
|
||
background: #fff;
|
||
width: calc(100% - 40rpx);
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
margin: 0 auto;
|
||
padding: 15rpx 20rpx;
|
||
}
|
||
|
||
.total-price-inner {
|
||
width: 100%;
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
|
||
view:nth-child(2) {
|
||
color: #fa2c19;
|
||
}
|
||
}
|
||
</style> |