2024-04-27 18:02:43 +08:00
|
|
|
|
<template>
|
|
|
|
|
<view class="">
|
|
|
|
|
<view class="card">
|
|
|
|
|
<up-form labelPosition="left" :model="formData" :rules="rules" ref="uForm" labelWidth="100">
|
2024-04-28 18:08:57 +08:00
|
|
|
|
<up-form-item label="收货人" prop="real_name" borderBottom>
|
|
|
|
|
<up-input v-model="formData.real_name" disabledColor="#ffffff" border="none" placeholder="请填写收货人姓名"></up-input>
|
2024-04-27 18:02:43 +08:00
|
|
|
|
</up-form-item>
|
|
|
|
|
<up-form-item label="联系电话" prop="phone" borderBottom>
|
|
|
|
|
<up-input v-model="formData.phone" disabledColor="#ffffff" type="number" placeholder="请填写联系电话"
|
|
|
|
|
border="none"></up-input>
|
|
|
|
|
</up-form-item>
|
2024-04-28 18:08:57 +08:00
|
|
|
|
<up-form-item label="详细地址" prop="detail" borderBottom>
|
|
|
|
|
<up-input v-model="formData.detail" disabledColor="#ffffff" placeholder="请填写详细地址" border="none"></up-input>
|
2024-04-27 18:02:43 +08:00
|
|
|
|
</up-form-item>
|
|
|
|
|
</up-form>
|
|
|
|
|
</view>
|
|
|
|
|
<view class="card">
|
|
|
|
|
<view class="is-default">
|
|
|
|
|
<view>设置为默认地址</view>
|
2024-04-29 18:14:58 +08:00
|
|
|
|
<up-switch v-model="formData.is_default" :activeValue="1" :inactiveValue="0" activeColor="#20B128"></up-switch>
|
2024-04-27 18:02:43 +08:00
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
<view class="bottom-fixed">
|
|
|
|
|
<up-button color="#20B128" shape="circle" @click="submit">保存</up-button>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup>
|
|
|
|
|
import { onLoad } from "@dcloudio/uni-app"
|
|
|
|
|
import { ref } from "vue"
|
2024-04-29 10:44:50 +08:00
|
|
|
|
import { addressCreateApi, addressEditApi, addressDetailApi } from "@/api/user.js"
|
2024-04-27 18:02:43 +08:00
|
|
|
|
|
|
|
|
|
const mode = ref('add');
|
|
|
|
|
|
|
|
|
|
const formData = ref({
|
2024-04-28 18:08:57 +08:00
|
|
|
|
real_name: '',
|
2024-04-27 18:02:43 +08:00
|
|
|
|
phone: '',
|
2024-04-28 18:08:57 +08:00
|
|
|
|
detail: '',
|
2024-04-29 18:14:58 +08:00
|
|
|
|
is_default: 0
|
2024-04-27 18:02:43 +08:00
|
|
|
|
})
|
|
|
|
|
const rules = ref({
|
2024-04-28 18:08:57 +08:00
|
|
|
|
real_name: [{ required: true, message: '请输入姓名', trigger: ['blur'] }],
|
2024-06-03 16:45:07 +08:00
|
|
|
|
phone: [{ required: true, message: '请输入手机号', trigger: ['blur'] },{
|
|
|
|
|
validator: (rule, value, callback) => {
|
|
|
|
|
// 上面有说,返回true表示校验通过,返回false表示不通过
|
|
|
|
|
// uni.$u.test.mobile()就是返回true或者false的
|
|
|
|
|
return uni.$u.test.mobile(value);
|
|
|
|
|
},
|
|
|
|
|
message: '手机号码不正确',
|
|
|
|
|
trigger: ['change','blur'],
|
|
|
|
|
}],
|
2024-04-28 18:08:57 +08:00
|
|
|
|
detail: [{ required: true, message: '请输入地址', trigger: ['blur'] }]
|
2024-04-27 18:02:43 +08:00
|
|
|
|
})
|
|
|
|
|
const uForm = ref(null);
|
|
|
|
|
const submit = () => {
|
|
|
|
|
uForm.value.validate().then(() => {
|
|
|
|
|
console.log('验证通过');
|
2024-04-28 18:08:57 +08:00
|
|
|
|
if(mode.value=='add'){
|
|
|
|
|
addressCreateApi(formData.value).then(res=>{
|
|
|
|
|
uni.$u.toast(res.msg);
|
|
|
|
|
uni.$u.sleep(800).then(res=>{
|
|
|
|
|
uni.navigateBack();
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
addressEditApi(formData.value).then(res=>{
|
|
|
|
|
uni.$u.toast(res.msg);
|
|
|
|
|
uni.$u.sleep(800).then(res=>{
|
|
|
|
|
uni.navigateBack();
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
2024-04-27 18:02:43 +08:00
|
|
|
|
}).catch(() => {
|
|
|
|
|
console.log('验证失败');
|
|
|
|
|
})
|
|
|
|
|
}
|
2024-04-29 10:44:50 +08:00
|
|
|
|
|
|
|
|
|
const getAddressDetil = (address_id)=>{
|
|
|
|
|
addressDetailApi({
|
|
|
|
|
address_id
|
|
|
|
|
}).then(res=>{
|
|
|
|
|
formData.value = res.data;
|
|
|
|
|
})
|
|
|
|
|
}
|
2024-04-27 18:02:43 +08:00
|
|
|
|
|
|
|
|
|
onLoad((options) => {
|
2024-04-29 10:44:50 +08:00
|
|
|
|
if (options.mode == 'edit'&&options.address_id) {
|
2024-04-27 18:02:43 +08:00
|
|
|
|
mode.value = 'edit';
|
|
|
|
|
uni.setNavigationBarTitle({
|
|
|
|
|
title: '编辑地址'
|
|
|
|
|
})
|
2024-04-29 10:44:50 +08:00
|
|
|
|
getAddressDetil(options.address_id)
|
2024-04-27 18:02:43 +08:00
|
|
|
|
} else uni.setNavigationBarTitle({
|
|
|
|
|
title: '新增地址'
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
|
.card {
|
|
|
|
|
margin: 20rpx;
|
|
|
|
|
background-color: #fff;
|
|
|
|
|
border-radius: 14rpx;
|
|
|
|
|
padding: 0 30rpx;
|
|
|
|
|
|
|
|
|
|
.is-default {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
padding: 20rpx 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.bottom-fixed {
|
|
|
|
|
position: fixed;
|
|
|
|
|
bottom: 0;
|
|
|
|
|
left: 0;
|
|
|
|
|
height: 120rpx;
|
|
|
|
|
height: calc(constant(safe-area-inset-bottom) + 120rpx);
|
|
|
|
|
/* 适用于iOS设备 */
|
|
|
|
|
height: calc(env(safe-area-inset-bottom) + 120rpx);
|
|
|
|
|
/* 适用于Android设备 */
|
|
|
|
|
width: 100%;
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
background-color: #fff;
|
|
|
|
|
padding: 20rpx;
|
|
|
|
|
padding-bottom: calc(constant(safe-area-inset-bottom) + 20rpx);
|
|
|
|
|
/* 适用于iOS设备 */
|
|
|
|
|
padding-bottom: calc(env(safe-area-inset-bottom) + 20rpx);
|
|
|
|
|
/* 适用于Android设备 */
|
|
|
|
|
}
|
|
|
|
|
</style>
|