feat: 商品详情的调整

This commit is contained in:
2025-09-06 16:24:44 +08:00
parent 7973743644
commit f6821ade2d
6 changed files with 136 additions and 32 deletions

View File

@@ -61,8 +61,8 @@ const ERROR_MESSAGES = {
* @typedef {Object} FormCardProps * @typedef {Object} FormCardProps
* @property {string} title - 表单标题 * @property {string} title - 表单标题
* @property {Object} form - 表单数据对象 * @property {Object} form - 表单数据对象
* @property {string} form.name - 姓名 * @property {string} form.visitorName - 姓名
* @property {string} form.phone - 手机号 * @property {string} form.contactPhone - 手机号
* @property {boolean} showDeleteIcon - 是否显示删除图标 * @property {boolean} showDeleteIcon - 是否显示删除图标
*/ */
const props = defineProps({ const props = defineProps({
@@ -73,12 +73,16 @@ const props = defineProps({
form: { form: {
type: Object, type: Object,
default: () => ({ default: () => ({
name: "", visitorName: "",
phone: "", contactPhone: "",
}), }),
validator: (value) => { validator: (value) => {
return value && typeof value === 'object' && return (
'name' in value && 'phone' in value; value &&
typeof value === "object" &&
"visitorName" in value &&
"contactPhone" in value
);
}, },
}, },
showDeleteIcon: { showDeleteIcon: {
@@ -90,11 +94,15 @@ const props = defineProps({
/** /**
* FormCard 组件事件 * FormCard 组件事件
* @typedef {Object} FormCardEmits * @typedef {Object} FormCardEmits
* @property {Function} update:name - 更新姓名事件 * @property {Function} update:visitorName - 更新姓名事件
* @property {Function} update:phone - 更新手机号事件 * @property {Function} update:contactPhone - 更新手机号事件
* @property {Function} delete - 删除表单事件 * @property {Function} delete - 删除表单事件
*/ */
const emit = defineEmits(["update:name", "update:phone", "delete"]); const emit = defineEmits([
"update:visitorName",
"update:contactPhone",
"delete",
]);
// 响应式状态 // 响应式状态
const nameError = ref(""); const nameError = ref("");
@@ -102,16 +110,16 @@ const phoneError = ref("");
// 计算属性 - 双向绑定 // 计算属性 - 双向绑定
const nameValue = computed({ const nameValue = computed({
get: () => props.form?.name || "", get: () => props.form?.visitorName || "",
set: (value) => emit("update:name", value?.trim() || ""), set: (value) => emit("update:visitorName", value?.trim() || ""),
}); });
const phoneValue = computed({ const phoneValue = computed({
get: () => props.form?.phone || "", get: () => props.form?.contactPhone || "",
set: (value) => { set: (value) => {
// 只允许数字输入 // 只允许数字输入
const numericValue = value.replace(/\D/g, ""); const numericValue = value.replace(/\D/g, "");
emit("update:phone", numericValue); emit("update:contactPhone", numericValue);
}, },
}); });
@@ -145,11 +153,11 @@ const getPhoneError = (phone) => {
// 验证方法 // 验证方法
const validateName = () => { const validateName = () => {
nameError.value = getNameError(props.form?.name); nameError.value = getNameError(props.form?.visitorName);
}; };
const validatePhone = () => { const validatePhone = () => {
phoneError.value = getPhoneError(props.form?.phone); phoneError.value = getPhoneError(props.form?.contactPhone);
}; };
// 事件处理 // 事件处理

View File

@@ -0,0 +1,45 @@
<template>
<view class="store-address" @click="openMap">
<text class="location-label">位于 [{{ orderData.commodityAddress }}]</text>
<text class="address-text">{{ orderData.commodityAddress }}</text>
</view>
</template>
<script setup>
import { defineProps } from "vue";
const props = defineProps({
orderData: {
type: Object,
required: true,
default: () => ({}),
},
});
// 打开地图
const openMap = () => {
const address = props.orderData.commodityAddress;
const latitude = Number(props.orderData.commodityLatitude);
const longitude = Number(props.orderData.commodityLongitude);
uni.getLocation({
type: "gcj02", //返回可以用于uni.openLocation的经纬度
success: (res) => {
console.log("当前经纬度", latitude, longitude);
uni.openLocation({
latitude: latitude,
longitude: longitude,
address: address,
success: () => {
console.log("success");
},
});
},
});
};
</script>
<style scoped lang="scss">
@import "./styles/index.scss";
</style>

View File

@@ -0,0 +1,49 @@
.store-address {
display: flex;
align-items: start;
flex-direction: column;
padding: 16px 12px;
background-color: #f0f0f0;
background-image: url(""); // 预留背景图片位置,用户手动导入
background-size: cover;
background-position: center;
border-radius: 12px;
font-size: 14px;
color: #333;
position: relative;
overflow: hidden;
// 添加半透明遮罩层确保文字可读性
&::before {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(255, 255, 255, 0.8);
z-index: 1;
}
// 确保内容在遮罩层之上
.location-label,
.address-text {
position: relative;
z-index: 2;
}
.location-label {
color: #333;
font-size: 14px;
margin-right: 4px;
font-weight: 500;
}
.address-text {
margin-top: 4px;
flex: 1;
color: #666;
font-size: 12px;
font-weight: 400;
}
}

View File

@@ -83,8 +83,12 @@
:form="item" :form="item"
:showDeleteIcon="userFormList.length > 1" :showDeleteIcon="userFormList.length > 1"
:key="index" :key="index"
@update:name="(value) => updateUserForm(index, 'name', value)" @update:visitorName="
@update:phone="(value) => updateUserForm(index, 'phone', value)" (value) => updateUserForm(index, 'visitorName', value)
"
@update:contactPhone="
(value) => updateUserForm(index, 'contactPhone', value)
"
@delete="() => deleteUserForm(index)" @delete="() => deleteUserForm(index)"
/> />
</scroll-view> </scroll-view>
@@ -126,10 +130,10 @@ const showToast = (title, icon = "none", duration = 2000) => {
const isValidUserForm = (user) => { const isValidUserForm = (user) => {
return ( return (
user && user &&
typeof user.name === "string" && typeof user.visitorName === "string" &&
user.name.trim() !== "" && user.visitorName.trim() !== "" &&
typeof user.phone === "string" && typeof user.contactPhone === "string" &&
user.phone.trim() !== "" user.contactPhone.trim() !== ""
); );
}; };
@@ -165,7 +169,7 @@ const emits = defineEmits(["confirm", "close"]);
// 工具函数 // 工具函数
const createEmptyUserForm = () => { const createEmptyUserForm = () => {
return { name: "", phone: "" }; return { visitorName: "", contactPhone: "" };
}; };
// 响应式数据 // 响应式数据
@@ -243,7 +247,7 @@ const updateUserForm = (index, field, value) => {
return; return;
} }
if (!["name", "phone"].includes(field)) { if (!["visitorName", "contactPhone"].includes(field)) {
return; return;
} }
@@ -308,8 +312,8 @@ const confirmOrder = () => {
quantity: quantity.value, quantity: quantity.value,
totalPrice: parseFloat(totalPrice.value), totalPrice: parseFloat(totalPrice.value),
userFormList: userFormList.value.map((user) => ({ userFormList: userFormList.value.map((user) => ({
name: user.name.trim(), visitorName: user.visitorName.trim(),
phone: user.phone.trim(), contactPhone: user.contactPhone.trim(),
})), })),
commodityType: props.goodsData?.commodityTypeCode, commodityType: props.goodsData?.commodityTypeCode,
timestamp: Date.now(), timestamp: Date.now(),

View File

@@ -21,7 +21,7 @@
<!-- 地址区域 --> <!-- 地址区域 -->
<view class="address-section"> <view class="address-section">
<LocationInfo :orderData="goodsData" /> <LocationCard :orderData="goodsData" />
</view> </view>
<!-- 设施信息区域 --> <!-- 设施信息区域 -->
@@ -41,7 +41,7 @@
<script setup> <script setup>
import { computed, defineProps, defineEmits } from "vue"; import { computed, defineProps, defineEmits } from "vue";
import LocationInfo from "@/components/LocationInfo/index.vue"; import LocationCard from "@/components/LocationCard/index.vue";
// 事件定义 // 事件定义
const emits = defineEmits(["showCalendar"]); const emits = defineEmits(["showCalendar"]);

View File

@@ -38,9 +38,7 @@
// 地址区域 // 地址区域
.address-section { .address-section {
padding: 12px 0; padding: 6px 0;
border-top: 1px solid #f0f0f0;
border-bottom: 1px solid #f0f0f0;
.address-item { .address-item {
display: flex; display: flex;