| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500 |
- <template>
- <view class="container">
- <!-- 物品信息 -->
- <view class="form-card">
- <view class="form-item">
- <view class="item-label">
- <input class="input-field" placeholder="姓名" placeholder-class="placeholder" maxlength="10"
- v-model="formData.contactName" />
- </view>
- <view class="item-control">
- <input class="input-field" placeholder="电话" placeholder-class="placeholder" maxlength="11"
- v-model="formData.contactPhone" />
- </view>
- </view>
- <picker mode="region" @change="changeAddress">
- <view class="form-item form-items">
- <text
- class="time-value placeholder">{{ formData.provinceName ? formData.provinceName + formData.cityName + formData.countyName : '省市区' }}</text>
- <text class="time-value value">{{ selectedTime }}</text>
- <u-icon class="arrow" name='arrow-right' size="18"></u-icon>
- </view>
- </picker>
- <view class="form-item">
- <view class="item-control">
- <input class="input-field" placeholder="详细地址" placeholder-class="placeholder"
- v-model="formData.detailedAddress" />
- </view>
- </view>
- <view class="form-item">
- <!-- 设置默认和清空 -->
- <view class="form-actions">
- <view class="action-left">
- <switch :checked="formData.defaultFlag == 1" color="#007AFF" @change="onDefaultChange" />
- <text class="action-text">设为默认寄件地址</text>
- </view>
- <view class="action-right" @click="clearForm">
- <text class="clear-text">清空</text>
- </view>
- </view>
- </view>
- </view>
- <view class="section-title" v-if="false">最近使用地址</view>
- <!-- 最近使用地址 -->
- <view class="recent-address" v-if="false">
- <!-- 地址项1 -->
- <view class="address-item" @tap="selectAddress(0)">
- <AddressInfo v-if="formData.id" :address="addressSend" />
- <view class="address-info">
- <view class="address-name">袁添昊 13344642161</view>
- <view class="address-detail">湖北省荆州市新石南路747号</view>
- </view>
- <!-- <view class="address-select">
-
- </view> -->
- </view>
- <!-- 地址项2 -->
- <view class="address-item" @tap="selectAddress(1)">
- <view class="address-info">
- <view class="address-name">袁添昊 13344642161</view>
- <view class="address-detail">湖北省荆州市新石南路747号</view>
- </view>
- <!-- <view class="address-select">
-
- </view> -->
- </view>
- </view>
- <!-- 下单按钮 -->
- <view class="submit-btn" @click="onConfirm">
- 确定
- </view>
- <!-- 安全区域占位 -->
- <view class="safe-area"></view>
- </view>
- </template>
- <script setup>
- import {
- ref,
- reactive
- } from 'vue'
- import {
- onLoad
- } from '@dcloudio/uni-app'
- import AddressInfo from '@/components/AddressInfo.vue'
- import {
- addBook,
- updateBook,
- getBook
- } from '@/api/address.js'
- const addType = ref('1') //1 表示从创建订单过来 2 表示编辑 3表示创建
- // 表单数据
- const formData = reactive({
- contactName: '', //姓名
- contactPhone: '', //电话
- provinceName: '', //省
- cityName: '', //市
- countyName: '', //区
- addressId: null, //地址ID
- detailedAddress: '', //详细地址
- defaultFlag: 0 //是否默认 0非默认1默认
- })
- // 最近地址列表
- const recentAddresses = ref([{
- name: '袁添昊',
- phone: '13344642161',
- address: '湖北省荆州市新石南路747号'
- },
- {
- name: '袁添昊',
- phone: '13344642161',
- address: '湖北省荆州市新石南路747号'
- }
- ])
- onLoad((option) => {
- if (option.id) {
- formData.addressId = option.id;
- getAddress()
- uni.setNavigationBarTitle({
- title:'编辑地址'
- })
- }
-
- })
- const getAddress = async () => {
- let res = await getBook(formData.addressId);
- console.log(res.data, formData);
- let {
- addressId,
- contactName,
- contactPhone,
- countyName,
- defaultFlag,
- detailedAddress,
- provinceName,
- cityName
- } = res.data;
- // formData = {addressId,contactName,contactPhone,countyName,defaultFlag,detailedAddress,provinceName}
- Object.assign(formData, {
- addressId,
- contactName,
- contactPhone,
- cityName,
- countyName,
- defaultFlag,
- detailedAddress,
- provinceName
- });
- }
- // 选择地址
- const changeAddress = (e) => {
- formData.provinceName = e.detail.value[0]
- formData.cityName = e.detail.value[1]
- formData.countyName = e.detail.value[2]
- }
- // 省市区选择
- const onRegionChange = (e) => {
- formData.region = e.detail.value
- }
- // 默认地址切换
- const onDefaultChange = (e) => {
- formData.defaultFlag = e.detail.value ? 1 : 0
- }
- // 清空表单
- const clearForm = () => {
- formData.contactName = ''
- formData.contactPhone = ''
- formData.provinceName = ''
- formData.cityName = ''
- formData.countyName = ''
- formData.detailedAddress = ''
- formData.defaultFlag = 0
- }
- // 确定提交
- const onConfirm = async () => {
- // 这里可以添加表单验证
- if (!formData.contactName || !formData.contactPhone || !formData.detailedAddress) {
- uni.showToast({
- title: '请填写完整信息',
- icon: 'none'
- })
- return
- }
-
- if (!formData.provinceName) return uni.showToast({
- title: '请选择省市区',
- icon: 'none'
- })
- // 提交逻辑
- let api = formData.addressId ? updateBook(formData) : addBook(formData)
- let res = await api;
- console.log('提交数据:', formData)
- uni.showToast({
- title: '提交成功',
- icon: 'success'
- })
- setTimeout(() => {
- // 返回上一页或执行其他操作
- uni.navigateBack()
- }, 800)
- }
- </script>
- <style scoped lang="less">
- .container {
- background-color: #F5F7FA;
- min-height: 100vh;
- padding: 20rpx 20rpx 30rpx 20rpx;
- }
- .form-card {
- background-color: #fff;
- border-radius: 32rpx;
- padding: 0rpx 20rpx;
- }
- .form-title {
- font-size: 32rpx;
- font-weight: 600;
- color: #333;
- margin-bottom: 32rpx;
- }
- .form-item {
- display: flex;
- justify-content: space-between;
- align-items: center;
- height: 100rpx;
- border-bottom: 1rpx solid #F1F3F8;
- &:last-child {
- border-bottom: none;
- margin-bottom: 0;
- }
- .item-label {
- font-size: 28rpx;
- color: #666;
- font-weight: 400;
- &.required::before {
- content: '*';
- color: #ff4444;
- margin-right: 8rpx;
- }
- }
- .item-control {
- display: flex;
- align-items: center;
- &.btn {
- background: #fff;
- border: 1rpx solid #dcdfe6;
- border-radius: 5rpx;
- height: 59rpx;
- width: 266rpx;
- box-sizing: border-box;
- }
- }
- .input-field {
- width: 100%;
- height: 100rpx;
- line-height: 100rpx;
- padding: 0 24rpx;
- font-size: 28rpx;
- color: #333;
- text-align: left;
- &::placeholder {
- color: #999;
- }
- }
- .time-value {
- display: flex;
- align-items: center;
- font-size: 28rpx;
- color: #333;
- line-height: 88rpx;
- height: 88rpx;
- padding: 0 24rpx;
- &.placeholder {
- color: #999;
- }
- .value {
- margin-right: 16rpx;
- }
- .arrow {
- margin-left: 32rpx;
- color: #999;
- font-size: 28rpx;
- font-weight: bold;
- }
- }
- }
- .form-items {
- &:last-child {
- border-bottom: 1rpx solid #F1F3F8;
- }
- }
- /* 寄件标识 */
- .send-tag {
- padding: 40rpx 30rpx 20rpx;
- background-color: #fff;
- }
- .send-circle {
- width: 60rpx;
- height: 60rpx;
- border-radius: 50%;
- background-color: #007AFF;
- color: #fff;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 28rpx;
- font-weight: bold;
- }
- /* 表单区域 */
- .form-container {
- background-color: #fff;
- padding: 0 30rpx;
- margin-bottom: 20rpx;
- }
- .form-title {
- font-size: 18px;
- font-weight: 500;
- color: #333;
- padding: 30rpx 0 20rpx;
- border-bottom: 1rpx solid #eee;
- }
- .form-item {
- width: 100%;
- padding: 30rpx 0;
- border-bottom: 1rpx solid #eee;
- }
- .form-input {
- font-size: 16px;
- height: 40rpx;
- line-height: 40rpx;
- color: #333;
- }
- .form-input::placeholder {
- color: #999;
- }
- .picker-placeholder {
- font-size: 16px;
- height: 40rpx;
- line-height: 40rpx;
- color: #999;
- }
- .picker-placeholder.has-value {
- color: #333;
- }
- /* 表单操作 */
- .form-actions {
- width: 100%;
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 30rpx 0;
- }
- .action-left {
- display: flex;
- align-items: center;
- }
- .action-text {
- font-size: 28rpx;
- color: #333;
- margin-left: 10rpx;
- }
- .action-right {
- padding: 10rpx 20rpx;
- }
- .clear-text {
- height: 44rpx;
- font-weight: 400;
- font-size: 28rpx;
- color: #1B64F0;
- line-height: 44rpx;
- }
- /* 最近地址 */
- .recent-address {
- background-color: #fff;
- padding: 0 30rpx;
- }
- .section-title {
- height: 48rpx;
- font-size: 32rpx;
- color: #333333;
- line-height: 48rpx;
- margin: 20rpx 0rpx;
- font-weight: bold;
- }
- .address-item {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 30rpx 0;
- border-bottom: 1rpx solid #eee;
- }
- .address-info {
- flex: 1;
- }
- .address-name {
- font-size: 16px;
- color: #333;
- margin-bottom: 10rpx;
- }
- .address-detail {
- font-size: 14px;
- color: #666;
- line-height: 1.4;
- }
- .address-select {
- width: 40rpx;
- height: 40rpx;
- border: 1rpx solid #007AFF;
- border-radius: 50%;
- margin-left: 20rpx;
- }
- .safe-area {
- height: 140rpx;
- }
- .submit-btn {
- position: fixed;
- bottom: 40rpx;
- left: 30rpx;
- right: 30rpx;
- width: 686rpx;
- height: 88rpx;
- background: #1B64F0;
- border-radius: 44rpx;
- display: flex;
- justify-content: center;
- align-items: center;
- font-size: 32rpx;
- color: #FFFFFF;
- line-height: 88rpx;
- text-align: center;
- z-index: 10;
- }
- </style>
|