add
This commit is contained in:
parent
5afd6b8978
commit
87cc78ffcd
|
@ -3,70 +3,110 @@
|
|||
<view class="card">
|
||||
<up-form labelPosition="left" :model="formData" :rules="rules" ref="uForm" labelWidth="100">
|
||||
<up-form-item label="收货人" prop="real_name" borderBottom>
|
||||
<up-input v-model="formData.real_name" disabledColor="#ffffff" border="none" placeholder="请填写收货人姓名"></up-input>
|
||||
<up-input v-model="formData.real_name" disabledColor="#ffffff" border="none"
|
||||
placeholder="请填写收货人姓名"></up-input>
|
||||
</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>
|
||||
<!-- <up-form-item label="所在位置" prop="address" borderBottom>
|
||||
<up-input v-model="formData.address" disabledColor="#ffffff" type="number"
|
||||
@click='showAddressPop=true' placeholder="点击选择位置" border="none"></up-input>
|
||||
<template #right>
|
||||
<up-icon name="arrow-right"></up-icon>
|
||||
</template>
|
||||
</up-form-item> -->
|
||||
<up-form-item label="详细地址" prop="detail" borderBottom>
|
||||
<up-input v-model="formData.detail" disabledColor="#ffffff" placeholder="请填写详细地址" border="none"></up-input>
|
||||
<up-input v-model="formData.detail" disabledColor="#ffffff" placeholder="请填写详细地址"
|
||||
border="none"></up-input>
|
||||
</up-form-item>
|
||||
</up-form>
|
||||
</view>
|
||||
<view class="card">
|
||||
<view class="is-default">
|
||||
<view>设置为默认地址</view>
|
||||
<up-switch v-model="formData.is_default" :activeValue="1" :inactiveValue="0" activeColor="#20B128"></up-switch>
|
||||
<up-switch v-model="formData.is_default" :activeValue="1" :inactiveValue="0"
|
||||
activeColor="#20B128"></up-switch>
|
||||
</view>
|
||||
</view>
|
||||
<view class="bottom-fixed">
|
||||
<up-button color="#20B128" shape="circle" @click="submit">保存</up-button>
|
||||
</view>
|
||||
<!-- 地址选择器 -->
|
||||
<up-popup :show="showAddressPop" @close="showAddressPop=false" @open="showAddressPop=true" :round="10">
|
||||
<view class='address-pop'>
|
||||
<view class="title">
|
||||
收货地址
|
||||
</view>
|
||||
</view>
|
||||
</up-popup>
|
||||
|
||||
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { onLoad } from "@dcloudio/uni-app"
|
||||
import { ref } from "vue"
|
||||
import { addressCreateApi, addressEditApi, addressDetailApi } from "@/api/user.js"
|
||||
import {
|
||||
onLoad
|
||||
} from "@dcloudio/uni-app"
|
||||
import {
|
||||
ref
|
||||
} from "vue"
|
||||
import {
|
||||
addressCreateApi,
|
||||
addressEditApi,
|
||||
addressDetailApi
|
||||
} from "@/api/user.js"
|
||||
|
||||
const mode = ref('add');
|
||||
const showAddressPop = ref(false)
|
||||
|
||||
const formData = ref({
|
||||
real_name: '',
|
||||
phone: '',
|
||||
detail: '',
|
||||
is_default: 0
|
||||
is_default: 0,
|
||||
address: ""
|
||||
})
|
||||
const rules = ref({
|
||||
real_name: [{ required: true, message: '请输入姓名', trigger: ['blur'] }],
|
||||
phone: [{ required: true, message: '请输入手机号', trigger: ['blur'] },{
|
||||
real_name: [{
|
||||
required: true,
|
||||
message: '请输入姓名',
|
||||
trigger: ['blur']
|
||||
}],
|
||||
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'],
|
||||
trigger: ['change', 'blur'],
|
||||
}],
|
||||
detail: [{ required: true, message: '请输入地址', trigger: ['blur'] }]
|
||||
detail: [{
|
||||
required: true,
|
||||
message: '请输入地址',
|
||||
trigger: ['blur']
|
||||
}]
|
||||
})
|
||||
const uForm = ref(null);
|
||||
const submit = () => {
|
||||
uForm.value.validate().then(() => {
|
||||
console.log('验证通过');
|
||||
if(mode.value=='add'){
|
||||
addressCreateApi(formData.value).then(res=>{
|
||||
if (mode.value == 'add') {
|
||||
addressCreateApi(formData.value).then(res => {
|
||||
uni.$u.toast(res.msg);
|
||||
uni.$u.sleep(800).then(res=>{
|
||||
uni.$u.sleep(800).then(res => {
|
||||
uni.navigateBack();
|
||||
})
|
||||
})
|
||||
} else {
|
||||
addressEditApi(formData.value).then(res=>{
|
||||
addressEditApi(formData.value).then(res => {
|
||||
uni.$u.toast(res.msg);
|
||||
uni.$u.sleep(800).then(res=>{
|
||||
uni.$u.sleep(800).then(res => {
|
||||
uni.navigateBack();
|
||||
})
|
||||
})
|
||||
|
@ -76,16 +116,16 @@
|
|||
})
|
||||
}
|
||||
|
||||
const getAddressDetil = (address_id)=>{
|
||||
const getAddressDetil = (address_id) => {
|
||||
addressDetailApi({
|
||||
address_id
|
||||
}).then(res=>{
|
||||
}).then(res => {
|
||||
formData.value = res.data;
|
||||
})
|
||||
}
|
||||
|
||||
onLoad((options) => {
|
||||
if (options.mode == 'edit'&&options.address_id) {
|
||||
if (options.mode == 'edit' && options.address_id) {
|
||||
mode.value = 'edit';
|
||||
uni.setNavigationBarTitle({
|
||||
title: '编辑地址'
|
||||
|
@ -130,4 +170,16 @@
|
|||
padding-bottom: calc(env(safe-area-inset-bottom) + 20rpx);
|
||||
/* 适用于Android设备 */
|
||||
}
|
||||
|
||||
.address-pop {
|
||||
height: 60vh;
|
||||
padding: 20rpx;
|
||||
overflow-y: auto;
|
||||
|
||||
.title {
|
||||
font-size: 32rpx;
|
||||
color: black;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
</style>
|
Loading…
Reference in New Issue