web-retail-h5/pages/address/index.vue

348 lines
8.5 KiB
Vue
Raw Normal View History

2025-03-23 09:29:40 +08:00
<template>
<view class="main">
<view class="contents">
<u-form :model="addressForm" labelWidth="auto" ref="uForm">
<view class="view-class">
2025-06-11 10:48:43 +08:00
<u-form-item label="收货人" label-width="100px" prop="recName">
2025-03-23 09:29:40 +08:00
<u-input
:maxlength="40"
v-model.trim="addressForm.recName"
placeholder-class="place-class"
class="border-color"
placeholder="请输入收货人姓名"
/>
</u-form-item>
</view>
<view class="view-class">
2025-06-11 10:48:43 +08:00
<u-form-item label="联系方式" label-width="100px" prop="recPhone">
2025-03-23 09:29:40 +08:00
<u-input
v-if="pkCountry == 1"
v-model.trim="addressForm.recPhone"
placeholder-class="place-class"
:maxlength="11"
class="border-color"
type="number"
placeholder="请输入联系方式"
/>
<u-input
v-else
v-model.trim="addressForm.recPhone"
placeholder-class="place-class"
:maxlength="30"
class="border-color"
placeholder="请输入联系方式"
/>
</u-form-item>
</view>
<view class="view-class" @click="getDiqu">
<u-form-item label="收货地址" label-width="100px" prop="address">
2025-03-23 09:29:40 +08:00
<view
v-if="address"
style="font-size: 28rpx; color: #333; margin-left: 20rpx"
>{{ address }}</view
>
<view
style="
margin-left: 20rpx;
font-size: 28rpx;
color: rgb(192, 196, 204);
"
v-else
>请选择收货地址</view
>
</u-form-item>
<view class="drop">
<image src="../../static/images/drop.png"></image>
</view>
</view>
<view class="view-class">
<u-form-item
label="详细地址"
2025-03-23 09:29:40 +08:00
class="label-style"
label-width="100px"
prop="recAddress"
>
<u-textarea
v-model.trim="addressForm.recAddress"
placeholder-class="place-class"
class="border-color"
maxlength="200"
placeholder="请输入详细地址"
2025-03-23 09:29:40 +08:00
/>
</u-form-item>
</view>
<view class="view-class flex-s">
<view> 设为默认地址 </view>
<view @click="checkTap">
<view class="check" v-if="addressForm.isDefault == 0">
<view></view>
</view>
<view class="check" v-else>
<image src="../../static/images/check.png"></image>
</view>
</view>
</view>
</u-form>
</view>
<v-address
ref="address"
@getAddressData="AddressData"
:defaultCode="defaultCode"
@addressData="addressData"
></v-address>
2025-06-11 10:48:43 +08:00
<u-button
:disabled="
!addressForm.recName || !addressForm.recPhone || !addressForm.recAddress
"
type="success"
2025-06-11 10:48:43 +08:00
shape="circle"
class="btn"
@click="submit"
color="#005BAC"
:loading="loading"
>
确定
</u-button>
2025-03-23 09:29:40 +08:00
<view style="height: 20rpx"></view>
</view>
</template>
<script>
2025-06-11 10:48:43 +08:00
import * as api from '@/config/login.js'
import { setToken } from '@/config/auth.js'
import address from '@/components/address.vue'
import store from '@/store'
2025-03-23 09:29:40 +08:00
export default {
data() {
return {
2025-06-11 10:48:43 +08:00
userInfo: '',
pkCountry: '',
2025-03-23 09:29:40 +08:00
check: false,
2025-06-11 10:48:43 +08:00
address: '',
2025-03-23 09:29:40 +08:00
defaultCode: [],
2025-06-11 10:48:43 +08:00
urls: '/member/api/maker-space/update-file',
2025-03-23 09:29:40 +08:00
addressForm: {
2025-06-11 10:48:43 +08:00
recName: '',
recPhone: '',
recProvince: '',
recCity: '',
recCounty: '',
recAddress: '',
2025-03-23 09:29:40 +08:00
isDefault: 0,
2025-06-11 10:48:43 +08:00
pkId: '',
2025-03-23 09:29:40 +08:00
},
loading: false,
2025-03-23 09:29:40 +08:00
rules: {
recName: [
{
// 必填项
required: true,
// 提示内容会出现在u-form-item内的底部
2025-06-11 10:48:43 +08:00
message: '姓名不能为空',
2025-03-23 09:29:40 +08:00
},
],
recAddress: [
{
// 必填项
required: true,
// 提示内容会出现在u-form-item内的底部
2025-06-11 10:48:43 +08:00
message: '详细地址不能为空',
2025-03-23 09:29:40 +08:00
},
],
recProvince: [
{
// 必填项
required: true,
// 提示内容会出现在u-form-item内的底部
2025-06-11 10:48:43 +08:00
message: '地址不能为空',
2025-03-23 09:29:40 +08:00
2025-06-11 10:48:43 +08:00
trigger: ['change'],
2025-03-23 09:29:40 +08:00
},
],
recPhone: [
{
required: true,
2025-06-11 10:48:43 +08:00
message: '请输入手机号',
trigger: ['blur'],
2025-03-23 09:29:40 +08:00
},
{
validator: (rule, value, callback) => {
2025-06-11 10:48:43 +08:00
return this.$u.test.mobile(value)
},
2025-06-11 10:48:43 +08:00
message: '手机号格式不正确',
trigger: ['blur'],
},
2025-03-23 09:29:40 +08:00
],
},
2025-06-11 10:48:43 +08:00
}
2025-03-23 09:29:40 +08:00
},
onLoad(option) {
if (option.pkId) {
2025-06-11 10:48:43 +08:00
this.getAddress(option.pkId)
2025-03-23 09:29:40 +08:00
uni.setNavigationBarTitle({
2025-06-11 10:48:43 +08:00
title: '修改收货地址',
})
2025-03-23 09:29:40 +08:00
}
2025-06-11 10:48:43 +08:00
this.pkCountry = uni.getStorageSync('pkCountry')
this.userInfo = uni.getStorageSync('User')
2025-03-23 09:29:40 +08:00
},
onReady() {
2025-06-11 10:48:43 +08:00
this.$refs.uForm.setRules(this.rules)
2025-03-23 09:29:40 +08:00
},
components: {
2025-06-11 10:48:43 +08:00
'v-address': address,
2025-03-23 09:29:40 +08:00
},
methods: {
AddressData(name) {
2025-06-11 10:48:43 +08:00
this.address = name
2025-03-23 09:29:40 +08:00
},
submit() {
2025-06-11 10:48:43 +08:00
this.$refs.uForm.validate().then(res => {
this.loading = true
2025-06-11 10:48:43 +08:00
api
.saveAddress(this.addressForm)
.then(res => {
if (res.code == '200') {
const toast = uni.showToast({
title: res.msg,
icon: 'none',
complete() {
setTimeout(() => {
this.loading = false
uni.navigateBack(1)
toast.hideToast()
}, 500)
},
})
} else {
this.loading = false
}
})
.catch(() => {
this.loading = false
2025-06-11 10:48:43 +08:00
})
})
2025-03-23 09:29:40 +08:00
},
getDiqu() {
2025-06-11 10:48:43 +08:00
this.$refs.address.setShow()
2025-03-23 09:29:40 +08:00
},
addressData(diqu, obj) {
2025-06-11 10:48:43 +08:00
this.address = diqu
this.addressForm.recProvince = obj.province
this.addressForm.recCity = obj.city
this.addressForm.recCounty = obj.county
this.$forceUpdate()
2025-03-23 09:29:40 +08:00
// this.getPostAge()
// this.queryAdressPostage()
},
checkTap() {
if (this.addressForm.isDefault == 0) {
2025-06-11 10:48:43 +08:00
this.addressForm.isDefault = 1
2025-03-23 09:29:40 +08:00
} else {
2025-06-11 10:48:43 +08:00
this.addressForm.isDefault = 0
2025-03-23 09:29:40 +08:00
}
},
getAddressData(e) {
2025-06-11 10:48:43 +08:00
console.error(e)
2025-03-23 09:29:40 +08:00
},
getAddress(id) {
api
.getAddress(id)
2025-06-11 10:48:43 +08:00
.then(res => {
2025-03-23 09:29:40 +08:00
if (res) {
this.addressForm = {
recName: res.data.recName,
recPhone: res.data.recPhone,
recProvince: res.data.recProvince,
recCity: res.data.recCity,
2025-06-11 10:48:43 +08:00
recCounty: res.data.recCounty || '',
2025-03-23 09:29:40 +08:00
pkId: res.data.pkId,
recAddress: res.data.recAddress,
isDefault: res.data.isDefault,
2025-06-11 10:48:43 +08:00
}
2025-03-23 09:29:40 +08:00
this.defaultCode = [
res.data.recProvince,
res.data.recCity,
2025-06-11 10:48:43 +08:00
res.data.recCounty || '',
]
2025-03-23 09:29:40 +08:00
}
})
2025-06-11 10:48:43 +08:00
.catch(error => {
reject(error)
})
2025-03-23 09:29:40 +08:00
},
},
2025-06-11 10:48:43 +08:00
}
2025-03-23 09:29:40 +08:00
</script>
<style lang="scss" scoped>
:v-deep .u-form-item__body__right__message {
2025-03-23 09:29:40 +08:00
margin-left: 215rpx !important;
padding-bottom: 20rpx;
}
.drop {
image {
width: 40rpx;
height: 40rpx;
position: absolute;
right: 0;
top: 30rpx;
}
}
.check {
position: relative;
view {
width: 36rpx;
height: 36rpx;
2025-06-11 10:48:43 +08:00
border: 1rpx solid #000;
2025-03-23 09:29:40 +08:00
border-radius: 50%;
margin-top: 25rpx;
}
image {
width: 40rpx;
height: 40rpx;
position: absolute;
right: 0rpx;
top: 25rpx;
// margin-top: 20rpx;
}
}
.flex-s {
justify-content: space-between;
display: flex;
height: 90rpx;
line-height: 90rpx;
}
.label-style {
display: block !important;
}
:v-deep .label-style .u-form-item__body__left {
2025-03-23 09:29:40 +08:00
display: block !important;
margin-top: 20rpx;
}
.uni-textarea {
height: 100rpx;
}
.view-class {
border-bottom: 1rpx solid #eee;
margin: 0 30rpx;
position: relative;
}
.border-color {
border: none;
}
page {
background-color: #f2f2f2;
}
.contents {
background-color: #fff;
}
.btn {
height: 92rpx;
line-height: 92rpx;
font-size: 30rpx;
margin: 40rpx auto;
width: 690rpx;
}
</style>