feat 搭建架构骨架
This commit is contained in:
194
src/views/profile/cpns/AddressDialog.vue
Normal file
194
src/views/profile/cpns/AddressDialog.vue
Normal file
@@ -0,0 +1,194 @@
|
||||
<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: rgba(0, 0, 0, 0.45);
|
||||
|
||||
&__panel {
|
||||
width: 480px;
|
||||
max-width: calc(100vw - 32px);
|
||||
padding: @spacing-lg;
|
||||
border-radius: @radius-lg;
|
||||
background: @white;
|
||||
box-shadow: @shadow-lg;
|
||||
.flex(column, flex-start);
|
||||
gap: @spacing-base;
|
||||
}
|
||||
|
||||
&__title {
|
||||
font-size: @font-size-lg;
|
||||
font-weight: 600;
|
||||
color: @heading-color;
|
||||
}
|
||||
|
||||
&__field {
|
||||
.flex(column, flex-start);
|
||||
gap: @spacing-xs;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
&__label {
|
||||
font-size: @font-size-base;
|
||||
color: @heading-color;
|
||||
}
|
||||
|
||||
&__input,
|
||||
&__textarea {
|
||||
width: 100%;
|
||||
padding: 0 @spacing-base;
|
||||
border: 1px solid @border-color;
|
||||
border-radius: @radius-base;
|
||||
background: @bg-color-light;
|
||||
font-size: @font-size-base;
|
||||
outline: none;
|
||||
transition: border-color 0.2s;
|
||||
box-sizing: border-box;
|
||||
|
||||
&:focus {
|
||||
border-color: @primary-color;
|
||||
}
|
||||
}
|
||||
|
||||
&__input {
|
||||
height: 40px;
|
||||
}
|
||||
|
||||
&__textarea {
|
||||
padding: @spacing-sm @spacing-base;
|
||||
line-height: 1.6;
|
||||
resize: vertical;
|
||||
}
|
||||
|
||||
&__footer {
|
||||
.flex(row, flex-end);
|
||||
gap: @spacing-sm;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user