249 lines
5.4 KiB
Vue
249 lines
5.4 KiB
Vue
<script setup lang="ts">
|
|
import { reactive, watch } from 'vue'
|
|
import { ElMessage } from 'element-plus'
|
|
import { AppButton } from '@/components'
|
|
import type { Address } from '@/types/business/profile'
|
|
|
|
interface Props {
|
|
address?: Address
|
|
}
|
|
|
|
const props = defineProps<Props>()
|
|
|
|
const visible = defineModel<boolean>('visible', { default: false })
|
|
|
|
const emit = defineEmits<{
|
|
save: [payload: Omit<Address, 'id' | 'isDefault'>]
|
|
}>()
|
|
|
|
const form = reactive({
|
|
receiverName: '',
|
|
phone: '',
|
|
region: '',
|
|
detailAddress: '',
|
|
})
|
|
|
|
watch(visible, (open) => {
|
|
if (!open) return
|
|
form.receiverName = props.address?.receiverName ?? ''
|
|
form.phone = props.address?.phone ?? ''
|
|
form.region = props.address?.region ?? ''
|
|
form.detailAddress = props.address?.detailAddress ?? ''
|
|
})
|
|
|
|
function onSave(): void {
|
|
if (!form.receiverName.trim()) {
|
|
ElMessage.warning('请填写收货人姓名')
|
|
return
|
|
}
|
|
if (!form.phone.trim()) {
|
|
ElMessage.warning('请填写联系方式')
|
|
return
|
|
}
|
|
if (!form.region.trim()) {
|
|
ElMessage.warning('请填写所在地区')
|
|
return
|
|
}
|
|
if (!form.detailAddress.trim()) {
|
|
ElMessage.warning('请填写详细地址')
|
|
return
|
|
}
|
|
emit('save', {
|
|
receiverName: form.receiverName.trim(),
|
|
phone: form.phone.trim(),
|
|
region: form.region.trim(),
|
|
detailAddress: form.detailAddress.trim(),
|
|
})
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<Teleport to="body">
|
|
<div v-if="visible" class="address-dialog" @click.self="visible = false">
|
|
<div class="address-dialog__panel">
|
|
<h3 class="address-dialog__title">
|
|
{{ props.address ? '编辑地址' : '新增地址' }}
|
|
</h3>
|
|
|
|
<div class="address-dialog__field">
|
|
<label class="address-dialog__label">收货人姓名</label>
|
|
<input
|
|
v-model="form.receiverName"
|
|
class="address-dialog__input"
|
|
type="text"
|
|
placeholder="请输入收货人姓名"
|
|
maxlength="20"
|
|
>
|
|
</div>
|
|
|
|
<div class="address-dialog__field">
|
|
<label class="address-dialog__label">联系方式</label>
|
|
<input
|
|
v-model="form.phone"
|
|
class="address-dialog__input"
|
|
type="text"
|
|
placeholder="请输入手机号"
|
|
maxlength="11"
|
|
>
|
|
</div>
|
|
|
|
<div class="address-dialog__field">
|
|
<label class="address-dialog__label">所在地区</label>
|
|
<input
|
|
v-model="form.region"
|
|
class="address-dialog__input"
|
|
type="text"
|
|
placeholder="省/市/区,如:山东省日照市东港区"
|
|
maxlength="60"
|
|
>
|
|
</div>
|
|
|
|
<div class="address-dialog__field">
|
|
<label class="address-dialog__label">详细地址</label>
|
|
<textarea
|
|
v-model="form.detailAddress"
|
|
class="address-dialog__textarea"
|
|
placeholder="街道、门牌号、楼层等"
|
|
maxlength="120"
|
|
rows="3"
|
|
/>
|
|
</div>
|
|
|
|
<div class="address-dialog__footer">
|
|
<AppButton type="default" @click="visible = false">
|
|
取消
|
|
</AppButton>
|
|
<AppButton type="primary" @click="onSave">
|
|
保存
|
|
</AppButton>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</Teleport>
|
|
</template>
|
|
|
|
<style lang="less" scoped>
|
|
.address-dialog {
|
|
position: fixed;
|
|
inset: 0;
|
|
z-index: 1000;
|
|
.flex(row, center);
|
|
background: transparent;
|
|
overflow-y: auto;
|
|
|
|
&__panel {
|
|
width: 700px;
|
|
max-width: calc(100vw - 32px);
|
|
max-height: calc(100vh - 48px);
|
|
overflow-y: auto;
|
|
padding: @spacing-base;
|
|
border-radius: @radius-lg;
|
|
background: @white;
|
|
box-shadow: @shadow-lg;
|
|
.flex(column, flex-start);
|
|
gap: @spacing-base;
|
|
.scrollbar();
|
|
}
|
|
|
|
&__title {
|
|
position: relative;
|
|
padding-left: 12px;
|
|
font-size: 12px;
|
|
font-weight: 700;
|
|
color: @heading-color;
|
|
line-height: 20px;
|
|
|
|
&::before {
|
|
content: '';
|
|
position: absolute;
|
|
left: 0;
|
|
top: 3px;
|
|
width: 3px;
|
|
height: 14px;
|
|
border-radius: 2px;
|
|
background: @primary-strong;
|
|
}
|
|
}
|
|
|
|
&__field {
|
|
.flex(column, flex-start);
|
|
gap: @spacing-xs;
|
|
width: 100%;
|
|
}
|
|
|
|
&__label {
|
|
font-size: 11px;
|
|
font-weight: 500;
|
|
color: @heading-color;
|
|
}
|
|
|
|
&__input,
|
|
&__textarea {
|
|
width: 100%;
|
|
padding: 0 12px;
|
|
border: 1px solid @profile-input-border;
|
|
border-radius: @profile-radius;
|
|
background: @white;
|
|
font-size: 11px;
|
|
color: @text-color;
|
|
outline: none;
|
|
transition: border-color 0.2s;
|
|
box-sizing: border-box;
|
|
|
|
&:focus {
|
|
border-color: @primary-strong;
|
|
}
|
|
|
|
&::placeholder {
|
|
color: @heading-color;
|
|
}
|
|
}
|
|
|
|
&__input {
|
|
height: 32px;
|
|
}
|
|
|
|
&__textarea {
|
|
padding: 8px 12px;
|
|
line-height: 1.6;
|
|
resize: vertical;
|
|
}
|
|
|
|
&__footer {
|
|
.flex(row, flex-start);
|
|
gap: @spacing-sm;
|
|
width: 100%;
|
|
}
|
|
|
|
.app-button {
|
|
flex: 1;
|
|
height: 36px;
|
|
font-size: 12px;
|
|
font-weight: 500;
|
|
border-radius: @profile-radius;
|
|
}
|
|
|
|
.app-button--primary {
|
|
border-color: @primary-strong;
|
|
background: @primary-strong;
|
|
|
|
&:hover {
|
|
border-color: darken(@primary-strong, 6%);
|
|
background: darken(@primary-strong, 6%);
|
|
}
|
|
}
|
|
|
|
.app-button--default {
|
|
border: none;
|
|
background: @profile-quiet-btn;
|
|
color: @text-color;
|
|
|
|
&:hover {
|
|
border: none;
|
|
background: darken(@profile-quiet-btn, 4%);
|
|
color: @text-color;
|
|
}
|
|
}
|
|
}
|
|
</style>
|